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

Issue 611652 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Buried. Ping if important.
Closed: Jun 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , All
Pri: 1
Type: Bug



Sign in to add a comment

Violations to a Report-Only policy are enforced if a page sets both an enforcing and a Report-Only policy

Project Member Reported by a...@google.com, May 13 2016

Issue description

Chrome Version       : 50.0.2661.94 (also tested 51 and 52)
URLs (if applicable) : http://lingro.com:81/cgi-bin/csp-both-modes.py
Other browsers tested:
  Add OK or FAIL after other browsers where you have tested this issue:
  Firefox 46: OK

What steps will reproduce the problem?

1. Create a page setting 2 CSP policies, one in enforcement mode which uses nonces, and one as Content-Security-Policy-Report-Only.
2. Ensure that the policy in enforcement mode has a whitelist which would not permit all scripts to execute, but that every script on the page has a valid nonce -- so that the enforcing policy generates no violations.
3. Ensure that the Report-Only policy causes a violation.

What is the expected result?

The Report-Only policy causes a violation, a report is sent to the report-uri endpoint in the Report-Only policy, and all scripts execute normally.


What happens instead of that?

Chrome behaves as if the violation applied to the enforcing policy, prevents the script from running and reports a violation to the report-uri of the enforcing policy.


Repro case:

Content-Security-Policy: script-src 'nonce-foobar123'; report-uri /enforcing
Content-Security-Policy-Report-Only: script-src 'self'; report-uri /report-only

<html>
  <head>
    <script nonce="foobar123" src="/cgi-bin/jsonp-log.py?msg=external script in head"></script>
    <script nonce="foobar123" src="https://code.jquery.com/jquery-1.11.3.js"></script>
  </head>
</html>

In this case both scripts should run, but the code.jquery.com one should report a violation to the /report-only endpoint (this is what happens in FF). Instead, both scripts are blocked and two violations are sent to /enforcing. This is doubly strange because at least the first script should execute (it is allowed by both policies).

When the Report-Only policy is removed, the behavior is as expected (both scripts execute).

 

Comment 1 by mkwst@chromium.org, May 13 2016

Cc: est...@chromium.org
Components: Blink>SecurityFeature
Labels: -Pri-2 Pri-1
That does look like a bug. CCing Emily, as she's poked at some of this code recently, but I think I've poked at it more recently, so it's probably my fault (is this a recent regression?)

Comment 2 by mkwst@chromium.org, May 13 2016

Status: Started (was: Unconfirmed)
Bah. It looks like we've been handling report-only nonces wrong since the beginning of time. The logic in `isAllowedByAllWithNonce` is simply incorrect, as it treats both enforce and report-only mode as the same.

Comment 3 by mkwst@chromium.org, May 13 2016

https://codereview.chromium.org/1980533002 is up for review.

Comment 4 by a...@google.com, May 14 2016

Cc: slawek@google.com

Comment 5 by a...@google.com, May 20 2016

Cc: d...@dropbox.com
BTW, I chatted with +Dev about it today and tried with two enforcing policies, with a similar error. I believe 1980533002 might address it already, but since it doesn't have anything to do with a Report-Only policy, I figured sharing another repro case won't hurt:

print """\
Content-Type: text/html; charset=utf-8
Content-Security-Policy: script-src www.google.com; report-uri /enforcing
Content-Security-Policy: script-src 'nonce-foobar123'; report-uri /enforcing2

<html>
  <head>
    <!-- This should execute because it satisfies both policies -->
    <script nonce="foobar123" src="https://www.google.com/jsapi?callback=alert&1-ok"></script>

    <!-- This shouldn't execute because it violates the whitelist policy -->
    <script nonce="foobar123" src="https://apis.google.com/jsapi?callback=alert&2-bad"></script>

    <!-- This shouldn't execute because it violates the nonce policy -->
    <script src="https://www.google.com/jsapi?callback=alert&3-bad"></script>
  </head>
  <body>
  </body>
</html>
"""
 


Project Member

Comment 6 by bugdroid1@chromium.org, May 20 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a309dc2c752b103e6e858a92a0b68ab824212cb0

commit a309dc2c752b103e6e858a92a0b68ab824212cb0
Author: mkwst <mkwst@chromium.org>
Date: Fri May 20 22:30:11 2016

CSP: Fix handling of nonces in report-only mode.

Our current implementation will only allow a nonce to bypass whitelists if
it is present in all active policies, not just those delivered in
enforce-mode.

This patch adjusts the logic in ContentSecurityPolicy to ensure that nonces
bypass whitelists if and only if they are present in each enforced policy.
In particular, note that policies which do not contain the relevant directive
will no longer be considered as passing a nonce check (though they will, of
course, continue to pass the whitelist check which happens during fetching).

BUG= 611652 

Review-Url: https://codereview.chromium.org/1980533002
Cr-Commit-Position: refs/heads/master@{#395189}

[add] https://crrev.com/a309dc2c752b103e6e858a92a0b68ab824212cb0/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/multiple-policies-with-nonce.php
[modify] https://crrev.com/a309dc2c752b103e6e858a92a0b68ab824212cb0/third_party/WebKit/Source/core/frame/csp/CSPDirectiveList.cpp
[modify] https://crrev.com/a309dc2c752b103e6e858a92a0b68ab824212cb0/third_party/WebKit/Source/core/frame/csp/ContentSecurityPolicy.cpp

Comment 7 by jww@chromium.org, May 24 2016

FYI, this "fix" has actually broke some stuff. See  issue 614416 . I'm working on it.
Project Member

Comment 8 by bugdroid1@chromium.org, May 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d9341c818db0c3f07aba8ad98e51eeeb71271506

commit d9341c818db0c3f07aba8ad98e51eeeb71271506
Author: jww <jww@chromium.org>
Date: Thu May 26 03:39:08 2016

Fix bug where a second CSP without script-src would cause failure

After an earlier change to make sure report-only mode did not
erroneously cause a policy failure (see
https://codereview.chromium.org/1980533002), the logic was changed so
that checking the script/style nonce would fail if a policy has no nonce
entry for a directive. Unfortunately, this had the side effect of
disallowing scripts/styles if there are two policies, and one allows
inline scripts via nonce, and the other simply did not mention scripts.

This modifies the nonce logic so that the allow[Script|Style]Nonce no
longer returns a simple bool and instead returns a disposition of Allow,
Deny, or NoPolicy. In the last case, this will not cause a failure in
and of itself, and will allow other policies to be processed before a
decision is made.

BUG= 614416 , 611652 
TBR=mkwst@chromium.org

Review-Url: https://codereview.chromium.org/2006653005
Cr-Commit-Position: refs/heads/master@{#396104}

[modify] https://crrev.com/d9341c818db0c3f07aba8ad98e51eeeb71271506/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/multiple-policies-with-nonce.php
[modify] https://crrev.com/d9341c818db0c3f07aba8ad98e51eeeb71271506/third_party/WebKit/Source/core/frame/csp/CSPDirectiveList.cpp
[modify] https://crrev.com/d9341c818db0c3f07aba8ad98e51eeeb71271506/third_party/WebKit/Source/core/frame/csp/CSPDirectiveList.h
[modify] https://crrev.com/d9341c818db0c3f07aba8ad98e51eeeb71271506/third_party/WebKit/Source/core/frame/csp/ContentSecurityPolicy.cpp

Project Member

Comment 9 by sheriffbot@chromium.org, Jun 2 2016

Labels: Hotlist-Google
Project Member

Comment 10 by bugdroid1@chromium.org, Jun 6 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7

commit cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7
Author: mkwst <mkwst@chromium.org>
Date: Mon Jun 06 15:57:30 2016

Refactor nonce support to correctly handle report-only policy.

In order to correctly handle report-only, we need to stop thinking of
nonces as a one-time bypass in 'ScriptLoader', and start thinking of it
as an ongoing check associated with a request (as it's specced in
https://w3c.github.io/webappsec-csp/#script-src-algorithms). This patch
moves nonce checking into 'FrameFetchContext::canRequest' by attaching
it to 'ResourceLoaderOptions', and using that new data inside the
'ContentSecurityPolicy::allow*' checks to ensure that each active policy
gets a crack at reporting violations.

To prevent regression, this patch adds a number of unit tests, moves
the existing nonce layout tests to a separate directory, and adds a
few layout tests as well.

BUG= 614416 , 611652 ,614802

Review-Url: https://codereview.chromium.org/2020223002
Cr-Commit-Position: refs/heads/master@{#398036}

[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/script-enforce-allowed.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/script-enforce-blocked.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/script-multiple-allowed.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/script-multiple-blocked.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/script-reportonly-allowed.php
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-allowed-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-allowed.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-and-scripthash-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-and-scripthash.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-basic-blocked-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-basic-blocked.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-blocked-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-blocked.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-ignore-unsafeinline-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-ignore-unsafeinline.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-invalidnonce-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-invalidnonce.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-redirect-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/scriptnonce-redirect.html
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/style-enforce-allowed.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/style-enforce-blocked.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/style-multiple-allowed.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/style-multiple-blocked.php
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/style-reportonly-allowed.php
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-allowed-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-allowed.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-basic-blocked-error-event-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-basic-blocked-error-event.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-blocked-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-blocked.html
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-svg-style-basic-blocked-error-event-expected.txt
[rename] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/nonces/stylenonce-svg-style-basic-blocked-error-event.html
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/core.gypi
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/dom/Element.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/dom/StyleElement.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/fetch/FetchRequest.h
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/fetch/ResourceLoaderOptions.h
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/CSPDirectiveList.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/CSPDirectiveList.h
[add] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/ContentSecurityPolicy.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/ContentSecurityPolicy.h
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/frame/csp/ContentSecurityPolicyTest.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/html/HTMLLinkElement.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
[modify] https://crrev.com/cb18719cbfb2652bd1f0c89ff2b43fc431d9a3a7/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp

Comment 11 by mkwst@chromium.org, Jun 16 2016

Status: Fixed (was: Started)
 Issue 596267  has been merged into this issue.

Sign in to add a comment