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

sanitizeParams does not filter out non public fields #191

Open
thoaif opened this issue May 1, 2020 · 0 comments
Open

sanitizeParams does not filter out non public fields #191

thoaif opened this issue May 1, 2020 · 0 comments

Comments

@thoaif
Copy link

thoaif commented May 1, 2020

Problem / motivation

sanitizeParams function does not filter out fields inside query params. This presents a challenge in "hiding" fields in from public access, since an attacker can still query using those fields and gain privileged information.

I am not exactly sure what intention of "fields" setting is, but I sure do hope no one is using them with the assumption that access is restricted to those fields

Example

Suppose I have the following:

module.exports = {
  name: 'example',

  settings: {
    fields: [ '_id' ],
    entityValidator: {
      hiddenField: { type: 'boolean', default: true },
    },
  }
}

I can still use hiddenField in actions with query param. For example:

call example.list --query '{"hiddenField": false}'

will list out all the fields where hiddenField is false. Ideally, querying in this manner should
not work.

Suggested Solution

Inside sanitizeParams function after parsing, one could filter by:

if (p.query) {
  const filteredQuery = Object.fromEntries(
    Object.entries(p.query)
      .filter(([field, val]) => 
         this.settings.fields.includes(field)
       )
   )
p.query = filteredQuery;
}
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

No branches or pull requests

1 participant