Source/WebCore/ChangeLog

 12013-02-18 Peter Nelson <peter@peterdn.com>
 2
 3 [WinCairo] Support for cookies is incomplete
 4 https://bugs.webkit.org/show_bug.cgi?id=110147
 5
 6 All cookies are now correctly accessible from JavaScript.
 7 Expired and HttpOnly cookies no longer accessible from JavaScript.
 8 Cookies set in JavaScript now have correct domain/path.
 9
 10 Reviewed by NOBODY (OOPS!).
 11
 12 Test: http/tests/cookies/http-get-cookie-set-in-js.html
 13 Enabled other cookie tests for WinCairo.
 14
 15 * platform/network/curl/CookieJarCurl.cpp:
 16 (WebCore::isExpired):
 17 (WebCore::getNetscapeCookieFormat):
 18 (WebCore):
 19 (WebCore::setCookiesFromDOM):
 20 (WebCore::cookiesForDOM):
 21 (WebCore::cookieRequestHeaderFieldValue):
 22
1232013-02-18 Sheriff Bot <webkit.review.bot@gmail.com>
224
325 Unreviewed, rolling out r143145.
143251

Source/WebCore/platform/network/curl/CookieJarCurl.cpp

2727
2828namespace WebCore {
2929
30 static HashMap<String, String> cookieJar;
 30inline bool isExpired(int expiryUnixTime)
 31{
 32 return expiryUnixTime && expiryUnixTime < time(0);
 33}
3134
32 void setCookiesFromDOM(const NetworkStorageSession&, const KURL&, const KURL& url, const String& value)
 35String getNetscapeCookieFormat(const KURL& url, const String& value, bool* expired = 0)
3336{
34  cookieJar.set(url.string(), value);
 37 // Netscape cookie file format consists
 38 // of seven tab-separated fields:
 39 // 1. domain
 40 // 2. allow subdomains (TRUE/FALSE)
 41 // 3. path
 42 // 4. secure connection required (TRUE/FALSE)
 43 // 5. expiration (UNIX time)
 44 // 6. name
 45 // 7. value
 46
 47 if (value.isEmpty())
 48 return "";
 49
 50 String valueStr;
 51 if (value.is8Bit())
 52 valueStr = value;
 53 else
 54 valueStr = String::make8BitFrom16BitSource(value.characters16(), value.length());
 55
 56 Vector<String> attributes;
 57 valueStr.split(';', false, attributes);
 58
 59 if (attributes.size())
 60 return "";
3561
 62 // First attribute should be <cookiename>=<cookievalue>
 63 String cookieName, cookieValue;
 64 Vector<String>::iterator attribute = attributes.begin();
 65 if (attribute->contains('=')) {
 66 Vector<String> nameValuePair;
 67 attribute->split('=', true, nameValuePair);
 68 cookieName = nameValuePair[0];
 69 cookieValue = nameValuePair[1];
 70 } else {
 71 // According to RFC6265 we should ignore the entire
 72 // set-cookie string now, but other browsers appear
 73 // to treat this as <cookiename>=<empty>
 74 cookieName = *attribute;
 75 }
 76
 77 int expires = 0;
 78 String secure = "FALSE";
 79 String path = url.baseAsString().substring(url.pathStart());
 80 if (path.length() > 1 && path.endsWith('/'))
 81 path.remove(path.length() - 1);
 82 String domain = url.host();
 83
 84 // Iterate through remaining attributes
 85 for (++attribute; attribute != attributes.end(); ++attribute) {
 86 if (attribute->contains('=')) {
 87 Vector<String> keyValuePair;
 88 attribute->split('=', true, keyValuePair);
 89 String key = keyValuePair[0].stripWhiteSpace().lower();
 90 String val = keyValuePair[1].stripWhiteSpace();
 91 if (key == "expires") {
 92 CString dateStr(reinterpret_cast<const char*>(val.characters8()), val.length());
 93 expires = WTF::parseDateFromNullTerminatedCharacters(dateStr.data()) / WTF::msPerSecond;
 94 } else if (key == "max-age")
 95 expires = time(0) + val.toInt();
 96 else if (key == "domain")
 97 domain = val;
 98 else if (key == "path")
 99 path = val;
 100 } else {
 101 String key = attribute->stripWhiteSpace().lower();
 102 if (key == "secure")
 103 secure = "TRUE";
 104 }
 105 }
 106
 107 StringBuilder cookieStr;
 108 cookieStr.reserveCapacity(domain.length() + path.length() + cookieName.length() + cookieValue.length() + 26);
 109 cookieStr.append(domain + "\t");
 110 cookieStr.append(domain.startsWith('.') ? "TRUE\t" : "FALSE\t");
 111 cookieStr.append(path + "\t");
 112 cookieStr.append(secure + "\t");
 113 cookieStr.append(String::number(expires) + "\t");
 114 cookieStr.append(cookieName + "\t");
 115 cookieStr.append(cookieValue);
 116
 117 if (expired)
 118 *expired = isExpired(expires);
 119
 120 return cookieStr.toString();
 121}
 122
 123void setCookiesFromDOM(const NetworkStorageSession&, const KURL&, const KURL& url, const String& value)
 124{
36125 CURL* curl = curl_easy_init();
37126
38127 if (!curl)

@@void setCookiesFromDOM(const NetworkStor
45134 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieJarFileName);
46135 curl_easy_setopt(curl, CURLOPT_SHARE, curlsh);
47136
48  String cookie("Set-Cookie: ");
49  if (value.is8Bit())
50  cookie.append(value);
51  else
52  cookie.append(String::make8BitFrom16BitSource(value.characters16(), value.length()));
 137 // CURL accepts cookies in either Set-Cookie or Netscape file format.
 138 // However with Set-Cookie format, there is no way to specify that we
 139 // should not allow cookies to be read from subdomains, which is the
 140 // required behavior if the domain field is not explicity specified.
 141 bool expired = false;
 142 String cookie = getNetscapeCookieFormat(url, value, &expired);
53143
54144 CString strCookie(reinterpret_cast<const char*>(cookie.characters8()), cookie.length());
55 
56145 curl_easy_setopt(curl, CURLOPT_COOKIELIST, strCookie.data());
57146
58147 curl_easy_cleanup(curl);

@@void setCookiesFromDOM(const NetworkStor
60149
61150String cookiesForDOM(const NetworkStorageSession&, const KURL&, const KURL& url)
62151{
63  return cookieJar.get(url.string());
 152 CURL* curl = curl_easy_init();
 153
 154 if (!curl)
 155 return "";
 156
 157 const char* cookieJarFileName = ResourceHandleManager::sharedInstance()->getCookieJarFileName();
 158 CURLSH* curlsh = ResourceHandleManager::sharedInstance()->getCurlShareHandle();
 159
 160 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieJarFileName);
 161 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieJarFileName);
 162 curl_easy_setopt(curl, CURLOPT_SHARE, curlsh);
 163
 164 curl_slist* cookies;
 165 curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
 166
 167 String cookiesStr = "";
 168 for (curl_slist* cookie = cookies; cookie; cookie = cookie->next) {
 169 // Cookie data returned in Netscape cookie file format.
 170 String cookieStr(cookie->data);
 171 Vector<String> attributes;
 172 cookieStr.split('\t', true, attributes);
 173
 174 if (attributes.size() != 7)
 175 continue;
 176
 177 // Check for allowed domain, path, security, expiration.
 178 String domain = attributes[0];
 179
 180 // HttpOnly cookie lines begin with "#HttpOnly_".
 181 if (domain.startsWith("#HttpOnly_"))
 182 continue;
 183
 184 bool allowedDomain;
 185 if (domain.startsWith('.'))
 186 allowedDomain = url.host().endsWith(domain.substring(1));
 187 else
 188 allowedDomain = url.host() == domain;
 189
 190 bool allowedPath = url.path().startsWith(attributes[2]);
 191 bool secure = attributes[3] == "FALSE" || url.protocolIs("https");
 192
 193 int expiry = attributes[4].toInt();
 194 bool notExpired = !isExpired(expiry);
 195
 196 if (allowedDomain && allowedPath && secure && notExpired) {
 197 cookiesStr.append(cookiesStr.length() > 0 ? "; " : "");
 198 cookiesStr.append(attributes[5]);
 199 if (!attributes[6].isEmpty()) {
 200 cookiesStr.append("=");
 201 cookiesStr.append(attributes[6]);
 202 }
 203 }
 204 }
 205
 206 curl_slist_free_all(cookies);
 207 curl_easy_cleanup(curl);
 208
 209 return cookiesStr;
64210}
65211
66212String cookieRequestHeaderFieldValue(const NetworkStorageSession&, const KURL& /*firstParty*/, const KURL& url)
67213{
68214 // FIXME: include HttpOnly cookie.
69  return cookieJar.get(url.string());
 215 // return cookieJar.get(url.string());
 216 return "";
70217}
71218
72219bool cookiesEnabled(const NetworkStorageSession&, const KURL& /*firstParty*/, const KURL& /*url*/)
143213

LayoutTests/ChangeLog

 12013-02-18 Peter Nelson <peter@peterdn.com>
 2
 3 [WinCairo] Support for cookies is incomplete
 4 https://bugs.webkit.org/show_bug.cgi?id=110147
 5
 6 Re-enabled cookie tests for WinCairo.
 7 Added test to check whether cookie set in HTTP response is accessible in JS.
 8
 9 Reviewed by NOBODY (OOPS!).
 10
 11 * http/tests/cookies/http-get-cookie-set-in-js-expected.txt: Added.
 12 * http/tests/cookies/http-get-cookie-set-in-js.html: Added.
 13 * http/tests/cookies/resources/cookies-test-pre.js:
 14 (clearAllCookies): Cookies set in JS now correctly cleared.
 15 * platform/wincairo/TestExpectations:
 16
1172013-02-17 Filip Pizlo <fpizlo@apple.com>
218
319 Get rid of DFG::DoubleOperand and simplify ValueToInt32
143251

LayoutTests/http/tests/cookies/http-get-cookie-set-in-js-expected.txt

 1Test that a cookie set using JavaScript can be correctly read by HTTP server
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6checking that the cookie set in javascript can be read by HTTP server
 7PASS cookie is 'name=value'.
 8PASS successfullyParsed is true
 9
 10TEST COMPLETE
 11
0

LayoutTests/http/tests/cookies/http-get-cookie-set-in-js.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<link rel="stylesheet" href="resources/cookies-test-style.css">
 5<script src="resources/cookies-test-pre.js"></script>
 6</head>
 7<body>
 8<p id="description"></p>
 9<div id="console"></div>
 10<script>
 11description(
 12'Test that a cookie set using JavaScript can be correctly read by HTTP server'
 13);
 14
 15clearAllCookies();
 16
 17document.cookie = "name=value;Max-Age=1000";
 18
 19debug('checking that the cookie set in javascript can be read by HTTP server');
 20testCookies("name=value");
 21
 22clearCookies();
 23
 24successfullyParsed = true;
 25</script>
 26<script src="resources/cookies-test-post.js"></script>
 27</body>
 28</html>
0

LayoutTests/http/tests/cookies/resources/cookies-test-pre.js

@@function clearAllCookies()
204204 var cookieName = cookieString.substr(0, cookieString.indexOf("=") || cookieString.length());
205205 cookies.push(cookieName);
206206 clearCookies();
 207
 208 // In case clearCookies.cgi failed, for example,
 209 // the domain/path do not match exactly:
 210 document.cookie = cookieName + "=;Max-Age=0";
207211 }
208212}
209213
143213

LayoutTests/platform/wincairo/TestExpectations

@@transitions/svg-text-shadow-transition.h
528528
529529http/tests/cache
530530http/tests/canvas/philip/tests
531 http/tests/cookies
532531http/tests/css
533532http/tests/history
534533http/tests/incremental

@@fast/loader/create-frame-in-DOMContentLo
10321031# Times out <rdar://problem/9304941>
10331032http/tests/multipart/invalid-image-data-standalone.html
10341033
1035 # Sometimes fail <rdar://problem/9349921>
1036 http/tests/cookies/simple-cookies-expired.html
1037 http/tests/cookies/simple-cookies-max-age.html
1038 
10391034################################################################################
10401035####################### No bugs filed about the below yet#######################
10411036################################################################################

@@http/tests/security/xss-DENIED-window-op
27812776http/tests/security/xss-DENIED-window-open-parent.html
27822777http/tests/security/xss-DENIED-xsl-document-securityOrigin.xml
27832778
2784 # Flaky http/tests/cookie tests
2785 # https://bugs.webkit.org/show_bug.cgi?id=95805
2786 http/tests/cookies/multiple-cookies.html
2787 http/tests/cookies/single-quoted-value.html
2788 
27892779# Flaky media/video tests
27902780# https://bugs.webkit.org/show_bug.cgi?id=95806
27912781media/video-aspect-ratio.html
143213