add native csrf helpers

This commit is contained in:
udo
2026-07-06 09:58:25 +00:00
parent 125a24e2f9
commit b8c2efe976
7 changed files with 129 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
:sig
void csrf_rotate(String session_name = "uce-session", String token_name = "csrf_token")
:params
session_name : session/cookie name used by `csrf_token()`
token_name : form/action token namespace to clear
:content
Starts the named session if needed and clears the stored CSRF token for `token_name`. The next `csrf_token()` call creates a new token. Rotate after sensitive successful mutations when replaying the same submitted form should fail.
:example
String old_token = csrf_token();
csrf_rotate();
String new_token = csrf_token();
print(old_token != new_token ? "rotated\n" : "unchanged\n");
:see
>http
csrf_token
csrf_valid
session_start