Bug 231313 - CSP: Implement unsafe-hashes
Summary: CSP: Implement unsafe-hashes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kate Cheney
URL:
Keywords: InRadar
: 205885 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-10-06 11:10 PDT by Kate Cheney
Modified: 2022-03-30 11:47 PDT (History)
8 users (show)

See Also:


Attachments
Patch (83.36 KB, patch)
2021-10-06 12:06 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (81.03 KB, patch)
2021-10-06 12:13 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (88.03 KB, patch)
2021-10-07 15:57 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (94.43 KB, patch)
2021-10-08 07:19 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch for landing (96.50 KB, patch)
2021-10-12 16:14 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch for landing (96.50 KB, patch)
2021-10-12 16:16 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kate Cheney 2021-10-06 11:10:34 PDT
CSP: Implement unsafe-hashes
Comment 1 Kate Cheney 2021-10-06 11:10:57 PDT
rdar://83724376
Comment 2 Kate Cheney 2021-10-06 12:06:40 PDT
Created attachment 440407 [details]
Patch
Comment 3 Kate Cheney 2021-10-06 12:08:08 PDT
(In reply to Kate Cheney from comment #2)
> Created attachment 440407 [details]
> Patch

WIP, not ready for review quite yet but wanted to see what EWS thinks. Will update ChangeLogs with more detail in the next patch.
Comment 4 Kate Cheney 2021-10-06 12:13:48 PDT
Created attachment 440410 [details]
Patch
Comment 5 Kate Cheney 2021-10-07 15:57:27 PDT
Created attachment 440550 [details]
Patch
Comment 6 Kate Cheney 2021-10-08 07:19:42 PDT
Created attachment 440604 [details]
Patch
Comment 7 Brent Fulgham 2021-10-12 15:03:33 PDT
Comment on attachment 440604 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=440604&action=review

r=me

> Source/WebCore/ChangeLog:9
> +        unsafe-hashes allows specific event handlers  and style attributes

double-space between 'handlers' and 'and'.

> Source/WebCore/dom/StyledElement.cpp:208
> +    if (reason == ModifiedByCloning || document().contentSecurityPolicy()->allowInlineStyle(document().url().string(), startLineNumber,  newStyleString.string(), CheckUnsafeHashes::Yes, isInUserAgentShadowTree()))

Looks like two spaces before "newStyleString.string()".

> Source/WebCore/page/csp/ContentSecurityPolicy.h:98
> +    bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, const String&, bool overrideContentSecurityPolicy = false) const;

I think showing 'code' for the new string makes sense here. Otherwise it's not clear what that parameter is for.

> Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp:169
> +    ContentSecurityPolicySourceListDirective* operativeDirective = this->operativeDirective(m_scriptSrc.get());

Could this be auto* ?

> Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp:177
> +    ContentSecurityPolicySourceListDirective* operativeDirective = this->operativeDirective(m_styleSrc.get());

Ditto

> LayoutTests/ChangeLog:15
> +        bug in our DOM code.

Could you please file a Bugzilla about that one failing test (and send me the #?)

> LayoutTests/TestExpectations:-957
> -imported/w3c/web-platform-tests/content-security-policy/unsafe-hashes/style_attribute_allowed.html [ Skip ]

Yes!

> LayoutTests/imported/w3c/web-platform-tests/content-security-policy/unsafe-hashes/javascript_src_allowed-window_location-expected.txt:2
> +PASS Test that the javascript: src is allowed to run

Yes!

> LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic-expected.txt:10
> +PASS inline event handlers triggered via UA code must not inherit the nonce from the triggering script, thus fail

Nice!
Comment 8 Chris Dumez 2021-10-12 15:15:06 PDT
Comment on attachment 440604 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=440604&action=review

> Source/WebCore/page/csp/ContentSecurityPolicy.cpp:389
> +    auto [foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies] = findHashOfContentInPolicies(WTFMove(searchPolicy), source, hashAlgorithms);

It is unclear why this function and findHashOfContentInPolicies() take searchPolicy as an r-value reference instead of simply a const reference.

> Source/WebCore/page/csp/ContentSecurityPolicy.cpp:407
> +        reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrcElem, violatedDirective, "inline", consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));

Assuming the parameter is a String, "inline"_s would be better (same comment elsewhere).
Comment 9 Kate Cheney 2021-10-12 16:03:32 PDT
Comment on attachment 440604 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=440604&action=review

>> Source/WebCore/ChangeLog:9
>> +        unsafe-hashes allows specific event handlers  and style attributes
> 
> double-space between 'handlers' and 'and'.

Oops, will fix.

>> Source/WebCore/dom/StyledElement.cpp:208
>> +    if (reason == ModifiedByCloning || document().contentSecurityPolicy()->allowInlineStyle(document().url().string(), startLineNumber,  newStyleString.string(), CheckUnsafeHashes::Yes, isInUserAgentShadowTree()))
> 
> Looks like two spaces before "newStyleString.string()".

Ditto, will fix.

>> Source/WebCore/page/csp/ContentSecurityPolicy.h:98
>> +    bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, const String&, bool overrideContentSecurityPolicy = false) const;
> 
> I think showing 'code' for the new string makes sense here. Otherwise it's not clear what that parameter is for.

Fair point, I'll add that back.

>> Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp:169
>> +    ContentSecurityPolicySourceListDirective* operativeDirective = this->operativeDirective(m_scriptSrc.get());
> 
> Could this be auto* ?

Yes, I'll fix it. We should probably change the rest of this file to use auto in another patch.

>> LayoutTests/ChangeLog:15
>> +        bug in our DOM code.
> 
> Could you please file a Bugzilla about that one failing test (and send me the #?)

Yes. Bug: https://bugs.webkit.org/show_bug.cgi?id=231642
Comment 10 Kate Cheney 2021-10-12 16:04:09 PDT
(In reply to Chris Dumez from comment #8)
> Comment on attachment 440604 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=440604&action=review
> 
> > Source/WebCore/page/csp/ContentSecurityPolicy.cpp:389
> > +    auto [foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies] = findHashOfContentInPolicies(WTFMove(searchPolicy), source, hashAlgorithms);
> 
> It is unclear why this function and findHashOfContentInPolicies() take
> searchPolicy as an r-value reference instead of simply a const reference.
> 

No good reason. Will change in the patch-for-landing.

> > Source/WebCore/page/csp/ContentSecurityPolicy.cpp:407
> > +        reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrcElem, violatedDirective, "inline", consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));
> 
> Assuming the parameter is a String, "inline"_s would be better (same comment
> elsewhere).

Will change.
Comment 11 Kate Cheney 2021-10-12 16:14:03 PDT
Created attachment 441013 [details]
Patch for landing
Comment 12 Kate Cheney 2021-10-12 16:16:28 PDT
Created attachment 441014 [details]
Patch for landing
Comment 13 EWS 2021-10-12 17:31:21 PDT
Committed r284067 (242896@main): <https://commits.webkit.org/242896@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441014 [details].
Comment 14 Sam Sneddon [:gsnedders] 2022-03-30 11:47:01 PDT
*** Bug 205885 has been marked as a duplicate of this bug. ***