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

Added recursive support for protected props #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dan-omniscience
Copy link

Hi,
I added support for recursive reduction of the props.
please review and merge if you like.
If you have any comments or suggestions I'll be happy to hear from you.

Thank you,
Dan

@@ -44,6 +44,9 @@ module.exports = function redactProtectedKeys(dictionary, blacklist) {
throw new Error('Consistency violation: Unexpected bad usage in cleanseDictionary. Expected blacklist to be an array of strings, but got: '+util.inspect(blacklist,{depth:null}));
}//>-•

if(_.isUndefined(recursive)){
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, imho if (....) { because that is used elsewhere in this code.

Copy link
Member

Choose a reason for hiding this comment

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

@dan-omniscience yeah, if you wouldn't mind, that'd be helpful just for consistency
@tarlepp thanks, good catch

@@ -57,5 +60,18 @@ module.exports = function redactProtectedKeys(dictionary, blacklist) {

});//</_.each>

if(recursive){
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

if(recursive){
// Loop over each top-level property and check if it is an object
_.each(cleansedCopy, function(value, key){
if(_.isObject(cleansedCopy[key])){
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here

if(_.isObject(cleansedCopy[key])){
// Loop over each object inner property and redact any that are protected.
_.each(cleansedCopy[key], function(value, PropName){
if(blacklist.indexOf(PropName) >= 0){
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here

@dan-omniscience
Copy link
Author

I'm sorry but I didn't understand what exactly do you mean by your comments, can you be more specific so I could fix them?

Thank you,
Dan

@tarlepp
Copy link
Collaborator

tarlepp commented Feb 20, 2017

if(...){ vs if (...) {

@mikermcneil
Copy link
Member

@dan-omniscience Nice work! Here's some of the stuff going through my head:

  • This feels a little risky, since it's such a security-sensitive setting and recursive parsing of unknown JS values can get kind of crazy (see .sanitize x_x)
  • I'm imagining a scenario where someone manually attaches a Buffer instance or circular reference to req.query, req.body, or req.params and it crashes their app. (Or, for example, another hook might do this automatically)
  • recursive makes me wonder "recursive what?" (i.e. could it be referring to something else? Recursive requests due to redirects? etc)
  • The notion of what a "recursive param" means is pretty self-explanatory, but could lead to misunderstanding of how the blacklist should be configured (e.g. should I use user.password or password?)

So, after that consideration, and in the interest of keeping this hook lightweight: I think it might be best to add a new, configurable function to configure the default redaction behavior, instead of a recursive flag-- e.g. along the lines of the new sails.config.blueprints.parseBlueprintOptions in Sails v1.

e.g.

cleanseParams: function (allParams) {
  // ...userland can do anything it likes here...
  return allParams;
},

At load-time in the configure function, I think we'd need to check that you do not specify BOTH dontLogParams and this new setting-- if you did, we should throw an error explaining that you should use one or the other, not both. (This is just for clarity, and to keep configuration as simple as possible to reduce edge cases that could bite us unexpectedly)

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

Successfully merging this pull request may close these issues.

3 participants