blob: 2c62d630ecad53aa1cb8948b1c033d592cd59ebe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
---
title: 'CSP: form-action'
slug: Web/HTTP/Headers/Content-Security-Policy/form-action
tags:
- CSP
- Content-Security-Policy
- Directive
- HTTP
- Security
- Sécurité
- form
- form-action
translation_of: Web/HTTP/Headers/Content-Security-Policy/form-action
---
{{HTTPSidebar}}
La directive HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) **`form`\*\***`-action`\*\* restreint les URL pouvant être utilisées comme cibles de soumissions de formulaires depuis un contexte donné.
> **Attention :** La question de savoir si `form-action` doit bloquer les redirections après une soumission de formulaire est encore [débattue](https://github.com/w3c/webappsec-csp/issues/8) et les implantations des navigateurs sur cet aspect sont incohérentes (par exemple Firefox 57 ne les bloque pas, contrairement à Chrome 63).
<table class="properties">
<tbody>
<tr>
<th scope="row">Version de CSP</th>
<td>2</td>
</tr>
<tr>
<th scope="row">Type de directive</th>
<td>{{Glossary("Navigation directive")}}</td>
</tr>
<tr>
<th scope="row">{{CSP("default-src")}} par défaut</th>
<td>Non, ne pas la définir autorise toutes les adresses.</td>
</tr>
</tbody>
</table>
## Syntaxe
Une ou plusieurs sources peuvent être utilisées pour cette directive :
Content-Security-Policy: form-action <source>;
Content-Security-Policy: form-action <source> <source>;
### Sources
{{page("fr/Web/HTTP/Headers/Content-Security-Policy/default-src", "Sources")}}
## Exemples
### Configuration par balise \<meta>
```html
<meta http-equiv="Content-Security-Policy" content="form-action 'none'">
```
### Configuration par Apache
```bash
<IfModule mod_headers.c>
Header set Content-Security-Policy "form-action 'none';"
</IfModule>
```
### Configuration par Nginx
```bash
add_header Content-Security-Policy "form-action 'none';"
```
### Cas de violation
Utiliser un élément {{HTMLElement("form")}} avec un attribut `action` défini à un script embarqué JavaScript résultera en une violation de CSP :
```html example-bad
<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'".
```
## Spécifications
| Spécification | Statut | Commentaire |
| ------------------------------------------------------------------------------------ | ---------------------------- | -------------------- |
| {{specName("CSP 3.0", "#directive-form-action", "form-action")}} | {{Spec2('CSP 3.0')}} | Inchangé. |
| {{specName("CSP 1.1", "#directive-form-action", "form-action")}} | {{Spec2('CSP 1.1')}} | Définition initiale. |
## Compatibilité des navigateurs
{{Compat("http.headers.csp.Content-Security-Policy.form-action")}}
## Voir aussi
- {{HTTPheader("Content-Security-Policy")}}
- {{HTMLElement("form")}}
|