Bug 234934 - Implement CSP strict-dynamic for module scripts
Summary: Implement CSP strict-dynamic for module scripts
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kate Cheney
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-06 13:26 PST by Kate Cheney
Modified: 2022-01-07 10:06 PST (History)
6 users (show)

See Also:


Attachments
Patch (9.03 KB, patch)
2022-01-06 13:28 PST, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch for landing (9.02 KB, patch)
2022-01-07 09:24 PST, 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 2022-01-06 13:26:09 PST
Implement CSP strict-dynamic for module scripts
Comment 1 Kate Cheney 2022-01-06 13:28:50 PST
Created attachment 448534 [details]
Patch
Comment 2 Kate Cheney 2022-01-06 13:29:21 PST
rdar://83728374
Comment 3 Brent Fulgham 2022-01-06 14:05:54 PST
Comment on attachment 448534 [details]
Patch

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

r=me

> Source/WebCore/dom/ScriptElement.cpp:379
> +    if (!contentSecurityPolicy.allowNonParserInsertedScripts(m_element.document().url(), m_startLineNumber, m_element.nonce(), sourceCode.source(), m_parserInserted))

Is there a specific CSP spec step we should reference for this decision? I know most of the CSP code doesn't add such comments, but I find them helpful when reviewing other areas of WebKit.

> LayoutTests/http/tests/security/contentSecurityPolicy/strict-dynamic-module-script.html:6
> +        <script src="/js-test-resources/testharnessreport.js" nonce='dummy'></script>

Nit: Weird spacing here
Comment 4 Kate Cheney 2022-01-06 14:37:55 PST
Comment on attachment 448534 [details]
Patch

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

>> Source/WebCore/dom/ScriptElement.cpp:379
>> +    if (!contentSecurityPolicy.allowNonParserInsertedScripts(m_element.document().url(), m_startLineNumber, m_element.nonce(), sourceCode.source(), m_parserInserted))
> 
> Is there a specific CSP spec step we should reference for this decision? I know most of the CSP code doesn't add such comments, but I find them helpful when reviewing other areas of WebKit.

Do you mean the m_startLineNumber change or why we check for allowNonParserInsertedScripts here? 

If it is the latter, generally yes but not specifically to module scripts. Under https://www.w3.org/TR/CSP3/#strict-dynamic-usage the spec explains "Script requests which are triggered by non-"parser-inserted" script elements are allowed." requestModuleScript is a place we were formerly not checking a requested script's parser-inserted status.
Comment 5 Brent Fulgham 2022-01-06 14:42:03 PST
Comment on attachment 448534 [details]
Patch

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

>>> Source/WebCore/dom/ScriptElement.cpp:379
>>> +    if (!contentSecurityPolicy.allowNonParserInsertedScripts(m_element.document().url(), m_startLineNumber, m_element.nonce(), sourceCode.source(), m_parserInserted))
>> 
>> Is there a specific CSP spec step we should reference for this decision? I know most of the CSP code doesn't add such comments, but I find them helpful when reviewing other areas of WebKit.
> 
> Do you mean the m_startLineNumber change or why we check for allowNonParserInsertedScripts here? 
> 
> If it is the latter, generally yes but not specifically to module scripts. Under https://www.w3.org/TR/CSP3/#strict-dynamic-usage the spec explains "Script requests which are triggered by non-"parser-inserted" script elements are allowed." requestModuleScript is a place we were formerly not checking a requested script's parser-inserted status.

I meant the latter, so I think you've explained it.
Comment 6 Kate Cheney 2022-01-07 09:24:25 PST
Created attachment 448604 [details]
Patch for landing
Comment 7 EWS 2022-01-07 10:06:09 PST
Committed r287756 (245819@main): <https://commits.webkit.org/245819@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 448604 [details].