CSP: form-action

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.

Die HTTP-Content-Security-Policy (CSP) form-action Direktive beschränkt die URLs, die als Ziel von Formularübertragungen in einem bestimmten Kontext verwendet werden können.

Warnung: Ob form-action Weiterleitungen nach einer Formularübertragung blockieren sollte, wird diskutiert und die Implementierung dieses Aspekts durch Browser ist uneinheitlich (zum Beispiel blockiert Firefox 57 die Weiterleitungen nicht, während Chrome 63 dies tut).

CSP-Version 2
Direktivtyp Navigationsdirektive
default-src Rückfall Nein. Wenn dies nicht gesetzt ist, ist alles erlaubt.

Syntax

http
Content-Security-Policy: form-action 'none';
Content-Security-Policy: form-action <source-expression-list>;

Diese Direktive kann einen der folgenden Werte haben:

'none'

Es dürfen keine Formularübertragungen erfolgen. Die einfachen Anführungszeichen sind obligatorisch.

<source-expression-list>

Eine durch Leerzeichen getrennte Liste von source expression Werten. Formularübertragungen dürfen an URLs erfolgen, die mit einem der angegebenen Quellausdrücke übereinstimmen. Für diese Direktive sind folgende Quellausdrücke anwendbar:

Beispiele

Meta-Tag-Konfiguration

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

Apache-Konfiguration

apacheconf
<IfModule mod_headers.c>
  Header set Content-Security-Policy "form-action 'none';"
</IfModule>

Nginx-Konfiguration

nginx
add_header Content-Security-Policy "form-action 'none';"

Verstoßfall

Die Verwendung eines <form>-Elements mit einer Action, die auf Inline-JavaScript gesetzt ist, führt zu einem CSP-Verstoß.

html
<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'".
-->

Spezifikationen

Specification
Content Security Policy Level 3
# directive-form-action

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
form-action
Redirects are blocked after a form submission
Non-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.

Siehe auch