From f72975d811a7622f32d66315276a9c8857f20090 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 11 Jul 2014 12:20:31 +0200 Subject: [PATCH] wininet: Don't allow overriding httponly cookies with non-httponly ones. --- dlls/wininet/cookie.c | 8 ++++++++ dlls/wininet/tests/internet.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c index 0af8c38dafe..8bf8953f9aa 100644 --- a/dlls/wininet/cookie.c +++ b/dlls/wininet/cookie.c @@ -963,6 +963,14 @@ DWORD set_cookie(const WCHAR *domain, const WCHAR *path, const WCHAR *cookie_nam if ((thisCookie = COOKIE_findCookie(thisCookieDomain, cookie_name))) { + if ((thisCookie->flags & INTERNET_COOKIE_HTTPONLY) && !(flags & INTERNET_COOKIE_HTTPONLY)) { + WARN("An attempt to override httponly cookie\n"); + SetLastError(ERROR_INVALID_OPERATION); + heap_free(data); + if (value != data) heap_free(value); + return COOKIE_STATE_REJECT; + } + if (!(thisCookie->flags & INTERNET_COOKIE_IS_SESSION)) update_persistent = TRUE; COOKIE_deleteCookie(thisCookie, FALSE); diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 17e16aba395..688f7862414 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -595,6 +595,21 @@ static void test_cookie_attrs(void) ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL); ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError()); ok(!strcmp(buf, "A=data"), "data = %s\n", buf); + + /* Try to override httponly cookie with non-httponly one */ + ret = InternetSetCookieA("http://cookie.attrs.com/bar", NULL, "A=test"); + ok(!ret && GetLastError() == ERROR_INVALID_OPERATION, "InternetSetCookie returned: %x (%u)\n", ret, GetLastError()); + + SetLastError(0xdeadbeef); + state = InternetSetCookieExA("http://cookie.attrs.com/bar", NULL, "A=data", 0, 0); + ok(state == COOKIE_STATE_REJECT && GetLastError() == ERROR_INVALID_OPERATION, + "InternetSetCookieEx returned: %x (%u)\n", ret, GetLastError()); + + size = sizeof(buf); + ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL); + ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError()); + ok(!strcmp(buf, "A=data"), "data = %s\n", buf); + } static void test_cookie_url(void)