Bug 234390 - CSP: Include the sample in eval violation reports
Summary: CSP: Include the sample in eval violation reports
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-16 07:22 PST by Carlos Garcia Campos
Modified: 2021-12-21 00:46 PST (History)
10 users (show)

See Also:


Attachments
Patch (32.16 KB, patch)
2021-12-16 07:32 PST, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Patch (32.16 KB, patch)
2021-12-20 03:04 PST, Carlos Garcia Campos
katherine_cheney: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2021-12-16 07:22:04 PST
We are not including the sample for eval reports.
Comment 1 Carlos Garcia Campos 2021-12-16 07:32:03 PST
Created attachment 447353 [details]
Patch
Comment 2 Kate Cheney 2021-12-17 09:36:52 PST
Comment on attachment 447353 [details]
Patch

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

> Source/JavaScriptCore/runtime/FunctionConstructor.cpp:144
> +        auto codeScope = DECLARE_THROW_SCOPE(vm);

What is the benefit of creating codeScope and using that instead of scope?

> Source/JavaScriptCore/runtime/FunctionConstructor.cpp:147
> +        globalObject->globalObjectMethodTable()->reportViolationForUnsafeEval(globalObject, !code.isNull() ? jsNontrivialString(vm, code) : nullptr);

I think this can be WTFMove(code) to avoid a potential copy.

> Source/WebCore/page/csp/ContentSecurityPolicy.h:226
> +    void reportViolation(const String& effectiveViolatedDirective, const ContentSecurityPolicyDirective& violatedDirective, const String& blockedURL, const String& consoleMessage, JSC::JSGlobalObject*, const StringView& sourceContent) const;

Despite the fact that this is done in multiple places in CSP code, I think passing a StringView as a const reference is actually worse for performance, because it's in the same "complexity category" as int and char* and it's cost-of-copy does not outweigh the benefits of pass-by-value.
Comment 3 Carlos Garcia Campos 2021-12-20 03:03:14 PST
Comment on attachment 447353 [details]
Patch

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

>> Source/JavaScriptCore/runtime/FunctionConstructor.cpp:144
>> +        auto codeScope = DECLARE_THROW_SCOPE(vm);
> 
> What is the benefit of creating codeScope and using that instead of scope?

I assumed we don't want to throw an exception in case something fails in stringifyFunction, since we don't even know if the sample report will be used at this point, and scope is already used to throw the createEvalError. I don't know what happens in throwException() if the given scope already has an exception thrown.

>> Source/JavaScriptCore/runtime/FunctionConstructor.cpp:147
>> +        globalObject->globalObjectMethodTable()->reportViolationForUnsafeEval(globalObject, !code.isNull() ? jsNontrivialString(vm, code) : nullptr);
> 
> I think this can be WTFMove(code) to avoid a potential copy.

Indeed.

>> Source/WebCore/page/csp/ContentSecurityPolicy.h:226
>> +    void reportViolation(const String& effectiveViolatedDirective, const ContentSecurityPolicyDirective& violatedDirective, const String& blockedURL, const String& consoleMessage, JSC::JSGlobalObject*, const StringView& sourceContent) const;
> 
> Despite the fact that this is done in multiple places in CSP code, I think passing a StringView as a const reference is actually worse for performance, because it's in the same "complexity category" as int and char* and it's cost-of-copy does not outweigh the benefits of pass-by-value.

Ok.
Comment 4 Carlos Garcia Campos 2021-12-20 03:04:26 PST
Created attachment 447593 [details]
Patch
Comment 5 Carlos Garcia Campos 2021-12-21 00:45:53 PST
Committed r287303 (245455@trunk): <https://commits.webkit.org/245455@trunk>
Comment 6 Radar WebKit Bug Importer 2021-12-21 00:46:18 PST
<rdar://problem/86758157>