Security: Prototype Pollution via Custom Attributes in BearerTokenType#440
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>
|
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 |
|
Thanks for the report @tomaioo, and for thinking about token-response safety. I dug into this with a PoC against the current code and I don't think there's a vulnerability here — and unfortunately the proposed change breaks token issuance. Details: No prototype pollution is possible. The change is equivalent for the stated concern — It also regresses the common path. When Since One process note, kindly meant: for anything you suspect is a security vulnerability, please report it privately rather than opening a public PR. The preferred channel is GitHub's private vulnerability reporting — the "Report a vulnerability" button on this repo's Security tab (it's enabled here, and it's how we already handle advisories). That keeps the report — and any description of how to exploit it — private until a fix can be prepared and released, which is exactly what coordinated/responsible disclosure exists to protect. A public PR effectively discloses the suspected issue to everyone before we can ship a fix. There's no actual vulnerability here so no harm done, but for next time the private advisory flow is the safe route — and we're always happy to collaborate on a fix there. Thanks again for the contribution and for keeping an eye on this. 🙏 |
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)