Skip to content

Commit 0a2a312

Browse files
committed
fix: resolve CSP violations for Crowdin inline translation
- Add 'unsafe-hashes' to script-src for jQuery event handlers - Add script-src-attr 'unsafe-hashes' for inline event handlers - Include crowdin-static.cf-downloads.crowdin.com for avatar images - Allow Crowdin blob workers and child sources for inline translation - Fixes CSP blocking of Crowdin functionality in inline-translation mode
1 parent cc82f36 commit 0a2a312

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

website/app/GeoKrety/Service/SecurityHeaders.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ private function applyCSP(\Base $f3): void {
5050

5151
// Base CSP directives
5252
$csp = [
53-
sprintf('script-src \'nonce-%s\' \'strict-dynamic\'', $this->nonce),
53+
sprintf('script-src \'nonce-%s\' \'strict-dynamic\'%s', $this->nonce, $isInlineTranslation ? ' \'unsafe-hashes\'' : ''),
5454
sprintf(
5555
'img-src \'self\' data: blob: %s %s https://www.gstatic.com/recaptcha/ https://tile.openstreetmap.org https://seccdn.libravatar.org/avatar/ https://cdn.geokrety.org%s',
5656
GK_CDN_SERVER_URL,
5757
GK_MINIO_SERVER_URL_EXTERNAL,
58-
$isInlineTranslation ? ' https://cdn.crowdin.com/jipt/images/ https://crowdin-static.downloads.crowdin.com/avatar/' : ''
58+
$isInlineTranslation ? ' https://cdn.crowdin.com/jipt/images/ https://crowdin-static.downloads.crowdin.com/avatar/ https://crowdin-static.cf-downloads.crowdin.com/avatar/' : ''
5959
),
6060
'frame-src https://www.google.com/ https://www.youtube.com/' . ($isInlineTranslation ? ' https://crowdin.com/' : ''),
6161
sprintf('style-src \'self\' \'nonce-%s\'', $this->nonce),
@@ -72,10 +72,24 @@ private function applyCSP(\Base $f3): void {
7272
)
7373
];
7474

75+
// Add script-src-attr for inline translation event handlers
76+
if ($isInlineTranslation) {
77+
$csp[] = "script-src-attr 'unsafe-hashes'";
78+
}
79+
7580
// Add reCAPTCHA support
7681
$recaptchaHosts = 'https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/';
77-
$csp[] = "worker-src 'self' blob: $recaptchaHosts";
78-
$csp[] = "child-src 'self' blob: $recaptchaHosts";
82+
$workerSrc = "'self' blob: $recaptchaHosts";
83+
$childSrc = "'self' blob: $recaptchaHosts";
84+
85+
// Add Crowdin worker support for inline translation
86+
if ($isInlineTranslation) {
87+
$workerSrc .= ' https://crowdin.com';
88+
$childSrc .= ' https://crowdin.com';
89+
}
90+
91+
$csp[] = "worker-src $workerSrc";
92+
$csp[] = "child-src $childSrc";
7993

8094
// Additional security directives
8195
$csp[] = "object-src 'none'";

0 commit comments

Comments
 (0)