fix: validator.isValid is not a function for certain objects#946
Open
ej-shafran wants to merge 1 commit intoauth0:masterfrom
Open
fix: validator.isValid is not a function for certain objects#946ej-shafran wants to merge 1 commit intoauth0:masterfrom
validator.isValid is not a function for certain objects#946ej-shafran wants to merge 1 commit intoauth0:masterfrom
Conversation
Objects with keys like `valueOf`, `toString`, and `__proto__` cause a
`TypeError` to be raised when calling `jwt.sign`. This is because the
key technically does exist on the `schema` param of `validate`, when
checked with `if (schema[key]) {}`. Using
`Object.prototype.hasOwnProperty` solves the issue.
dubzzz
reviewed
Jan 31, 2024
|
|
||
| const KEY = "any_key"; | ||
|
|
||
| describe("issue 945 - validator.isValid is not a function", () => { |
There was a problem hiding this comment.
As the issue has been detected via property based testing mechanisms, I wonder if at some point having such tests to cover this project could be a thing. It seems that it could be useful in addition to these tests to avoid regressions or even more nasty bugs such as things related to nested objects...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Objects with keys like
valueOf,toString, and__proto__cause aTypeErrorto be raised when callingjwt.sign. This is because the key technically does exist on theschemaparam ofvalidate, when checked withif (schema[key]) {}. UsingObject.prototype.hasOwnPropertysolves the issue.I used
Object.prototype.hasOwnProperty.call(schema, key). This method has full browser support. Alternatively,lodash.hascould be installed and used, but I think that would be overkill.References
Fixes #945
Testing
I have added
test/issue_945.tests.js. It fails if the change made tosign.jsis not present.Checklist