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

cookie: reject cookie names or content with TAB characters #9659

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion lib/cookie.c
Expand Up @@ -538,7 +538,7 @@ Curl_cookie_add(struct Curl_easy *data,
do {
/* we have a <what>=<this> pair or a stand-alone word here */
name[0] = what[0] = 0; /* init the buffers */
if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n=] =%"
if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\t\r\n=] =%"
MAX_NAME_TXT "[^;\r\n]",
name, what)) {
/*
Expand Down Expand Up @@ -592,6 +592,13 @@ Curl_cookie_add(struct Curl_easy *data,
while(*whatptr && ISBLANK(*whatptr))
whatptr++;

/* Reject cookies with a TAB inside the content */
if(strchr(whatptr, '\t')) {
freecookie(co);
infof(data, "cookie contains TAB, dropping");
return NULL;
}

/*
* Check if we have a reserved prefix set before anything else, as we
* otherwise have to test for the prefix in both the cookie name and
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1105
Expand Up @@ -19,6 +19,9 @@ Funny-head: yesyes swsclose
Set-Cookie: foobar=name;
Set-Cookie: mismatch=this; domain=127.0.0.1; path="/silly/";
Set-Cookie: partmatch=present; domain=.0.0.1; path=/;
Set-Cookie: foo bar=barfoo
Set-Cookie: bar foo=
Set-Cookie: bar=foo bar

</data>
</reply>
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test8
Expand Up @@ -54,7 +54,7 @@ Set-Cookie: cookie5=%hex[%05-junk]hex%
Set-Cookie: cookie6=%hex[%06-junk]hex%
Set-Cookie: cookie7=%hex[%07-junk]hex%
Set-Cookie: cookie8=%hex[%08-junk]hex%
Set-Cookie: cookie9=%hex[junk-%09-]hex%
Set-Cookie: cookie9=%hex[junk--%09]hex%
Set-Cookie: cookie11=%hex[%0b-junk]hex%
Set-Cookie: cookie12=%hex[%0c-junk]hex%
Set-Cookie: cookie14=%hex[%0e-junk]hex%
Expand Down Expand Up @@ -90,7 +90,7 @@ GET /we/want/%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
User-Agent: curl/%VERSION
Accept: */*
Cookie: name with space=is weird but; trailingspace=removed; cookie=perhaps; cookie=yes; foobar=name; blexp=yesyes; cookie9=junk- -
Cookie: name with space=is weird but; trailingspace=removed; cookie=perhaps; cookie=yes; foobar=name; blexp=yesyes; cookie9=junk--

</protocol>
</verify>
Expand Down