Submit a CSRF-protected form
POST
https://api.testingapis.com/api/auth/csrf/submitSubmit a CSRF-protected form (double-submit cookie check).
Requires the XSRF-TOKEN cookie from GET /api/auth/csrf/token and a matching X-CSRF-Token header.
Note: Call GET /api/auth/csrf/token first; send its token in X-CSRF-Token and keep the cookie it sets. The token must be one this server issued: tokens are signed, so a made-up value fails even when the cookie and header match.
CSRF double-submit: X-CSRF-Token header must match the XSRF-TOKEN cookie
Parameters 1
| Name | Type | Description |
|---|---|---|
X-CSRF-Tokenrequired | header · string | Token from GET /api/auth/csrf/token (the matching cookie is sent automatically by the browser). |
Request body
Optional. application/json. Any body.
Example body
{"comment": "hello"}Responses
- 200
- Cookie and header match.
- 403
- Cookie or header missing, they don't match, or the token wasn't issued by this server.
Example
Request
curl -X POST "https://api.testingapis.com/api/auth/csrf/submit" \
-H "Content-Type: application/json" \
-H "X-CSRF-Token: {{csrfToken}}" \
-H "Cookie: XSRF-TOKEN={{csrfToken}}" \
-d '{"comment": "hello"}'Response200 OK
{"message": "CSRF check passed. Form submitted.", "submittedAt": "2026-09-30T18:26:45Z"}Code examples
JavaScript (fetch)
// Browsers don't let fetch set a Cookie header; this works in Node.js 18 and later.
const response = await fetch("https://api.testingapis.com/api/auth/csrf/submit", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": "{{csrfToken}}",
"Cookie": "XSRF-TOKEN={{csrfToken}}",
},
body: "{\"comment\": \"hello\"}",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/auth/csrf/submit",
headers={
"Content-Type": "application/json",
"X-CSRF-Token": "{{csrfToken}}",
"Cookie": "XSRF-TOKEN={{csrfToken}}",
},
data="{\"comment\": \"hello\"}".encode("utf-8"),
allow_redirects=False,
)
print(response.status_code, response.text)Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.testingapis.com/api/auth/csrf/submit"))
.header("Content-Type", "application/json")
.header("X-CSRF-Token", "{{csrfToken}}")
.header("Cookie", "XSRF-TOKEN={{csrfToken}}")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"comment\": \"hello\"}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}