Revision 1143137 of CSP: form-action

  • Revision slug: Web/HTTP/Headers/Content-Security-Policy/form-action
  • Revision title: CSP: form-action
  • Revision id: 1143137
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{HTTPSidebar}}

The HTTP {{HTTPHeader("Content-Security-Policy")}} form-action directive restricts the URLs which can be used as the target of a form submissions from a given context.

CSP version 2
Directive type {{Glossary("Navigation directive")}}
{{CSP("default-src")}} fallback No. Not setting this allows anything.

Syntax

One or more sources can be set for the form-action policy:

Content-Security-Policy: form-action <source>;
Content-Security-Policy: form-action <source> <source>;

Sources

{{page("Web/HTTP/Headers/Content-Security-Policy/default-src", "Sources")}}

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 {{HTMLElement("form")}} element with an action set to inline JavaScript will result in a CSP violation.

<meta http-equiv="Content-Security-Policy" content="form-action 'none'">

<form action="javascript:alert('Foo')" id="form1" method="post"> 
  <input type="text" name="fieldName" value="fieldValue"> 
  <input type="submit" id="submit" value="submit"> 
</form>

// Error: Refused to send form data because it violates the following 
// Content Security Policy directive: "form-action 'none'".

Specifications

Specification Status Comment
{{specName("CSP 3.0", "#directive-form-action", "form-action")}} {{Spec2('CSP 3.0')}} No changes.
{{specName("CSP 1.1", "#directive-form-action", "form-action")}} {{Spec2('CSP 1.1')}} Initial definition.

Browser compatibility

{{Compat("http/headers/content-security-policy", "form-action")}}

See also

  • {{HTTPheader("Content-Security-Policy")}}
  • {{HTMLElement("form")}}

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The HTTP {{HTTPHeader("Content-Security-Policy")}} <code><strong>form</strong></code><strong><code>-action</code></strong> directive restricts the URLs which can be used as the target of a form submissions from a given context.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">CSP version</th>
   <td>2</td>
  </tr>
  <tr>
   <th scope="row">Directive type</th>
   <td>{{Glossary("Navigation directive")}}</td>
  </tr>
  <tr>
   <th scope="row">{{CSP("default-src")}} fallback</th>
   <td>No. Not setting this allows anything.</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<p>One or more sources can be set for the <code>form-action</code> policy:</p>

<pre class="syntaxbox">
Content-Security-Policy: form-action &lt;source&gt;;
Content-Security-Policy: form-action &lt;source&gt; &lt;source&gt;;
</pre>

<h3 id="Sources">Sources</h3>

<p>{{page("Web/HTTP/Headers/Content-Security-Policy/default-src", "Sources")}}</p>

<h2 id="Examples">Examples</h2>

<h3 id="Meta_tag_configuration">Meta tag configuration</h3>

<pre class="brush: html">
&lt;meta http-equiv="Content-Security-Policy" content="form-action 'none'"&gt;</pre>

<h3 id="Apache_configuration">Apache configuration</h3>

<pre class="brush: bash">
&lt;IfModule mod_headers.c&gt; 
Header set Content-Security-Policy "form-action 'none';
&lt;/IfModule&gt;</pre>

<h3 id="Nginx_configuration">Nginx configuration</h3>

<pre class="brush: bash">
add_header Content-Security-Policy "form-action 'none';"</pre>

<h3 id="Violation_case">Violation case</h3>

<p>Using a {{HTMLElement("form")}} element with an action set to inline JavaScript will result in a CSP violation.</p>

<pre class="brush: html; example-bad">
&lt;meta http-equiv="Content-Security-Policy" content="form-action 'none'"&gt;

&lt;form action="javascript:alert('Foo')" id="form1" method="post"&gt; 
  &lt;input type="text" name="fieldName" value="fieldValue"&gt; 
  &lt;input type="submit" id="submit" value="submit"&gt; 
&lt;/form&gt;

// Error: Refused to send form data because it violates the following 
// Content Security Policy directive: "form-action 'none'".</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{specName("CSP 3.0", "#directive-form-action", "form-action")}}</td>
   <td>{{Spec2('CSP 3.0')}}</td>
   <td>No changes.</td>
  </tr>
  <tr>
   <td>{{specName("CSP 1.1", "#directive-form-action", "form-action")}}</td>
   <td>{{Spec2('CSP 1.1')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("http/headers/content-security-policy", "form-action")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTTPheader("Content-Security-Policy")}}</li>
 <li>{{HTMLElement("form")}}</li>
</ul>
Revert to this revision