Commit 4187d71
authored
1257: add CSP to scratch.html (#1438)
issue:
[1257](RaspberryPiFoundation/digital-editor-issues#1257)
I’ve built the CSP to try to tap into the env variables that we use for
deployments.
I’ve also tried to do some due diligence on the testing staging and
staging environments in order to anticipate any problems - I did find
something that was a begin pulled in on those environments that I’ve
added a workaround for [(see the comment
below)](#1438 (comment))
### Local dev CSP output
This has to feature 'unsafe-eval' to allow the dev server to work
```
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
base-uri 'none';
object-src 'none';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
worker-src 'self' blob:;
child-src 'self' blob:;
connect-src 'self' http://localhost:3009 http://localhost:3011;
img-src 'self' data: blob: http://localhost:3011;
media-src 'self' blob: http://localhost:3011;
font-src 'self' data: http://localhost:3011;
form-action 'self';
upgrade-insecure-requests;
">
```
### Staging CSP output (take values from deploy-main in ci-cd.yml)
As the test environment uses editor-ui in staging that testing api needs
to be listed on staging as well
```
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
base-uri 'none';
object-src 'none';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
worker-src 'self' blob:;
child-src 'self' blob:;
connect-src 'self' https://staging-editor-api.raspberrypi.org https://test-editor-api.raspberrypi.org https://staging-editor-static.raspberrypi.org;
img-src 'self' data: blob: https://staging-editor-static.raspberrypi.org;
media-src 'self' blob: https://staging-editor-static.raspberrypi.org;
font-src 'self' data: https://staging-editor-static.raspberrypi.org;
form-action 'self';
upgrade-insecure-requests;
">
```
### Production (take values from deploy-tag in ci-cd.yml)
```
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
base-uri 'none';
object-src 'none';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
worker-src 'self' blob:;
child-src 'self' blob:;
connect-src 'self' https://editor-api.raspberrypi.org https://editor-static.raspberrypi.org;
img-src 'self' data: blob: https://editor-static.raspberrypi.org;
media-src 'self' blob: https://editor-static.raspberrypi.org;
font-src 'self' data: https://editor-static.raspberrypi.org;
form-action 'self';
upgrade-insecure-requests;
">
```
### CSP violations for assets
Regarding current attempts to access images from
`https://cdn.assets.scratch.mit.edu/` - the set up above will result in
CSP errors in the console.
<img width="643" height="146" alt="CDN-ASSET-SCRATCH_CSP"
src="https://github.com/user-attachments/assets/c5961ada-15c6-4cb3-bf96-fe66b52493c1"
/>
This should be short lived until we arrive at the solution for asset
hosting - I don’t think this will stop anything else in the app working
as a results. If we choose to host images on a different domain to the
ones already stated we should be able to just add that domain to the
img-src/media-src CSP.1 parent d4ebe0e commit 4187d71
4 files changed
Lines changed: 67 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
| 165 | + | |
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
166 | | - | |
| 171 | + | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
6 | 24 | | |
7 | 25 | | |
8 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
12 | 50 | | |
13 | 51 | | |
14 | 52 | | |
| |||
237 | 275 | | |
238 | 276 | | |
239 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
240 | 282 | | |
241 | 283 | | |
242 | 284 | | |
| |||
0 commit comments