Content-Security-Policy: form-action directive
The HTTP Content-Security-Policy (CSP) form-action directive restricts the URLs which can be used as the target of form submissions from a given context.
The HTTP Content-Security-Policy (CSP) form-action directive restricts the URLs which can be used as the target of form submissions from a given context.
[!WARNING] Whether
form-actionshould block redirects after a form submission is debated and browser implementations of this aspect are inconsistent (e.g., Firefox 57 doesn't block the redirects whereas Chrome 63 does).
| CSP version | 2 |
|---|---|
| Directive type | Navigation directive |
| default-src fallback | No. Not setting this allows anything. |
Syntax
Content-Security-Policy: form-action 'none';
Content-Security-Policy: form-action <source-expression-list>;
This directive may have one of the following values:
'none'- : No form submissions may be made. The single quotes are mandatory.
<source-expression-list>- : A space-separated list of source expression values. Form submissions may be made to URLs that match any of the given source expressions. For this directive, the following source expression values are applicable:
Examples
Meta tag configuration
<meta http-equiv="Content-Security-Policy" content="form-action 'none'" />
Apache configuration
<IfModule mod_headers.c>
Header set Content-Security-Policy "form-action 'none';"
</IfModule>
Nginx configuration
add_header Content-Security-Policy "form-action 'none';"
Violation case
Using a form element with an action set to inline JavaScript will result in a CSP violation.
```html example-bad
```
Specifications
Browser compatibility
See also
- Content-Security-Policy
- form