# C.S.R.F. Mitigation

En attendant l’abandon des *credentials* de type *cookie*, *basic auth* et certificat client, une solution de mitigation des attaques de type C.S.R.F. est de positionner un *cookie* *(non http-only)* contenant **un&#x20;*****token*****&#x20;aléatoire et imprévisible&#x20;*****(un nonce)***.

L’application client *(JavaScript)* doit alors envoyer la valeur de ce *token* dans le *header* `Authorization` *(Ex. : `Authorization: Bearer ..., Csrf: ...`)* à chaque requête.

L’API n’a plus qu’à **comparer les deux valeurs présentes dans le&#x20;*****cookie*****&#x20;et dans le&#x20;*****header*** pour s'assurer qu'il s'agit du bon token.

*En effet, dans le cas d'une attaque C.S.R.F., l'attaquant utilise les cookies sans y avoir accès en lecture ou écriture.*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide-api-rest.marmicode.fr/securite-des-apis-rest/c.s.r.f.-mitigation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
