Skip to content

Conversation

@Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jul 3, 2022

If you have Objects were you want to allow also prototype and constructor as valid keys without having the risk of prototype pollution, you have to create Objects with prototype set to null. This PR adds the nullPrototype option. It also improves the performance, by avoiding creating unnecessary intermediary Objects

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

@Eomm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

Uzlopak and others added 4 commits July 3, 2022 12:18
Co-authored-by: Manuel Spigolon <[email protected]>
Co-authored-by: Manuel Spigolon <[email protected]>
Co-authored-by: Manuel Spigolon <[email protected]>
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

wait please. I am currently implementing your proposal, and trying to get it back to 100% test coverage

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

@Eomm ready

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I'm not sure exactly why are we adding this here. Offering prototype pollution protection is asking for security researchers to find holes in this algorithm. I would rather avoid the problem if we don't need it elsewhere.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

I added it here, because when we merge two json schemas and they could theoretically contain the key prototype or constructor than merging it into a normal Object would result in prototype pollution. What is your concern? If you dont set nullPrototype you have normal prototype pollution.

@mcollina
Copy link
Member

mcollina commented Jul 3, 2022

JSON schemas are code. There is nothing to worry about prototype pollutions.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

Please decide. I will then just take the performance improvements to the master branch

@Uzlopak Uzlopak mentioned this pull request Jul 3, 2022
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 3, 2022

@mcollina
Copy link
Member

mcollina commented Jul 4, 2022

What's the link about?

JSON Schema should be treated as code, see https://www.fastify.io/docs/latest/Reference/Validation-and-Serialization/. Neither AJV nor fast-json-stringify are to be considered safe against malicious schemas.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 4, 2022

Ah now I get what you mean with "Has to be handled like code".
Then we sould maybe just add to the docs, that keys like prototype or constructor are not allowed for JSON Schemas.

Should I close this PR?

@mcollina
Copy link
Member

mcollina commented Jul 4, 2022

Then we sould maybe just add to the docs, that keys like prototype or constructor are not allowed for JSON Schemas.

Maybe I'm not understanding the issue. I think those properties are allowed in JSON Schemas, aren't them?

Should I close this PR?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 4, 2022

I just fear that fast-json-stringify will not be able to handle those keys when doing merges on the schema, which are simple objects.

@Uzlopak Uzlopak closed this Jul 5, 2022
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