Security: Prototype Pollution via Custom Attributes in BearerTokenType#440
Open
tomaioo wants to merge 1 commit into
Open
Conversation
In `BearerTokenType.valueOf()`, custom attributes are iterated using `for...in` without proper prototype chain protection. While `Object.prototype.hasOwnProperty.call` is used, if `customAttributes` itself is an object with a polluted prototype (e.g., via `__proto__` or `constructor`), properties from the prototype chain could be included in the token response. Additionally, the constructor allows `customAttributes` to be any object, which could lead to information disclosure or unexpected behavior if malicious properties are passed. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Member
|
Dear @tomaioo if you think this is related to a reproducible vulnerability then please open a new advisory: https://github.com/node-oauth/node-oauth2-server/security/advisories/new |
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.
Summary
Security: Prototype Pollution via Custom Attributes in BearerTokenType
Problem
Severity:
Medium| File:lib/token-types/bearer-token-type.js:L58In
BearerTokenType.valueOf(), custom attributes are iterated usingfor...inwithout proper prototype chain protection. WhileObject.prototype.hasOwnProperty.callis used, ifcustomAttributesitself is an object with a polluted prototype (e.g., via__proto__orconstructor), properties from the prototype chain could be included in the token response. Additionally, the constructor allowscustomAttributesto be any object, which could lead to information disclosure or unexpected behavior if malicious properties are passed.Solution
Use
Object.keys(this.customAttributes)instead offor...into avoid prototype chain iteration, or ensurecustomAttributesis created withObject.create(null). Also validate thatcustomAttributesonly contains expected types (strings, numbers, booleans) to prevent object injection attacks.Changes
lib/token-types/bearer-token-type.js(modified)