New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 707525 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Apr 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , All
Pri: 2
Type: Bug-Security



Sign in to add a comment

Security: Service workers do not respect 'unsafe-eval' in their CSP

Project Member Reported by a...@google.com, Apr 1 2017

Issue description

VULNERABILITY DETAILS
I can't imagine this leading to an actual problem, but the behavior was surprising to me so here goes:

Service workers obey the policy sent in the HTTP response which returns the service worker. For example, if the SW has a CSP and tries to call importScripts('foo.js') this will fail unless the CSP contains script-src 'self'.

However, restrictions on eval() (e.g. script-src 'none', *without* 'unsafe-eval') have no effect on SWs. Serving a worker with such a policy still allows it to call eval() and does not cause a CSP violation; I believe it should do so.

VERSION
Chrome Version: Tested on M57, M59 (59.0.3053.3)
Operating System: Linux (Ubuntu)

REPRODUCTION CASE

HTML:
<head>
  <meta http-equiv="content-security-policy" 
        content="script-src 'nonce-foo' 'self'; worker-src *">
</head>

<script nonce=foo>
  navigator.serviceWorker.register('/cgi-bin/service-worker-with-csp.py', 
      {scope: '/cgi-bin/'}).then(function(registration) {
    console.log('SW registered');
    }).catch(function(error) {
    console.log('SW error');
  });
</script>

JS:
#!/usr/bin/python
import cgi
import cgitb
cgitb.enable()

print """\
Content-Type: text/javascript; charset=utf-8
Content-Security-Policy: script-src 'self';

console.log(eval(1));
self.importScripts('service-worker-foo.py');
"""

Output:
> 1
> SW registered

 
Project Member

Comment 1 by sheriffbot@chromium.org, Apr 2 2017

Status: Assigned (was: Unconfirmed)

Comment 2 by ta...@google.com, Apr 3 2017

Components: Blink>ServiceWorker
Labels: -Pri-3 Security_Severity-Medium Security_Impact-Stable Pri-2

Comment 3 by ta...@google.com, Apr 3 2017

Labels: OS-Linux OS-All
Project Member

Comment 4 by sheriffbot@chromium.org, Apr 4 2017

Labels: M-58

Comment 5 by a...@google.com, Apr 5 2017

Quick update: I just noticed that in Chrome CSP blocks eval(String) but not eval(Number) or eval(Object). This is probably fine and consistent with what I saw above, so I assume this is WAI...

Comment 6 by mkwst@chromium.org, Apr 6 2017

Cc: mkwst@chromium.org
Owner: jochen@chromium.org
Jochen knows things about V8 and eval and types. Sooooo....
https://tc39.github.io/ecma262/#sec-performeval step 2 says if the arg of eval() is not  a string to return the arg verbatim.

would you like CSP to block that behavior as well?
Status: WontFix (was: Assigned)
filed https://github.com/w3c/webappsec-csp/issues/201 to track the spec issue, closing this issue for now

Comment 9 by a...@google.com, Apr 10 2017

Sounds good, thanks for taking a look!
Project Member

Comment 10 by sheriffbot@chromium.org, Jul 14 2017

Labels: -Restrict-View-SecurityTeam allpublic
This bug has been closed for more than 14 weeks. Removing security view restrictions.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Sign in to add a comment