-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
New CSP Requirement #1311
Comments
Another CSP related discussion: #1297 |
@jmanico are you able to draft the suggested text? |
I would also recommend CSP3 with nonces, but I would not require it. For some applications a CSP with allow-lists works fine and provides adequate security. I would not require these applications to move to CSP with nonces. |
Seemed to be support for CSP staying as Level 1 in #1297 so I closed that but I think we still need to decide how we want it to read in 5.0. Currently it looks like this:
@jmanico or @Sjord could you make any sensible or more prescriptive modifications here? |
Problem 1: Problem 2: maybe we should set the focus of the wording from "mitigating XSS" to "loading and communicating only with allow-listed resources". Or we can ask "fetch, document, navigation and reporting directives are all set" / for loading and communicating only allow-listed resources / for mitigating XSS attacks |
Ok, to me Content Security policy is a well known enough control that we don't need to see what it protects against but rather be more prescriptive about how it should be considered which is what I am looking for suggestions for :) We could also split into multiple requirements for L1, L2 and L3 |
I totally agree with @Sjord comment: here. IMO the end solution should be minimum set of CSP rules that should be applied at each level eg. not allowing In order not to make it too verbose it can be based on CSP tools (like Google CSP Evaluator or CSP Auditor - Burp Suite Extension) and not allow for |
If we want say in details what CSP should do, we need entire paragraph of requirements for that. Using nonces are better and more flexible, but at the same time - I would not say we should block using allow-list method, it does not provide less security. Also, the context - from "XSS" perspective, this requirement is a 2nd layer of defense. What the requirement should say is that the header must be present for every rendered HTTP responses, including error messages from the webserver. |
I am ok to drop this and not get over CSP perscriptive |
to be honest, I would like it to be slightly more prescriptive but I don't want to have to define the text myself :) |
Do we talk about new CSP Requirement like the issue title says or we talk about updating current requirement? With current requirement I would use my previous proposal as input: Or we can ask "fetch, document, navigation and reporting directives are all set" / for loading and communicating only allow-listed resources / for mitigating XSS attacks. |
allow-lists are not at all recommended for CSP policies. Nonce based policies are way more secure. https://research.google/pubs/pub45542/ |
I would recommend the following: For the CSP section description:Any new web project should have a CSP implemented at the beginning of the project and initially be set very strictly. Then during the implementation it might be loosen up depending on the specific needs and accepted risks in the project. For legacy applications CSP implementation should start with using Content-Security-Policy-Report-Only with report-uri (over https) in order to report CSP violations. The initial CSP can start with:
Please note:
It's highly recommended to use CSP validator (like csp-evaluator.withgoogle.com) to verify the strength of the CSP rules. The actual ASVS requirements:From Level 1: CSP should be implemented without 'unsafe-eval', should be checked with CSP validators and be as strict as possible. From Level 2: CSP should be implemented without 'unsafe-inline' in script-src From Level 3: CSP should be checked with CSP validators and have no Red / High severity findings. Every finding should be and addressed and secured in some other way. |
I really like this idea @tw2as. For your L1 control, is "should be checked with CSP validators and be as strict as possible." practical/testable? |
For me it's wrong direction. This requirements does not describe any rules other than "it should exist". What is "valid" validator? What is "as strict as possible"? The requirement does not describe, what must be achieved. In "initial CSP" - why not Basically we just need to sent the message, at via browser, (in HTML or JavaScript; injection or execution situation - it should not be possible to do any communication for loading resources or send requests which are not valid based on application needs. |
@elarlang - I get your point that initial CSP wouldn't work for some projects. How about the following CSP section description?
@tghosth - I get your porint that some of those requirements are not testable. If we can to base the requirements on external CSP validator (which I believe is updated more often then the ASVS itself) then I would base it on https://csp-evaluator.withgoogle.com. Ideally I would prefer to force no high severity findings from L2 and no medium severity findings from L3 but I guess for some projects (especially legacy) it could be to difficult to achieve therefore I propose the following:
|
Strongly disagree to suggest whitelist policies like this. Nonce & strict-dynamic policies are much much stronger.--Jim ***@***.*** Coding Education+1 (808) 652-3805On Jan 5, 2023, at 12:56 PM, Tomasz Wrobel ***@***.***> wrote:
@elarlang - I get your point that initial CSP wouldn't work for some projects. How about the following CSP section description?
Any new web project should have a CSP implemented at the beginning of the project and initially be set very strictly by disabling every CSP directive by setting it's value to 'none'. Then during the implementation it might be loosen up depending on the specific needs and accepted risks in the project.
For legacy applications CSP implementation should start with using Content-Security-Policy-Report-Only with report-uri (over https) in order to report CSP violations.
It's highly recommended to use CSP validator (like csp-evaluator.withgoogle.com) to verify the strength of the CSP rules.
@tghosth - I get your porint that some of those requirements are not testable. If we can to base the requirements on external CSP validator (which I believe is updated more often then the ASVS itself) then I would base it on https://csp-evaluator.withgoogle.com.
Ideally I would prefer to force no high severity findings from L2 and no medium severity findings from L3 but I guess for some projects (especially legacy) it could be to difficult to achieve therefore I propose the following:
From Level 1: Verify that a Content Security Policy (CSP) response header is in place which helps mitigate impact for XSS attacks like HTML, DOM, JSON, and JavaScript injection vulnerabilities and that it does not have 'unsafe-eval' value.
From Level 2: Verify that a Content Security Policy (CSP) response header does not have 'unsafe-inline' value in 'script-src' directive.
From Level 3: Verify Content Security Policy (CSP) response header value with CSP validator (https://csp-evaluator.withgoogle.com/) to make sure that it does not have any High severity findings.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@elarlang I think that @tw2as is on the right track as long as the suggestions are testable/verifable. @tw2as Jim's original request was to focus around a "nonce or hash strict-dynamic" type policy but it looks like that is not specified by your requirements, are you able to clarify that in your suggested text? |
From @jmanico
Jim, fight mode on and not reading? :) Where exactly in my comment (#1311 (comment)) I say anything about whitelist?
In fact, I don't. It's achievable using allow-lists, it's achievable using nonces. And like we have discussed here before - nonce and strict-dynamic is not something we can force to be used over allow-list approach. Application is not more vulnerable when it uses allow-listed sources correctly. With nonces I think you may have problems when you try to cache static content, as nonce itself is not static and cacheable. I still stand for my previously linked comment and we should not say anything about script-src in CSP, because this is "hidden client-side architecture requirement in CSP" If we want to force script-src or unsafe-eval or whatever similar to (not) being used, we should declare them as separate requirements and CSP is just "block the functionality if it's not done correctly or an attack (attempt) happened". From @tw2as
I agree with all the content, but I'm not sure, it's a content for the ASVS. Feels more like Cheat Sheet content for me.
I don't like dependency on external tools, as we don't know what those will do in the future. In a way it's against ASVS versioning - let's say application A was valid against CSP rule on date X, then it was retested again on date Y and it was not valid anymore. In ASVS it could be breaking change. If someone has idea to link requirement text to some tool, then we actually need to point clearly, what we need to achieve (with this tool and without mentioning this tool). |
@tghosth - it's testable as it requires verification of the CSP response header. I understand the point that we don't want to include external tools (I guess it more suitable for Cheat Sheet). I propose the following:
I am not sure if forcing strict-dynamic over allow-list is nesesery. @jmanico if you think so that it's a case of adding the following:
|
There are a lot of level 3 requirements that are difficult to implement. Strict-CSP is challenging to implement in some cases, but I still think we need to push in that direction since it’s the main way, statistically, to implement CSP with good security properties.
Again, many other level 3 requirements are very difficult to implement, that’s why they are level 3.
|
My thoughts on what has been written:
@elarlang I agree that setting out the goal of the requirement is key and ideally focusing the requirement around the goal rather than specific
This definitely seems like the right direction to me @ryarmst @jmanico :)
This is an important point but I also agree with @jmanico that L3 requirements are usually hard and that
@jmanico I think I have to agree with this, the guidance tends to be a little unfocused unfortunately. My questions@Sjord @ryarmst @jmanico @elarlang:
|
@tghosth on your questions:
|
Because Allow-Lists are overall bypassable (93% bypassable) I want to make sure we encourage nonce/hash policies in a very strong way. I vote for L2. Also, CSP policies that try to prevent exfiltration are also weak, and the standard has moved away from trying to plug all the exfiltration vectors. I suggest we focus ASVS CSP requirements on just XSS/content injection defense. |
I think having a best-effort CSP using allowlists should be L2, and having a watertight CSP using nonces should be L3. I think
@jmanico This sounds interesting, outside the context of this issue. Do you have additional information on this where I can read more about this? |
Here is the research on CSP bypasses and similar. https://speakerdeck.com/lweichselbaum/csp-a-successful-mess-between-hardening-and-mitigation?slide=16 .. even with a strict allow list, bypasses include:
|
I didn't really ask about CSP bypasses, but about exfiltration vectors. They talk about that in the presentation, but that's only focused on data exfiltration through JavaScript. It still seems valuable to prevent e.g. CSS injection to prevent exfiltrating the CSRF token. Here's another interesting slide from the same presentation, which could help us determine which CSP directives to require at which levels: However, I think their level 1 won't allow inline event handlers (i.e. |
In general, the CSP standard body has stopped trying to prevent data exfiltration with CSP. There are just too many vectors. CSP is really about stopping the initial injection. |
@jmanico Do you have a source for that? Some publication of the CSP standard body that confirms this? |
For sure. Let me do a little digging on this and I'll get back to you. But basically, attackers have developed rather sophisticated techniques that can bypass CSP protections, such as using trusted domains or exploiting browser bugs. CSP is less effective in stopping data exfiltration, especially when attackers use legitimate channels for data transmission. I'll give you a reference soon. |
This is from one of the CSP standard body members: "It's true that CSP isn't suited to prevent data exfil. E.g. it's trivial to use navigation to extract data and there's nothing you can do with CSP to prevent this. Once the attacker has script execution it's game over. So the primary goal is to prevent that from happening. I'm not sure if there's an official w3c stance on it, but indirectly this position is confirmed by consensus of deprecating the navigate-to CSP directive. iirc we also had a slide on this in our 2019 locomocosec talk" |
@jmanico, having read back through the comments above and especially @ryarmst's comment I think that it is a little unrealistic for a strict nonce/hash based policy for L2 and an allow list based policy might be more difficult than it is worth. It makes me thing that the L2 requirement should be non-prescriptive on how it is achieved and the L3 requirement should specify nonce/hash based policy. For the specific wording, I think it will depend on the discussions in #1958. |
It makes me think that the L2 requirement should be non-prescriptive on how it is achieved and the L3 requirement should specify nonce/hash based policy.
I like this approach. 👍🏼
|
I have a new set of proposals with a couple options. I removed implementation details while still trying to capture the goal/outcome. If it's not clear enough, implementation specifics can be added. For example, for L3: "This can be accomplished using CSP-nonces and/or CSP-hashes". Option 1: Single requirement that specifies special L3 requirement. All in one:
L1/L2:
L3:
|
I think we need to add "allow-lists or nonces" to L1/L2 and "nonces" to L3. cc @elarlang who verbalized he has a different opinion here. |
Reformulating based on feedback, including:
L2:
L3:
|
Reformulating:
|
Looks good to me |
New candidate per @jmanico feedback:
|
Minor wordsmithing: Verify that every HTTP response includes a Content-Security-Policy (CSP) header field to reducing the risk of malicious JavaScript. For L3, define a per-response policy with nonces or hashes with object-src and base-uri set to 'none'. For L2, allowlists and a global policy may be used. |
For L2 application, allowlists and a global policy may be used, for L3 a per-response policy with nonces or hashes with object-src and base-uri set to 'none' must be defined. |
Taking Elar into consideration. _Verify that every HTTP response includes a Content-Security-Policy (CSP) header field to reduce the risk of malicious JavaScript. For L2, allowlists and a global policy may be used. For L3, a per-response policy with nonces or hashes, and object-src and base-uri set to 'none,' must be defined. _ |
I suggest we have a CSP requirement that moves folks away from allow-lists to a nonce or hash strict-dynamic policy (CSP3 stuff) which is much easier to deploy and more secure.
The text was updated successfully, but these errors were encountered: