Skip to content

Commit d7aa93f

Browse files
authored
feat(v8/sveltekit): Deprecate fetchProxyScriptNonce option (#15011)
Deprecate the `fetchProxyScriptNonce` option which we'll remove in v9 due to security concerns.
1 parent 79c2c2a commit d7aa93f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/sveltekit/src/server/handle.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@ export type SentryHandleOptions = {
4040
* Controls if `sentryHandle` should inject a script tag into the page that enables instrumentation
4141
* of `fetch` calls in `load` functions.
4242
*
43+
* You can safely set this to `false` if you're using `@sveltejs/kit` version 2.16.0 or newer. This
44+
* is only needed for versions older than 2.16.0.
45+
*
4346
* @default true
4447
*/
4548
injectFetchProxyScript?: boolean;
4649

4750
/**
48-
* If this option is set, the `sentryHandle` handler will add a nonce attribute to the script
49-
* tag it injects into the page. This script is used to enable instrumentation of `fetch` calls
50-
* in `load` functions.
51+
* Warning: Setting this option is **strongly discouraged** and it will be removed in the next major version of the SDK.
52+
*
53+
* If you set this option, the passed nonce will be added to fetch proxy `<script>` tag that the Sentry SDK adds to your page.
54+
* The nonce passed to this option will be reused across multiple requests, which is defeating the purpose of a nonce.
55+
* See below for options what to do instead.
56+
*
57+
* @deprecated This option will be removed in the next major version of the SDK.
5158
*
52-
* Use this if your CSP policy blocks the fetch proxy script injected by `sentryHandle`.
59+
* If you rely on this option, you have the following replacement options:
60+
* - set a hash instead of the nonce in your CSP config [as documented here](https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/#configure-csp-for-client-side-fetch-instrumentation)
61+
* - update `@sveltejs/kit` to at least version 2.16.0 or newer and set `injectFetchProxyScript: false`
5362
*/
5463
fetchProxyScriptNonce?: string;
5564
};
@@ -73,12 +82,13 @@ export const FETCH_PROXY_SCRIPT = `
7382
* Exported only for testing
7483
*/
7584
export function addSentryCodeToPage(options: SentryHandleOptions): NonNullable<ResolveOptions['transformPageChunk']> {
85+
// eslint-disable-next-line deprecation/deprecation
7686
const { fetchProxyScriptNonce, injectFetchProxyScript } = options;
7787
// if injectFetchProxyScript is not set, we default to true
7888
const shouldInjectScript = injectFetchProxyScript !== false;
7989
const nonce = fetchProxyScriptNonce ? `nonce="${fetchProxyScriptNonce}"` : '';
8090

81-
return ({ html }) => {
91+
return ({ html }: { html: string }) => {
8292
const metaTags = getTraceMetaTags();
8393
const headWithMetaTags = metaTags ? `<head>\n${metaTags}` : '<head>';
8494

0 commit comments

Comments
 (0)