
Fix open source package uses tough-cookie 2.5.0 - CVE-2023-26136,
Versions of the package tough-cookie before 4.1.3 are vulnerable to Prototype Pollution due to improper handling of Cookies when using CookieJar in rejectPublicSuffixes=false mode. This issue arises from the manner in which the objects are initialized.
https://nvd.nist.gov/vuln/detail/CVE-2023-26136
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as proto, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution
There are two main ways in which the pollution of prototypes occurs:
important not: https://github.com/salesforce/tough-cookie/issues/282
=> To fix the vulnerability in the MemoryCookieStore class, you need to modify the putCookie method to prevent prototype pollution when cookie.domain is set to proto.
a. Change tough_cookie_2.5.0\node_modules\tough-cookie\lib\memstore.js
All occurrences of new object creation in memstore.js have been changed from {} Object.create(Object.prototype) to Object.create(null)
so that we are using object instances that do not have a prototype property that can be polluted.
b. Created a new , /node_modules/tough-cookie/lib/test-unit.js use in vanillajs for it found in tests folder file cookie_jar_test.js "Issue #282 - Prototype pollution"
Command: node test-unit.js
c. Created a new file,/node_modules/tough-cookie/lib/testVerifyVulnerable.js verify the vulnerable behavior was fixed.
Command: node testVerifyVulnerable.js
a. Regular package tough-cookie V 2.5.0
Command: npm install [email protected] && node index.js
b. Compress package tough-cookie V 2.5.0 tgz format with changes
Command: npm install ./tough-cookie-2.5.0-PATCHED.tgz && node index.js
c.
Prototype Pollution: By adding properties directly to Object. prototype, there's a risk of polluting the entire prototype chain. This can lead to unexpected behavior across the application, as any object that traverses the prototype chain may be affected.
Security Risks: In a web application context, prototype pollution can be exploited by attackers to manipulate objects and properties, potentially leading to security vulnerabilities such as privilege escalation, information leakage.
Compatibility Issues: Modifying core prototypes like Object. prototype can introduce compatibility issues with other libraries or frameworks that rely on standard behavior. This can cause errors or unexpected behavior when integrating or updating dependencies. d. wrote above.
How to install this project