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

Should we allow custom populate params? #311

Open
0x0a0d opened this issue Mar 28, 2022 · 5 comments
Open

Should we allow custom populate params? #311

0x0a0d opened this issue Mar 28, 2022 · 5 comments

Comments

@0x0a0d
Copy link
Contributor

0x0a0d commented Mar 28, 2022

Hi @icebob,

Currently, how populate receive & send params, is predefined on settings.populates, I wonder if we can make it more flexible. Instead of populate: string[], we can accept populate as object like

{
  fields: ["dynamic-limited-fields"]
}

Example: I only need populate user.get with field name but sometime need field username

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Mar 28, 2022

I think we can allow to custom fields and mapping

image

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Mar 28, 2022

Custom mapping may crash app because it returns object instead array

In fact, caller can change return from fields populate by set ctx.params.fields likes

{
"fields": "user.username", // only return username on user populate
}

but if users is an array, ctx.params.fields can not use to filter fields (both on web api call and broker call)
So if we can flexible like this

{
  populate: [{
    populate: "user",
    fields: ["username", "name"]
  }, "another-old-style-populate"]
}

will amazing :D

@icebob
Copy link
Member

icebob commented Apr 1, 2022

I planned it sometimes about it in the past but always dropped the idea because it can leak sensitive data if the user can change the returned fields. E.g. you have a posts service that has a populated field "author". The author's email address is sensitive data, so posts listing action must not access this field.

So it can work only if there is an "allowed populate fields" which contains all available fields and the caller can't add fields which is not allowed.

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Apr 2, 2022

Please check my code
If settings.populates[X] has a fields, we will call authorizeFields to limit populate fields of caller

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Apr 3, 2022

populate: rule.populate

Is this bug?
Rule does not have populate, if user want to populate, he must put it in params.populate

Document https://moleculer.services/docs/0.14/moleculer-db.html#Populating

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

2 participants