aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-25 08:48:27 -0500
committerGitHub <noreply@github.com>2020-01-25 08:48:27 -0500
commitf3e6351e472bdbc3b574a7734437c9f8cd1b60cc (patch)
tree273a262008942347ab5a1db5f41921d64a34e735
parent53879945a9ee3a3c74d36af791bb52d95fd93366 (diff)
parent6d31827464fb4eb18dfd891fcedfd40fb955aae8 (diff)
downloadservo-f3e6351e472bdbc3b574a7734437c9f8cd1b60cc.tar.gz
servo-f3e6351e472bdbc3b574a7734437c9f8cd1b60cc.zip
Auto merge of #25598 - pshaughn:cookieexpire, r=jdm
Expire cookies on lookup <!-- Please describe your changes on the following line: --> Cookies were rarely, if ever, expiring; this caused tests that used max-age=0 as a cookie deletion method to have cookies they shouldn't have had. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24911 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
-rw-r--r--components/net/cookie_storage.rs12
-rw-r--r--components/net/http_loader.rs1
-rw-r--r--components/net/resource_thread.rs2
-rw-r--r--components/net/websocket_loader.rs1
-rw-r--r--tests/wpt/metadata/fetch/api/cors/cors-cookies-redirect.any.js.ini15
-rw-r--r--tests/wpt/metadata/fetch/api/cors/cors-cookies.any.js.ini26
-rw-r--r--tests/wpt/metadata/fetch/api/credentials/cookies.any.js.ini29
7 files changed, 16 insertions, 70 deletions
diff --git a/components/net/cookie_storage.rs b/components/net/cookie_storage.rs
index 0f37ae754b9..f0815635476 100644
--- a/components/net/cookie_storage.rs
+++ b/components/net/cookie_storage.rs
@@ -10,6 +10,7 @@ use net_traits::pub_domains::reg_suffix;
use net_traits::CookieSource;
use servo_url::ServoUrl;
use std::cmp::Ordering;
+use std::collections::hash_map::Entry;
use std::collections::HashMap;
use time::{self, Tm};
@@ -144,6 +145,17 @@ impl CookieStorage {
}
}
+ pub fn remove_expired_cookies_for_url(&mut self, url: &ServoUrl) {
+ let domain = reg_host(url.host_str().unwrap_or(""));
+ if let Entry::Occupied(mut entry) = self.cookies_map.entry(domain) {
+ let cookies = entry.get_mut();
+ cookies.retain(|c| !is_cookie_expired(&c));
+ if cookies.len() == 0 {
+ entry.remove_entry();
+ }
+ }
+ }
+
// http://tools.ietf.org/html/rfc6265#section-5.4
pub fn cookies_for_url(&mut self, url: &ServoUrl, source: CookieSource) -> Option<String> {
let filterer = |c: &&mut Cookie| -> bool {
diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs
index e48174443a2..0d0d7c46368 100644
--- a/components/net/http_loader.rs
+++ b/components/net/http_loader.rs
@@ -248,6 +248,7 @@ pub fn set_request_cookies(
cookie_jar: &RwLock<CookieStorage>,
) {
let mut cookie_jar = cookie_jar.write().unwrap();
+ cookie_jar.remove_expired_cookies_for_url(url);
if let Some(cookie_list) = cookie_jar.cookies_for_url(url, CookieSource::HTTP) {
headers.insert(
header::COOKIE,
diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs
index f85d623fe4f..bdbc815baa4 100644
--- a/components/net/resource_thread.rs
+++ b/components/net/resource_thread.rs
@@ -291,6 +291,7 @@ impl ResourceChannelManager {
},
CoreResourceMsg::GetCookiesForUrl(url, consumer, source) => {
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
+ cookie_jar.remove_expired_cookies_for_url(&url);
consumer
.send(cookie_jar.cookies_for_url(&url, source))
.unwrap();
@@ -300,6 +301,7 @@ impl ResourceChannelManager {
},
CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => {
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
+ cookie_jar.remove_expired_cookies_for_url(&url);
let cookies = cookie_jar
.cookies_data_for_url(&url, source)
.map(Serde)
diff --git a/components/net/websocket_loader.rs b/components/net/websocket_loader.rs
index 76dccfc2270..93bb031dca8 100644
--- a/components/net/websocket_loader.rs
+++ b/components/net/websocket_loader.rs
@@ -70,6 +70,7 @@ impl<'a> Handler for Client<'a> {
}
let mut cookie_jar = self.http_state.cookie_jar.write().unwrap();
+ cookie_jar.remove_expired_cookies_for_url(self.resource_url);
if let Some(cookie_list) = cookie_jar.cookies_for_url(self.resource_url, CookieSource::HTTP)
{
req.headers_mut()
diff --git a/tests/wpt/metadata/fetch/api/cors/cors-cookies-redirect.any.js.ini b/tests/wpt/metadata/fetch/api/cors/cors-cookies-redirect.any.js.ini
deleted file mode 100644
index e741b7a8478..00000000000
--- a/tests/wpt/metadata/fetch/api/cors/cors-cookies-redirect.any.js.ini
+++ /dev/null
@@ -1,15 +0,0 @@
-[cors-cookies-redirect.any.worker.html]
- [Untitled]
- expected: FAIL
-
- [cors-cookies-redirect]
- expected: FAIL
-
-
-[cors-cookies-redirect.any.html]
- [Untitled]
- expected: FAIL
-
- [cors-cookies-redirect]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/fetch/api/cors/cors-cookies.any.js.ini b/tests/wpt/metadata/fetch/api/cors/cors-cookies.any.js.ini
deleted file mode 100644
index ccbcd99802d..00000000000
--- a/tests/wpt/metadata/fetch/api/cors/cors-cookies.any.js.ini
+++ /dev/null
@@ -1,26 +0,0 @@
-[cors-cookies.any.html]
- type: testharness
- [Include mode: local cookies are not sent with remote request]
- expected: FAIL
-
- [Include mode: remote cookies are not sent with local request]
- expected: FAIL
-
-
-[cors-cookies.any.worker.html]
- type: testharness
- [Include mode: local cookies are not sent with remote request]
- expected: FAIL
-
- [Include mode: remote cookies are not sent with local request]
- expected: FAIL
-
- [Include mode: remote cookies are not sent with local request]
- expected: FAIL
-
- [Include mode: local cookies are not sent with remote request]
- expected: FAIL
-
- [cors-cookies]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/fetch/api/credentials/cookies.any.js.ini b/tests/wpt/metadata/fetch/api/credentials/cookies.any.js.ini
deleted file mode 100644
index 8902979dbe4..00000000000
--- a/tests/wpt/metadata/fetch/api/credentials/cookies.any.js.ini
+++ /dev/null
@@ -1,29 +0,0 @@
-[cookies.any.html]
- type: testharness
- [Include mode: 2 cookies]
- expected: FAIL
-
- [Omit mode: no cookie is stored]
- expected: FAIL
-
- [Same-origin mode: 1 cookie]
- expected: FAIL
-
- [Same-origin mode: 2 cookies]
- expected: FAIL
-
-
-[cookies.any.worker.html]
- type: testharness
- [Include mode: 2 cookies]
- expected: FAIL
-
- [Omit mode: no cookie is stored]
- expected: FAIL
-
- [Same-origin mode: 1 cookie]
- expected: FAIL
-
- [Same-origin mode: 2 cookies]
- expected: FAIL
-