CVE-2021-21368: Msgpack5 Prototype Poisoning Vulnerability
MODERATECVE-2021-21368 is a MODERATE (CVSS 6.7) prototype poisoning vulnerability (CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')) affecting Msgpack5 libraries in the npm ecosystem. The issue involves prototype poisoning. Remediation is available by upgrading affected packages to version 3.6.1, 4.5.1, 5.2.1.
CVE-2021-21368 at a Glance
Security Impact
CVSS: 6.7
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:L/I:H/A:H).
How to Fix CVE-2021-21368
To remediate this vulnerability, upgrade all affected Msgpack5 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install msgpack5@3.6.1
npm install msgpack5@4.5.1
npm install msgpack5@5.2.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls msgpack5
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2021-21368, inspect your project dependencies using npm:
npm ls msgpack5
Analyze the terminal output to locate any version of Msgpack5 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.6.1), your application is affected.
Note: The npm ls msgpack5 command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution'), where the product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype. In Msgpack5, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-21368 Affected Msgpack5 Versions
3 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
msgpack5
|
npm |
< 3.6.1
|
3.6.1
|
|
msgpack5
|
npm |
≥ 4.0.0
< 4.5.1
|
4.5.1
|
|
msgpack5
|
npm |
≥ 5.0.0
< 5.2.1
|
5.2.1
|
References
Frequently Asked Questions
What is CVE-2021-21368?
Which Msgpack5 versions are affected?
What version fixes CVE-2021-21368?
Is msgpack5 affected?
What is the CVSS score of CVE-2021-21368?
What CWE is associated with CVE-2021-21368?
How can I check npm dependencies for CVE-2021-21368?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-gmjw-49p4-pcfm",
"modified" : "2021-03-12T16:57:44Z",
"published" : "2021-03-12T22:44:17Z",
"aliases" : [ "CVE-2021-21368" ],
"summary" : "Prototype poisoning",
"details" : "### Impact\n\nThe issue is as follows: when `msgpack5` decodes a map containing a \nkey `\"__proto__\"`, it assigns the decoded value to `__proto__`. As you \nare no doubt aware, `Object.prototype.__proto__` is an accessor \nproperty for the receiver's prototype. If the value corresponding to \nthe key `__proto__` decodes to an object or `null`, `msgpack5` sets \nthe decoded object's prototype to that value. \n\nAn attacker who can submit crafted MessagePack data to a service can \nuse this to produce values that appear to be of other types; may have \nunexpected prototype properties and methods (for example `length`, \nnumeric properties, and `push` et al if `__proto__`'s value decodes to \nan `Array`); and/or may throw unexpected exceptions when used (for \nexample if the `__proto__` value decodes to a `Map` or `Date`). Other \nunexpected behavior might be produced for other types. \n\nThere is no effect on the global prototype.\n\nAn example: \n\n```js \nconst msgpack5 = require('msgpack5')(); \n\nconst payload = {}; \nObject.defineProperty(payload, '__proto__', { \nvalue: new Map().set(1, 2), \nenumerable: true \n}); \n\nconst encoded = msgpack5.encode(payload); \nconsole.log(encoded); // <Buffer 81 a9 5f 5f 70 72 6f 74 6f 5f 5f 81 01 02> \n\nconst decoded = msgpack5.decode(encoded); \n\n// decoded's prototype has been overwritten \nconsole.log(Object.getPrototypeOf(decoded)); // Map(1) { 1 => 2 } \nconsole.log(decoded.get); // [Function: get] \n\n// decoded appears to most common typechecks to be a Map \nconsole.log(decoded instanceof Map); // true \nconsole.log(decoded.toString()); // [object Map] \nconsole.log(Object.prototype.toString.call(decoded)); // [object Map] \nconsole.log(decoded.constructor.name); // Map \nconsole.log(Object.getPrototypeOf(decoded).constructor.name); // Map \n\n// decoded is not, however, a Map \nconsole.log(Object.getPrototypeOf(decoded) === Map.prototype); // false \n\n// using decoded as though it were a Map throws \ntry { \ndecoded.get(1); \n} catch (error) { \nconsole.log(error); // TypeError: Method Map.prototype.get called \n// on incompatible receiver #<Map> \n} \ntry { \ndecoded.size; \n} catch (error) { \nconsole.log(error); // TypeError: Method get Map.prototype.size \n// called on incompatible receiver #<Map> \n} \n\n// re-encoding the decoded value throws \ntry { \nmsgpack5.encode(decoded); \n} catch (error) { \nconsole.log(error); // TypeError: Method Map.prototype.entries \n// called on incompatible receiver #<Map> \n} \n``` \n\nThis \"prototype poisoning\" is sort of a very limited inversion of a \nprototype pollution attack. Only the decoded value's prototype is \naffected, and it can only be set to `msgpack5` values (though if the \nvictim makes use of custom codecs, anything could be a `msgpack5` \nvalue). We have not found a way to escalate this to true prototype \npollution (absent other bugs in the consumer's code). \n\n### Patches\n\nVersions v5.2.1, v4.5.1, v3.6.1 include the fix.\n\n### Workarounds\n\nAlways validate incoming data after parsing before doing any processing.\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [example link to repo](http://example.com)\n* Email us at [example email address](mailto:example@example.com)",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:L/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "msgpack5"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.6.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "msgpack5"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "4.5.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "msgpack5"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "5.0.0"
}, {
"fixed" : "5.2.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/mcollina/msgpack5/security/advisories/GHSA-gmjw-49p4-pcfm"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21368"
}, {
"type" : "WEB",
"url" : "https://github.com/mcollina/msgpack5/commit/d4e6cb956ae51c8bb2828e71c7c1107c340cf1e8"
}, {
"type" : "WEB",
"url" : "https://github.com/mcollina/msgpack5/releases/tag/v3.6.1"
}, {
"type" : "WEB",
"url" : "https://github.com/mcollina/msgpack5/releases/tag/v4.5.1"
}, {
"type" : "WEB",
"url" : "https://github.com/mcollina/msgpack5/releases/tag/v5.2.1"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/package/msgpack5"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1321", "CWE-915" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2021-03-12T16:57:44Z",
"nvd_published_at" : "2021-03-12T17:15:00Z"
}
}