When subdomain redirection is off, the login form is served inline on the protected host and submission happens via a same-origin fetch() call in _script.html.twig. The CSP default-src 'none' was blocking that fetch (connect-src falls back to default-src), producing:
Content-Security-Policy: The page's settings blocked the loading of a resource (connect-src) ... it violates the following directive: "default-src 'none'"
Fix
Add connect-src 'self' to the CSP only when the request is not on the auth subdomain (i.e. when the inline script is present and the form submits via JS). On the auth subdomain the form POSTs normally with no inline script, so the stricter policy still applies there.
This is the least-privilege relaxation: only same-origin connections, only on pages that need them.
## Problem
When subdomain redirection is off, the login form is served inline on the protected host and submission happens via a same-origin `fetch()` call in `_script.html.twig`. The CSP `default-src 'none'` was blocking that fetch (`connect-src` falls back to `default-src`), producing:
```
Content-Security-Policy: The page's settings blocked the loading of a resource (connect-src) ... it violates the following directive: "default-src 'none'"
```
## Fix
Add `connect-src 'self'` to the CSP **only** when the request is not on the auth subdomain (i.e. when the inline script is present and the form submits via JS). On the auth subdomain the form POSTs normally with no inline script, so the stricter policy still applies there.
This is the least-privilege relaxation: only same-origin connections, only on pages that need them.
```diff
+ $inlineScript = $this->domainManager->getAuthSubdomain() !== $event->getRequest()->getHost();
$csp = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline';";
+ if ($inlineScript) {
+ $csp .= " connect-src 'self';";
+ }
```
## Testing
All 295 existing tests pass. php-cs-fixer clean.
When subdomain redirection is off, the login form is served inline on
the protected host and submission happens via a same-origin fetch() call
in _script.html.twig. The CSP default-src 'none' was blocking that
fetch (connect-src falls back to default-src).
Add connect-src 'self' to the CSP only when the request is not on the
auth subdomain (i.e. when the inline script is present). On the auth
subdomain the form POSTs normally with no inline script, so the stricter
policy still applies there.
This is the least-privilege relaxation: only same-origin connections,
only on pages that need them.
andrew
approved these changes 2026-08-17 19:05:09 -04:00
andrew
merged commit e2780ca5f6 into main2026-08-17 19:05:16 -04:00
andrew
deleted branch fix/csp-connect-src-inline-script2026-08-17 19:05:16 -04:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
When subdomain redirection is off, the login form is served inline on the protected host and submission happens via a same-origin
fetch()call in_script.html.twig. The CSPdefault-src 'none'was blocking that fetch (connect-srcfalls back todefault-src), producing:Fix
Add
connect-src 'self'to the CSP only when the request is not on the auth subdomain (i.e. when the inline script is present and the form submits via JS). On the auth subdomain the form POSTs normally with no inline script, so the stricter policy still applies there.This is the least-privilege relaxation: only same-origin connections, only on pages that need them.
Testing
All 295 existing tests pass. php-cs-fixer clean.