Skip to content

Commit db744f5

Browse files
semenkodiracdeltas
authored andcommitted
Remove onHeadersReceived listener
The onHeadersReceived listener served one purpose: Secure cookies set via HTTPS (not HTTP, not JS) This task is already handled by: - onBeforeSendHeaders (blocking) which should secure cookies - onCookieChanged (non-blocking) which secures any cookies on create/update Moreover, the current function is broken: - We look for a case-sensitive "Set-Cookie," but many servers send only a lowercase "set-cookie" (e.g. Google, Twitter, ...) - "; Secure" is frequently not the end of the cookie (old #L192) By removing this function, here's what happens for different cookie types: - Set by HTTP No change, wasn't ever handled by onHeadersReceived - Set by Javascript No change, wasn't ever handled by onHeadersReceived - Set by HTTPS Now (as before) secured by onCookieChanged (non-blocking, so maybe a tiny window for a race to steal the cookie, but ...) Secured by onBeforeSendHeaders (blocking) Signed-off-by: Nick Semenkovich <semenko@alum.mit.edu>
1 parent b865eca commit db744f5

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

chromium/background.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -177,35 +177,6 @@ function onCookieChanged(changeInfo) {
177177
}
178178
}
179179

180-
// Check to see if a newly set cookie in an HTTP request should be secured
181-
function onHeadersReceived(details) {
182-
var a = document.createElement("a"); // hack to parse URLs
183-
a.href = details.url; //
184-
var host = a.hostname;
185-
186-
// TODO: Verify this with wireshark
187-
for (var h in details.responseHeaders) {
188-
if (details.responseHeaders[h].name == "Set-Cookie") {
189-
log(INFO,"Deciding whether to secure cookies in " + details.url);
190-
var cookie = details.responseHeaders[h].value;
191-
192-
if (cookie.indexOf("; Secure") == -1) {
193-
log(INFO, "Got insecure cookie header: "+cookie);
194-
// Create a fake "nsICookie2"-ish object to pass in to our rule API:
195-
var fake = {domain:host, name:cookie.split("=")[0]};
196-
var ruleset = all_rules.shouldSecureCookie(fake, true);
197-
if (ruleset) {
198-
activeRulesets.addRulesetToTab(details.tabId, ruleset);
199-
details.responseHeaders[h].value = cookie+"; Secure";
200-
log(INFO, "Secured cookie: "+details.responseHeaders[h].value);
201-
}
202-
}
203-
}
204-
}
205-
206-
return {responseHeaders:details.responseHeaders};
207-
}
208-
209180
// This event is needed due to the potential race between cookie permissions
210181
// update and cookie transmission, because the cookie API is non-blocking.
211182
// It would be less perf impact to have a blocking version of the cookie API
@@ -279,11 +250,6 @@ wr.onBeforeRequest.addListener(onBeforeRequest, {urls: ["https://*/*", "http://*
279250
wr.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: ["http://*/*"]},
280251
["requestHeaders", "blocking"]);
281252

282-
// This parses HTTPS cookies and may set their secure flag.
283-
// We never do this for cookies set by HTTP.
284-
wr.onHeadersReceived.addListener(onHeadersReceived, {urls: ["https://*/*"]},
285-
["responseHeaders", "blocking"]);
286-
287253
wr.onResponseStarted.addListener(onResponseStarted,
288254
{urls: ["https://*/*", "http://*/*"]});
289255
wr.onErrorOccurred.addListener(onErrorOccurred,

0 commit comments

Comments
 (0)