@@ -84,14 +84,14 @@ function onBeforeRequest(details) {
8484 if ( canonical_host . charAt ( canonical_host . length - 1 ) == "." ) {
8585 while ( canonical_host . charAt ( canonical_host . length - 1 ) == "." )
8686 canonical_host = canonical_host . slice ( 0 , - 1 ) ;
87+ uri . hostname ( canonical_host ) ;
8788 }
88- uri . hostname ( canonical_host ) ;
8989
9090 // If there is a username / password, put them aside during the ruleset
9191 // analysis process
92- var tmpuserinfo = tmpuri . userinfo ( ) ;
92+ var tmpuserinfo = uri . userinfo ( ) ;
9393 if ( tmpuserinfo ) {
94- tmpuri . userinfo ( '' ) ;
94+ uri . userinfo ( '' ) ;
9595 }
9696
9797 var canonical_url = uri . toString ( ) ;
@@ -107,7 +107,7 @@ function onBeforeRequest(details) {
107107 activeRulesets . removeTab ( details . tabId ) ;
108108 }
109109
110- var rs = all_rules . potentiallyApplicableRulesets ( a . hostname ) ;
110+ var rs = all_rules . potentiallyApplicableRulesets ( uri . hostname ( ) ) ;
111111 // If no rulesets could apply, let's get out of here!
112112 if ( rs . length === 0 ) { return ; }
113113
@@ -119,7 +119,7 @@ function onBeforeRequest(details) {
119119 if ( redirectCounter [ details . requestId ] > 9 ) {
120120 log ( NOTE , "Redirect counter hit for " + canonical_url ) ;
121121 urlBlacklist [ canonical_url ] = true ;
122- var hostname = tmpuri . hostname ( ) ;
122+ var hostname = uri . hostname ( ) ;
123123 domainBlacklist [ hostname ] = true ;
124124 log ( WARN , "Domain blacklisted " + hostname ) ;
125125 return ;
@@ -137,7 +137,7 @@ function onBeforeRequest(details) {
137137 }
138138 }
139139
140- if ( newuristr && tmpuserinfo != "" ) {
140+ if ( newuristr && tmpuserinfo !== "" ) {
141141 // re-insert userpass info which was stripped temporarily
142142 // while rules were applied
143143 var finaluri = new URI ( newuristr ) ;
@@ -330,25 +330,17 @@ function onCookieChanged(changeInfo) {
330330}
331331
332332// This event is needed due to the potential race between cookie permissions
333- // update and cookie transmission, because the cookie API is non-blocking.
334- // It would be less perf impact to have a blocking version of the cookie API
335- // available instead .
333+ // update and cookie transmission ( because the cookie API is non-blocking) .
334+ // Without this function, an aggressive attacker could race to steal a not-yet-secured
335+ // cookie if they controlled & could redirect the user to a non-SSL subdomain .
336336// WARNING: This is a very hot function.
337337function onBeforeSendHeaders ( details ) {
338- // XXX this function appears to enforce something equivalent to the secure
339- // cookie flag by independent means. Is that really what it's supposed to
340- // do?
341- // @@@ Agreed, this function is really weird. I'm not sure it's even useful
342- // since we block WebRequests to HTTP sites (and maybe rewrite them to SSL)
343- // we force cookies to be sent over HTTPS even if they don't have the flag
344- // "Secure" set. (Unless I'm reading this wrong?)
345338 // TODO: Verify this with wireshark
346339 for ( var h in details . requestHeaders ) {
347340 if ( details . requestHeaders [ h ] . name == "Cookie" ) {
348341 // Per RFC 6265, Chrome sends only ONE cookie header, period.
349- var a = document . createElement ( "a" ) ;
350- a . href = details . url ;
351- var host = a . hostname ;
342+ var uri = new URI ( details . url ) ;
343+ var host = uri . hostname ( ) ;
352344
353345 var newCookies = [ ] ;
354346 var cookies = details . requestHeaders [ h ] . value . split ( ";" ) ;
0 commit comments