
ecurity patch for CVE-2023-26136 in tough-cookie 2.5.0 - Prototype pollution vulnerability fix with backward compatibility
This project addresses CVE-2023-26136, a critical prototype pollution vulnerability in tough-cookie versions before 4.1.3. The vulnerability affects Penguin Software Inc.'s web application, which uses [email protected] for cookie processing.
CVE-2023-26136 is a prototype pollution vulnerability that occurs when CookieJar is used with rejectPublicSuffixes=false. The issue arises from improper object initialization in the MemoryCookieStore class, allowing attackers to inject properties into the Object.prototype through maliciously crafted cookie domains.
The vulnerability exists in lib/memstore.js where cookies are stored using plain JavaScript objects ({}). Since these objects inherit from Object.prototype, attackers can exploit this by setting cookies with domains like __proto__, constructor, or prototype, leading to prototype pollution.
The fix replaces all instances of {} with Object.create(null) in the MemoryCookieStore class:
// Before (vulnerable)
this.idx = {};
// After (fixed)
this.idx = Object.create(null);
This change prevents prototype pollution by creating objects with no prototype chain, effectively isolating cookie storage from unintended inheritance.
lib/memstore.js: Updated object initialization to use Object.create(null)├── README.md # This file
├── changes.diff # Git-compatible diff file
├── test-cve-2023-26136.js # Unit test for the fix
├── tough-cookie/
│ ├── index.js # Exploit demonstration
│ ├── Original v2.5.0/ # Original vulnerable version
│ ├── v2.5.0-PATCHED/ # Patched version
│ │ └── tough-cookie-2.5.0.tgz # Packed version
│ └── package.json
└── mission.txt # Original mission requirements
The patched version is available as tough-cookie/v2.5.0-PATCHED/tough-cookie-2.5.0.tgz.
To install:
npm install ./tough-cookie/v2.5.0-PATCHED/tough-cookie-2.5.0.tgz
The original tough-cookie test suite should pass. To run tests:
cd tough-cookie/v2.5.0-PATCHED
npm install
npm test
Note: The original tough-cookie 2.5.0 doesn't include a test directory in this distribution, but the patched version maintains full compatibility with the original API.
Run the custom unit test to verify the fix:
node test-cve-2023-26136.js
Expected output:
Testing CVE-2023-26136 fix...
✅ CVE-2023-26136 fix verified: No prototype pollution detected
✅ Test passed: The vulnerability has been successfully patched
The project includes an exploit demonstration in tough-cookie/index.js:
cd tough-cookie
node index.js
This will test both the original vulnerable version and the patched version, showing:
EXPLOITED SUCCESSFULLY for the original versionEXPLOIT FAILED for the patched versionThe changes.diff file contains a git-compatible diff that can be applied using:
git apply changes.diff
This diff includes only the necessary changes to fix the vulnerability without any unintended modifications.
The exploit works by:
CookieJar with rejectPublicSuffixes: false__proto__Object.prototype chainPotential Damage:
✅ Tested and verified on Node.js 20 (LTS)
GitHub Repository: Forked tough-cookie repository
Git Tag: v2.5.0-patched-cve-2023-26136-fix
GitHub Actions - Expert level
Jenkins - Advanced level
Travis CI - Intermediate level
CircleCI - Intermediate level
GitLab CI/CD - Advanced level
This project maintains the original tough-cookie license (BSD-3-Clause) while adding the security fix.
Note: This is a security-focused patch that maintains full backward compatibility while eliminating the CVE-2023-26136 vulnerability.