feat(sveltekit): Add options to configure fetch instrumentation script for CSP #9969
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds options to the
sentryHandle
request handler that allows control over CSP-relevant aspects for the<script>
that the request handler injects into the page. Previously, the injected script was blocked by browsers if CSP was enabled, due to inline<script>
s not being allowed without a nonce or hash.Users who configured CSP have now two options to deal with this script:
1.
fetchProxyScriptNonce
Users can pass a nonce to
sentryHandle
which will be added to the injected script:<script nonce="...">
:This requires additional CSP configuration. For example:
2. Disable the fetch script with
injectFetchProxyScript
Users can opt out of
sentryHandle
injecting the fetch proxy script:For SvelteKit <1.26.0 this will disable fetch instrumentation in
load
function. For more recent versions, fetch instrumentation should continue to work because sveltejs/kit#10009 was merged in 1.26.0.In the future we could look for a way to decide if we should at all inject the script based on the Kit version. However, for now, I think these manual methods are fine.
fixes #8925