New issue
Advanced search Search tips

Issue 610488 link

Starred by 3 users

Issue metadata

Status: Duplicate
Merged: issue 453843
Owner: ----
Closed: May 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

chrome.webRequest.onHeadersReceived listener sometimes not called

Reported by derj...@googlemail.com, May 9 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36

Steps to reproduce the problem:
1. install the attached crx
2. open the extension background page
3. navigate to https://tampermonkey.net/empty.html
4. see "https://tampermonkey.net/empty.html" being logged
5. navigate to https://www.ingdirect.com.au/securebanking/
6. open new tabs with this URL until "https://www.ingdirect.com.au/securebanking/" is NOT logged
7. reload the page and see it still not being logged
8. open the dev tool -> network tab and enable "Disable Cache" and reload the page
9. see https://www.ingdirect.com.au/securebanking/ being logged

What is the expected behavior?
The chrome.webRequest.onHeadersReceived listener should always be called and log the URL.

What went wrong?
chrome.webRequest.onHeadersReceive sometimes isn't called

WebStore page: https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo

Did this work before? Yes 49.0.2623.108

Chrome version: 50.0.2661.94  Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: Shockwave Flash 21.0 r0

Reproducable at Windows 7 and Version 50.0.2661.94 m 
and Ubuntu 14.04 52.0.2723.2 dev + 51.0.2704.36
 
webRequest.crx
2.7 KB Download
I did some more investigation and it now looks like I was wrong. This is not a regression. :(

However, since chrome.webRequest.onHeadersReceived is not called and the original response headers are used, there is no way for an extension to persistently modify the headers of such cached pages.

Comment 2 by rob@robwu.nl, May 12 2016

Cc: rob@robwu.nl
Mergedinto: 453843
Status: Duplicate (was: Unconfirmed)
When I open chrome://net-internals and follow the above steps, I see the following log entry at some point. So it is a duplicate of issue 453843.

Out of curiousity - why do you want to modify headers in Tampermonkey?

1036: URL_REQUEST
https://www.ingdirect.com.au/securebanking/
Start Time: 2016-05-13 00:30:05.491

t=0 [st=0] +REQUEST_ALIVE  [dt=3]
t=0 [st=0]    DELEGATE_INFO  [dt=1]
              --> delegate_info = "NavigationResourceThrottle"
t=2 [st=2]    URL_REQUEST_DELEGATE  [dt=0]
t=2 [st=2]   +URL_REQUEST_START_JOB  [dt=0]
              --> load_flags = 37121 (MAIN_FRAME | MAYBE_USER_GESTURE | VALIDATE_CACHE | VERIFY_EV_CERT)
              --> method = "GET"
              --> priority = "HIGHEST"
              --> url = "https://www.ingdirect.com.au/securebanking/"
t=2 [st=2]      APPCACHE_DELIVERING_CACHED_RESPONSE
t=2 [st=2]   -URL_REQUEST_START_JOB
t=2 [st=2]   +URL_REQUEST_DELEGATE  [dt=1]
t=2 [st=2]      DELEGATE_INFO  [dt=0]
                --> delegate_info = "NavigationResourceThrottle"
t=3 [st=3]   -URL_REQUEST_DELEGATE
t=3 [st=3]    URL_REQUEST_JOB_BYTES_READ
              --> byte_count = 2605
t=3 [st=3] -REQUEST_ALIVE
> Out of curiousity - why do you want to modify headers in Tampermonkey?

As you know, Tampermonkey executes user defined scripts. 
These userscripts are stored at the background page and are retrieved by the content script via asynchronous communication. (executeScript is at the moment not reliable enough 471801) 
This means the page's scripts might have been executed already when the userscripts arrive at the content script. 
Unfortunately script tags that are injected by content scripts after document_start can be discovered by the page using a MutationObserver and this allows the page to parse the content of the script tag and to hook into the Tampermonkey page script and content script communication.

In order to avoid this a very small piece of code is injected at document_start which establishes a communication bridge, but this requires the userscript code that can only be transferred as a string to be eval'ed.
That's why TM relaxes the CSP of pages where a userscript is supposed to run to allow unsafe-eval.

Comment 4 by rob@robwu.nl, May 13 2016

Don't use eval, but an inline script and you don't have to touch the CSP headers.

Try the following extension for example. It shows that eval is indeed blocked in all cases, but <script> tags (inline and with src) are not blocked if the content script injected it.

To try it out, put csp.html on some website (e.g. localhost), load the extension and visit csp.html
csp.html
217 bytes View Download
manifest.json
292 bytes View Download
contentscript.js
410 bytes View Download
injectedscript.js
119 bytes View Download
> Don't use eval, but an inline script and you don't have to touch the CSP headers.

I know, but as I said: inline scripts that are injected after document_start can be detected and read by the page's scripts using a MutationObserver.

Sign in to add a comment