-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does the meta http-equiv="Content-Security-Policy"
tag allow lists of policies?
#5102
Comments
The Nu Html Checker just uses https://github.com/shapesecurity/salvation/ on the backend, as https://cspvalidator.org/ also does. So I reckon @shekyan might also be interested in clarification on this |
Salvation (which I help maintain) actually has APIs for parsing both single policies and lists of policies. The fact that the Nu HTML checker disallows lists means they've chosen to use the API for a single policy, I believe. |
Explanation of why the HTML checker doesn’t allow lists of policies
aha
The they in this case is me. I never intentionally chose to explicitly limit the checker to using the API for a single policy. I just did it out of laziness/ignorance. …or else I guess possibly salvation back then might not have yet had support for checking a list of policies, at the time I initially added in the feature — ~4 years ago, circa salvation-1.0.3; see validator/validator@dfd77df#diff-e706d1dfdc30b96b123a2fa3cb7eadacR66, which just directly calls
OK then, if/when the HTML spec is updated to clearly allow lists of policies, I could happily and easily update the HTML checker code to allow lists of policies. |
As you note, Chrome (and presumably WebKit, since the implementation is likely common to both) simply takes whatever's in the I'm surprised to hear that that comes up in practice, as I don't think there's much value in delivering multiple policies via I suspect I intended to link to "parse a serialized CSP list" when I sent the PR against HTML. That would create the behavior I suggested above. If y'all agree with the rationale, I'll send that patch and add some tests. |
There is considerable value in it because there are behaviors which are not expressible as a single policy, only as a list of policies. (The simplest example is two policies with different That might not come up if you're writing a policy manually, but it certainly does if you're trying to automatically manipulate policies. (That's how I ran into it.)
SGTM |
I agree that multiple policies are valuable! I'm questioning the value of that mechanism in Still, I'd prefer to align on Chrome's behavior. I'll send a PR to that effect. |
There's going to be parser input differences at least as one is a byte sequence and the other is a string. I would also expect combining differences. Ideally for HTTP we combine first and then parse, but I don't think that's workable for |
That comes up already; browsers seem to just reject any
There would still be a maximum of one |
Not sure what the next step is here…
@mkwest are you still planning on doing that, or did @annevk‘s comment at #5102 (comment) dissuade you? |
The html spec says that the
content
of an<meta http-equiv="Content-Security-Policy" content="...">
tag should be aserialized-policy
and should be parsed according to Parse a serialized CSP.This implies that it does not allow multiple comma-separated policies, such as
img-src 'none', script-src 'sha256-lLvWePLrgCn07EcwYB0JPy65n3OloEYiWK34Ql9Zdmc='
. That would be aserialized-csp-list
, parsed according to Parse a serialized CSP list, which nothing I can find actually uses. (Also, that algorithm returns multiple policies, each of which would need to be enforced.)However, both Chrome and Safari do allow policy lists such as the above. Firefox and the Nu HTML checker do not - Firefox attempts to parse it as a single policy including the
,
, while the Nu HTML checker considers it an outright error.As far as I can tell, the web platform tests do not cover this case.
Here is a simple page with the above comma-separated CSP, which contains both an image and an inline script with no hash. Its source is below.
Which is the intended behavior?
demo page source
The text was updated successfully, but these errors were encountered: