You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The nJwt library is susceptible to prototype pollution, particularly affecting the JwtHeader and JwtBody objects. These objects lack validation to ensure that attributes assigned to them don't resolve to the object prototype. The problem lies within the Parser.prototype.parse method, which is invoked when a user attempts to verify a JWT token using the nJwt.verify(token, signingKey) method.
By adding or modifying attributes of an object prototype, it is possible to create attributes that exist on every object and its inheritance or bypass certain checks. This can be problematic if the software depends on the existence or non-existence of certain attributes, or uses pre-defined attributes of object prototype (such as hasOwnProperty, toString, or valueOf).
Proof of Concept (PoC)
Create a new JWT token with header and body as follows:
An arbitrary user can override existing attributes with ones that have incompatible types, which may lead to a crash, or bypass certain checks via attribute modification, for example, overriding the JwtHeader.prototype.reservedKeys arrays. It might also be possible to create polluted attributes on every object inheriting from JwtBody and JwtHeader objects.
Mitigation
This issue can be fixed by freezing the prototype, or by implementing validation to check for prototype keywords (__proto__, constructor and prototype), where if it exists, the function denies merging it into JwtBody and JwtHeader object, thus preventing the prototype pollution vulnerability.
The text was updated successfully, but these errors were encountered:
Prototype Pollution in nJwt library
Description
The nJwt library is susceptible to prototype pollution, particularly affecting the
JwtHeader
andJwtBody
objects. These objects lack validation to ensure that attributes assigned to them don't resolve to the object prototype. The problem lies within theParser.prototype.parse
method, which is invoked when a user attempts to verify a JWT token using thenJwt.verify(token, signingKey)
method.By adding or modifying attributes of an object prototype, it is possible to create attributes that exist on every object and its inheritance or bypass certain checks. This can be problematic if the software depends on the existence or non-existence of certain attributes, or uses pre-defined attributes of object prototype (such as
hasOwnProperty
,toString
, orvalueOf
).Proof of Concept (PoC)
Create a new JWT token with
header
andbody
as follows:JWT Header
JWT Body
Resulting Token (Example)
Then, supply the token to be verified with
nJwt.verify()
function, for example:As a result, the
JwtHeader
andJwtBody
attributes will be polluted as follows:JWT Header
JWT Body
Impact
An arbitrary user can override existing attributes with ones that have incompatible types, which may lead to a crash, or bypass certain checks via attribute modification, for example, overriding the
JwtHeader.prototype.reservedKeys
arrays. It might also be possible to create polluted attributes on every object inheriting fromJwtBody
andJwtHeader
objects.Mitigation
This issue can be fixed by freezing the prototype, or by implementing validation to check for prototype keywords (
__proto__
,constructor
andprototype
), where if it exists, the function denies merging it intoJwtBody
andJwtHeader
object, thus preventing the prototype pollution vulnerability.The text was updated successfully, but these errors were encountered: