Skip to content

Commit 06da45d

Browse files
committed
clean up CSP content
1 parent 682378d commit 06da45d

File tree

5 files changed

+63
-74
lines changed

5 files changed

+63
-74
lines changed

docs/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,63 @@ Most community CDNs properly set an `Access-Control-Allow-Origin` header.
9393

9494
</PlatformCategorySection>
9595

96+
<PlatformSection supported={["javascript.sveltekit"]}>
97+
98+
<Expandable permalink title="Configure CSP for Client-side `fetch` Instrumentation">
99+
100+
<Alert>
101+
Only relevant for SvelteKit versions below `@sveltejs/[email protected]`
102+
</Alert>
103+
If you're using a SvelteKit version older than `sveltejs/[email protected]`, the Sentry SDK injects an inline `<script>` tag into the HTML response of the server.
104+
This script proxies all client-side `fetch` calls so that `fetch` calls inside your `load` functions are captured by the SDK.
105+
However, if you configured CSP rules to block inline fetch scripts by default, this script will be [blocked by the browser](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script).
106+
107+
You have multiple options to solve this CSP issue:
108+
109+
#### Option 1: Upgrade SvelteKit
110+
111+
The easiest option is to update `@sveltejs/kit` to at least version `2.16.0` (or newer). The SDK will not inject the fetch proxy script as it's no longer necessary.
112+
113+
#### Option 2: Add Script Hash to CSP policy
114+
115+
To enable the script, add an exception for the `sentryHandle` script by adding the hash of the script to your CSP script source rules.
116+
117+
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
118+
119+
```javascript {filename:svelte.config.js} {5-7}
120+
const config = {
121+
kit: {
122+
csp: {
123+
directives: {
124+
"script-src": ["sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8="], // + rest of your values
125+
},
126+
},
127+
},
128+
};
129+
```
130+
131+
For external CSP configurations, add the following hash to your `script-src` directive:
132+
133+
```txt
134+
'sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8='
135+
```
136+
<Alert>
137+
We will not change this script any time soon, so the hash will stay consistent.
138+
</Alert>
139+
140+
#### Option 3: Disable `fetch` Proxy Script
141+
If you don't want to inject the script responsible for instrumenting client-side `fetch` calls, you can disable injection by passing `injectFetchProxyScript: false` to `sentryHandle`:
142+
143+
```javascript {filename:hooks.server.(js|ts)}
144+
export const handle = sentryHandle({ injectFetchProxyScript: false });
145+
```
146+
147+
Note that if you disable the `fetch` proxy script, the SDK will not be able to capture spans for `fetch` calls made by SvelteKit when your route has a server load function. This also means that potential spans created on the server for these `fetch` calls will not be connected to the client-side trace.
148+
149+
</Expandable>
150+
151+
</PlatformSection>
152+
96153
<PlatformCategorySection supported={['browser']}>
97154

98155
<Expandable permalink title="Unexpected OPTIONS request">

docs/platforms/javascript/guides/sveltekit/manual-setup.mdx

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ export const handle = Sentry.sentryHandle();
124124
// export const handle = sequence(Sentry.sentryHandle(), yourHandler());
125125
```
126126

127+
<Expandable title="Having CSP issues with `fetch` instrumentation on older SvelteKit versions?">
128+
129+
If you're using SvelteKit versions older than `2.16.0` and encounter Content Security Policy (CSP) errors related to Sentry's `fetch` instrumentation, you can find support in our [Troubleshooting guide](/platforms/javascript/guides/sveltekit/troubleshooting/#configure-csp-for-client-side-fetch-instrumentation).
130+
131+
</Expandable>
132+
127133
### Configure Vite
128134

129135
Add the `sentrySvelteKit` plugin **before** `sveltekit` in your `vite.config.(js|ts)` file to automatically upload source maps to Sentry and instrument `load` functions for tracing if it's configured.
@@ -239,60 +245,6 @@ export default {
239245
};
240246
```
241247

242-
### Configure CSP for Client-side `fetch` Instrumentation
243-
244-
<Alert>
245-
246-
Only relevant for SvelteKit versions below `@sveltejs/[email protected]`
247-
248-
</Alert>
249-
250-
If you're using a SvelteKit version older than `sveltejs/[email protected]`, The Sentry SDK injects an inline `<script>` tag into the HTML response of the server.
251-
This script proxies all client-side `fetch` calls, so that `fetch` calls inside your `load` functions are captured by the SDK.
252-
However, if you configured CSP rules to block inline fetch scripts by default, this script will be [blocked by the browser](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script).
253-
254-
You have multiple options to solve this CSP issue:
255-
256-
#### Upgrade SvelteKit
257-
258-
The easiest option is to update `@sveltejs/kit` to at least version `2.16.0` (or newer). The SDK will not inject the fetch proxy script as it's no longer necessary.
259-
260-
#### Add Script Hash to CSP policy
261-
262-
To enable the script, add an exception for the `sentryHandle` script by adding the hash of the script to your CSP script source rules.
263-
264-
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
265-
266-
```javascript {filename:svelte.config.js} {5-7}
267-
const config = {
268-
kit: {
269-
csp: {
270-
directives: {
271-
"script-src": ["sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8="], // + rest of your values
272-
},
273-
},
274-
},
275-
};
276-
```
277-
278-
For external CSP configurations, add the following hash to your `script-src` directive:
279-
280-
```txt
281-
'sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8='
282-
```
283-
284-
We will not make changes to this script any time soon, so the hash will stay consistent.
285-
286-
#### Disable `fetch` Proxy Script
287-
288-
If you don't want to inject the script responsible for instrumenting client-side `fetch` calls, you can disable injection by passing `injectFetchProxyScript: false` to `sentryHandle`:
289-
290-
```javascript {filename:hooks.server.(js|ts)}
291-
export const handle = sentryHandle({ injectFetchProxyScript: false });
292-
```
293-
294-
Note that if you disable the `fetch` proxy script, the SDK will not be able to capture spans for `fetch` calls made by SvelteKit when your route has a server load function. This also means that potential spans created on the server for these `fetch` calls will not be connected to the client-side trace.
295-
296248
### Manual Instrumentation
297249

298250
Instead or in addition to [Auto Instrumentation](#auto-instrumentation), you can manually instrument certain SvelteKit-specific features with the SDK:

docs/platforms/javascript/guides/sveltekit/sourcemaps/troubleshooting_js/debug-ids.mdx

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/platforms/javascript/guides/sveltekit/sourcemaps/troubleshooting_js/index.mdx

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/platforms/javascript/guides/sveltekit/sourcemaps/troubleshooting_js/legacy-uploading-methods.mdx

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)