Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use options.remotingContext for conditional settings #1662

Merged
merged 1 commit into from
Nov 15, 2018

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Nov 12, 2018

Description

This PR uses options from remote requests to decide default values for certain security-related settings

Related issues

See #1638 (comment)
#1663

  • connect to <link_to_referenced_issue>

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just a nitpick.

@@ -345,7 +345,7 @@ Memory.prototype.findOrCreate = function(model, filter, data, callback) {
});
}

self._models[model].model.include(nodes[0], filter.include, {}, function(err, nodes) {
self._models[model].model.include(nodes[0], filter.include, options, function(err, nodes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options || {} in case the option is undefined.

lib/dao.js Outdated
// See https://github.com/strongloop/loopback-datasource-juggler/issues/1651
var maxDepth = this._getSetting('maxDepthOfQuery', options);
if (maxDepth == null) {
if (isRemote) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented in strongloop/loopback#4065 (review), juggler should not be dealing specifics of remoting. I prefer us to allow juggler API callers to provide custom maxDepthOfQuery via options, which we already have for free thanks to this._getSetting.

lib/dao.js Outdated
// See https://github.com/strongloop/loopback-datasource-juggler/issues/1651
var maxDepth = this._getSetting('maxDepthOfData', options);
if (maxDepth == null) {
if (isRemote) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto: As I commented in strongloop/loopback#4065 (review), juggler should not be dealing specifics of remoting.

@raymondfeng
Copy link
Contributor Author

@bajtos PTAL

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to move DataAccessObject._normalize into a different file:

  • The format of Filter object is to specific to DAO only, KeyValue APIs use different filter properties.
  • It is pretty much impossible to review changes made in that method.
  • Such huge change will be difficult to back-port to older versions, because there is no automated way how to ensure the backport is not accidentally back-porting changes in _normalize implementation that are not supposed to be back-ported.

The rest of the patch LGTM.

@@ -336,7 +336,7 @@ function sanitizeQuery(query, options) {
const prohibitedKeys = options.prohibitedKeys;
const offendingKeys = [];
const normalizeUndefinedInQuery = options.normalizeUndefinedInQuery;
const maxDepth = options.maxDepth || 12;
const maxDepth = options.maxDepth || Number.MAX_SAFE_INTEGER;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to allow arbitrary deep queries? Or is this reverting back to the old behavior we used to have in juggler before recent security-related fixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a default value for the utility method itself. Juggler already sets 32 as the default value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So can we use 32 as the default value in this place too? I'd rather avoid all possibilities of implicitly infinite depth.

@bajtos
Copy link
Member

bajtos commented Nov 15, 2018

coverage/coveralls — Coverage decreased (-0.01%) to 83.954%

Please check the coverage data, there may be an important use case (test scenario) that you forgot to cover.

@raymondfeng
Copy link
Contributor Author

I don't think it's a good idea to move DataAccessObject._normalize into a different file:
The format of Filter object is to specific to DAO only, KeyValue APIs use different filter properties.
It is pretty much impossible to review changes made in that method.
Such huge change will be difficult to back-port to older versions, because there is no automated way how to ensure the backport is not accidentally back-porting changes in _normalize implementation that are not supposed to be back-ported.

The refactoring is to fix #1663.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants