Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a guard against maliciously-sized cookies #39

Merged
merged 2 commits into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev
fix: bump limit to 32K
  • Loading branch information
andyburke committed Dec 9, 2022
commit eaa00021caf6ae09449dde826108153b578348e5
4 changes: 2 additions & 2 deletions cookiejar.js
Expand Up @@ -64,8 +64,8 @@

var cookie_str_splitter = /[:](?=\s*[a-zA-Z0-9_\-]+\s*[=])/g;
Cookie.prototype.parse = function parse(str, request_domain, request_path) {
if ( str.length > 4096 ) {
console.warn("Cookie too long for parsing (>4096 characters)");
if ( str.length > 32768 ) {
console.warn("Cookie too long for parsing (>32768 characters)");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test.js
Expand Up @@ -68,7 +68,7 @@ assert.equal(cookie.path, "/");
assert.deepEqual(cookie, new Cookie("a=1;domain=.test.com;path=/"));

// ensure cookies that are too long are not parsed to avoid any issues with DoS inputs
var too_long_cookie = new Cookie( "foo=" + "blah".repeat( 2000 ) );
var too_long_cookie = new Cookie( "foo=" + "blah".repeat( 10000 ) );
assert.equal(too_long_cookie, undefined);

// Test request_path and request_domain
Expand Down