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

Hide creator fields from public api by default #8052

Merged
merged 15 commits into from Oct 1, 2020

Conversation

Convly
Copy link
Member

@Convly Convly commented Sep 25, 2020

❓ What has been done?

πŸ™… Removed the creator's fields (updated_by, created_by) by default from public API responses.

πŸ”§ Added a model option to populate and return the creator's fields in public API responses (populateCreatorFields)

βœ… Added new utilities to centralize checks on the attribute's privacy.

πŸŒ„ Removed the creator's fields from upload's controller routes.

πŸ› Fixed GraphQL behavior with privates attributes (removed computed private attributes from resolvers generation)

πŸ—’οΈ Notes

@alexandrebodin, @petersg83, I went with populateCreatorFields as the name of the model option but any feedback or suggestion is welcome

resolve #7177
resolve #8069

@Convly Convly added the source: core:strapi Source is core/strapi package label Sep 25, 2020
@Convly Convly added this to the 3.2.0 milestone Sep 25, 2020
@Convly Convly force-pushed the hide-creator-fields-public-api branch from 5cfa0fc to 4431cf3 Compare September 25, 2020 15:21
Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

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

Should move docs to the v3 not v3-beta

docs/3.0.0-beta.x/concepts/models.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #8052 into master will increase coverage by 0.05%.
The diff coverage is 47.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8052      +/-   ##
==========================================
+ Coverage   32.71%   32.77%   +0.05%     
==========================================
  Files        1194     1197       +3     
  Lines       12969    13019      +50     
  Branches     1280     1286       +6     
==========================================
+ Hits         4243     4267      +24     
- Misses       7886     7907      +21     
- Partials      840      845       +5     
Flag Coverage Ξ”
#front 24.80% <16.66%> (-0.01%) ⬇️
#unit 53.88% <50.81%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
...n/src/containers/NotificationProvider/selectors.js 0.00% <0.00%> (ΓΈ)
...-manager/admin/src/components/Wysiwyg/constants.js 0.00% <ΓΈ> (ΓΈ)
...nt-manager/admin/src/components/Wysiwyg/helpers.js 0.00% <ΓΈ> (ΓΈ)
...cumentation/admin/src/containers/HomePage/index.js 0.00% <ΓΈ> (ΓΈ)
...ugin-upload/admin/src/components/EditForm/index.js 0.00% <0.00%> (ΓΈ)
.../containers/InputModalStepper/InputModalStepper.js 0.00% <ΓΈ> (ΓΈ)
.../src/containers/InputModalStepperProvider/index.js 0.00% <0.00%> (ΓΈ)
...-upload/admin/src/containers/ModalStepper/index.js 0.00% <ΓΈ> (ΓΈ)
...rapi-plugin-upload/admin/src/translations/index.js 0.00% <0.00%> (ΓΈ)
packages/strapi-plugin-upload/services/Upload.js 15.75% <0.00%> (-0.45%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 7a45bde...c37df67. Read the comment docs.

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
…i controller (find)

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
… builds)

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
@Convly Convly force-pushed the hide-creator-fields-public-api branch from 5476f76 to 7288941 Compare October 1, 2020 12:16
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
@Convly Convly force-pushed the hide-creator-fields-public-api branch from 7288941 to 5fcf64f Compare October 1, 2020 12:36
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

Last comment :)

alexandrebodin and others added 2 commits October 1, 2020 15:48
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
…t.js)

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

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

Docs look fine to me

@alexandrebodin alexandrebodin modified the milestones: 3.2.0, 3.1.7 Oct 1, 2020
@alexandrebodin alexandrebodin added the issue: enhancement Issue suggesting an enhancement to an existing feature label Oct 1, 2020
@alexandrebodin alexandrebodin merged commit e55ea1d into master Oct 1, 2020
@alexandrebodin alexandrebodin deleted the hide-creator-fields-public-api branch October 1, 2020 15:47
@dalbitresb12
Copy link
Contributor

Hi @Convly, I was looking at the files that were changed with this PR and I saw something strange.

const userModel = {
primaryKey: 'id',
options: {
timestamps: ['created_at', 'updated_at'],
},
privateAttributes: ['email'],

Correct me if I'm wrong, but I thought the privateAttributes option was supposed to be inside the options. This also happens in some other parts of that same test file.

const articleModel = {
primaryKey: 'id',
options: {
timestamps: ['created_at', 'updated_at'],
},
privateAttributes: ['secret'],

const model = {
...models.user,
options: {
...models.user.options,
privateAttributes: ['firstname'],
},
privateAttributes: [].concat(models.user.privateAttributes, ['firstname'], ['id']),
};

Is there something I'm missing here?

@Convly
Copy link
Member Author

Convly commented Oct 1, 2020

Hello @dalbitresb12

The privateAttributes is indeed an option in the model schema.
However this is not the only place where we use this notion.
Starting from this PR, we also introduce a privateAttributes in the mounted model's definition (strapi.models[modelName].privateAttributes) which will run the getPrivateAttributes computation once for all instead of each time we want to check if an attribute is private.
This attribute is created in the mount-model (eg: here) process in every connector using the getPrivateAttributes utility to calculate the value (using config.api.response.privateAttributes + model.options.privateAttributes + attributes.filter(isPrivate)).

In the tests, we simulate the result of the mount-model operation and attach it to the object. (so that the model.privateAttributes should be equal to model.options.privateAttributes + global privateAttributes (hardcoded at this level) + model attributes with private=true

@dalbitresb12
Copy link
Contributor

Oh, so this is just a calculated value that Strapi uses internally? It is not one that us as developers should add manually?

@Convly
Copy link
Member Author

Convly commented Oct 1, 2020

Exactly πŸ™‚

@dalbitresb12
Copy link
Contributor

That's actually great. Thank you for clarifying this. πŸ˜„

@lauriejim
Copy link
Contributor

This pull request has been mentioned on Strapi Community. There might be relevant details there:

https://forum.strapi.io/t/new-release-strapi-v3-1-7/256/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: core:strapi Source is core/strapi package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The Media Library's upload route exposes sensitive user data Disable or hide created_by & updated_by
6 participants