Skip to content
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

Add an |includeReportOnlyPolicies| boolean argument to Does sink type require trusted types? #518

Merged

Conversation

lukewarlow
Copy link
Member

@lukewarlow lukewarlow commented May 28, 2024

This is needed by w3c/webappsec-csp#665


Preview | Diff

@lukewarlow lukewarlow marked this pull request as ready for review May 28, 2024 14:24
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated
1. For each |policy| in |global|'s <a>CSP list</a>:
1. If |policy|'s <a>directive set</a> does not contain a <a>directive</a>
whose [=directive/name=] is `"require-trusted-types-for"`, skip to the next |policy|.
1. Let |directive| be the |policy|'s |directive set|'s [=directive=] whose name
is `"require-trusted-types-for"`
1. If |directive|'s [=directive/value=] does not contain a <a>trusted-types-sink-group</a> which is a match
for |sinkGroup|, skip to the next |policy|.
1. Set |result| to `true`.
1. Let |enforced| be true if |policy|'s [=policy/disposition=] is `"enforce"`, and false otherwise.
1. Set |result| to true if |enforced| is true, and set to |includeReportOnly| otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read this correctly, the name includeReportOnly seems wrong, since the "enforce" policies are always forcing the result to true ; while the "report" policies only forces the result to true if includeReportOnly is false.

Also the "set to |includeReportOnly|" wording sounds a bit ambiguous to me. At least as a non-native speaker I initally misunderstood this meant setting the result variable to the value of includeReportOnly, which does not make sense.

So I guess what you want is rename the parameter includeEnforceOnly and rewrite the line to something like:

  1. If includeEnforceOnly is false or |policy|'s [=policy/disposition=] is "enforce" then set |result| to true.

The boolean values of the caller would still need to be changed to includeEnforceOnly=false if we want to keep including all the policies.

Finally, even before your change it seems the result can only be set to true and never goes back to false ; so probably you can either just exit the "for each" loop immediately when it's set to true. Alternatively, remove the "result" variable and use "return true" or "return false" statements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this method right now returns true if there's a require-trusted-types-for CSP header. Regardless of whether it's report only or not. Because currently it's used to go down the default policy codepath etc.

However, with the new CSP script-src keyword, we don't want that. We want this to only return true if it is enforced.

So this is updated with a new |includeReportOnly| boolean, which is set to true in the current usage, and set to false in the CSP PR.

So this then returns true if the policy is enforced, and additionally returns true if the policy is report only and |includeReportOnly| is true.

I'll reword it a bit to hopefully make it clearer, and add the early return when the result is true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've realised the ambiguity regarding the variable name too. Good point, I've changed it to includeReportOnlyPolicies to hopefully make it clearer what is meant.

spec/index.bs Show resolved Hide resolved
@lukewarlow lukewarlow force-pushed the does-sink-type-require-include-report-only branch from 2adae0d to 7359179 Compare January 8, 2025 18:21
@lukewarlow lukewarlow force-pushed the does-sink-type-require-include-report-only branch from 7359179 to 80a006f Compare January 8, 2025 18:22
@lukewarlow lukewarlow changed the title Add an |includeReportOnly| boolean argument to Does sink type require trusted types? Add an |includeReportOnlyPolicies| boolean argument to Does sink type require trusted types? Jan 8, 2025
@lukewarlow lukewarlow requested a review from fred-wang January 8, 2025 19:35
Copy link
Collaborator

@fred-wang fred-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that much clearer with the "includeReportOnlyPolicies" name.

@lukewarlow lukewarlow merged commit 0cc17c1 into w3c:main Jan 10, 2025
3 checks passed
github-actions bot added a commit that referenced this pull request Jan 10, 2025
… require trusted types? (#518)

SHA: 0cc17c1
Reason: push, by lukewarlow

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants