--- name: csp-form-action-debugging description: "Debug CSP form-action blocking issues — Chrome silently blocks forms when action URLs contain certain patterns in query params." tags: [csp, security, debugging, form-action, chrome] triggers: - "form submission fails silently" - "CSP form-action violation" - "login redirect not working" - "form POST blocked by browser" - "ERR_ABORTED on form submit" --- # CSP form-action Debugging ## The Core Problem Chrome's CSP `form-action 'self'` implementation has a known behavior: when a form's `action` URL contains `//` in the **query string** (e.g., `?redirect=https%3A//example.com/`), the CSP evaluator may decode `%3A` → `:` internally, interpret `://` as a scheme separator, and block the submission as cross-origin — even though the action URL itself is same-origin. **Symptom:** Form POST returns `net::ERR_ABORTED` in DevTools network tab. Cookie may still be set (server responded), but browser doesn't follow the redirect. **Console error:** ``` Sending form data to 'https://same-origin.example/api?redirect=https%3A//other.example/' violates the following Content Security Policy directive: "form-action 'self'". The request has been blocked. ``` ## Diagnosis Steps 1. **Check CSP headers** on the page: ``` curl -sI "https://page-url" | grep -i content-security-policy ``` Look for `form-action` directive. 2. **Check form action** — is it a clean URL or does it carry redirect/return params in query string? ```js document.querySelector('form').action ``` 3. **Test without query params** — if form works without the redirect param in action URL, CSP is the culprit. 4. **Verify with Playwright console listener:** ```python page.on("console", lambda msg: print(f"[{msg.type}] {msg.text}")) # CSP violations appear as [error] messages ``` ## Fix Pattern **Move redirect/return_url from query string to hidden form field:** Before (broken): ```html