Skip to content

Commit 5863276

Browse files
authored
fix(csp): allow https images in markdown preview and html sandbox (#4394)
* fix(csp): allow https images in markdown preview and html sandbox * fix(csp): remove inoperative self token from sandboxed html preview img-src * chore(csp): remove redundant img-src entries superseded by https scheme * fix(csp): revert html preview img-src to data: blob: to preserve connect-src none isolation
1 parent 39c6aef commit 5863276

1 file changed

Lines changed: 3 additions & 33 deletions

File tree

  • apps/sim/lib/core/security

apps/sim/lib/core/security/csp.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,7 @@ const STATIC_SCRIPT_SRC = [
6161
: []),
6262
] as const
6363

64-
const STATIC_IMG_SRC = [
65-
"'self'",
66-
'data:',
67-
'blob:',
68-
'https://*.googleusercontent.com',
69-
'https://*.google.com',
70-
'https://*.atlassian.com',
71-
'https://cdn.discordapp.com',
72-
'https://*.githubusercontent.com',
73-
'https://*.s3.amazonaws.com',
74-
'https://s3.amazonaws.com',
75-
'https://*.amazonaws.com',
76-
'https://*.blob.core.windows.net',
77-
'https://github.com/*',
78-
'https://cursor.com',
79-
...(isHosted ? ['https://www.googletagmanager.com', 'https://www.google-analytics.com'] : []),
80-
] as const
64+
const STATIC_IMG_SRC = ["'self'", 'data:', 'blob:', 'https:'] as const
8165

8266
const STATIC_CONNECT_SRC = [
8367
"'self'",
@@ -147,20 +131,7 @@ export const buildTimeCSPDirectives: CSPDirectives = {
147131
'script-src': [...STATIC_SCRIPT_SRC],
148132
'style-src': ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],
149133

150-
'img-src': [
151-
...STATIC_IMG_SRC,
152-
...(env.S3_BUCKET_NAME && env.AWS_REGION
153-
? [`https://${env.S3_BUCKET_NAME}.s3.${env.AWS_REGION}.amazonaws.com`]
154-
: []),
155-
...(env.S3_KB_BUCKET_NAME && env.AWS_REGION
156-
? [`https://${env.S3_KB_BUCKET_NAME}.s3.${env.AWS_REGION}.amazonaws.com`]
157-
: []),
158-
...(env.S3_CHAT_BUCKET_NAME && env.AWS_REGION
159-
? [`https://${env.S3_CHAT_BUCKET_NAME}.s3.${env.AWS_REGION}.amazonaws.com`]
160-
: []),
161-
...getHostnameFromUrl(env.NEXT_PUBLIC_BRAND_LOGO_URL),
162-
...getHostnameFromUrl(env.NEXT_PUBLIC_BRAND_FAVICON_URL),
163-
],
134+
'img-src': [...STATIC_IMG_SRC],
164135

165136
'media-src': ["'self'", 'blob:'],
166137
'worker-src': ["'self'", 'blob:'],
@@ -216,14 +187,13 @@ export function generateRuntimeCSP(): string {
216187
const ollamaUrl = getEnv('OLLAMA_URL') || (isDev ? DEFAULT_OLLAMA_URL : '')
217188

218189
const brandLogoDomains = getHostnameFromUrl(getEnv('NEXT_PUBLIC_BRAND_LOGO_URL'))
219-
const brandFaviconDomains = getHostnameFromUrl(getEnv('NEXT_PUBLIC_BRAND_FAVICON_URL'))
220190
const privacyDomains = getHostnameFromUrl(getEnv('NEXT_PUBLIC_PRIVACY_URL'))
221191
const termsDomains = getHostnameFromUrl(getEnv('NEXT_PUBLIC_TERMS_URL'))
222192

223193
const runtimeDirectives: CSPDirectives = {
224194
...buildTimeCSPDirectives,
225195

226-
'img-src': [...STATIC_IMG_SRC, ...brandLogoDomains, ...brandFaviconDomains],
196+
'img-src': [...STATIC_IMG_SRC],
227197

228198
'connect-src': [
229199
...STATIC_CONNECT_SRC,

0 commit comments

Comments
 (0)