fix(csrf): stateless HMAC token to survive page cache
Déploiement PROD / check (push) Successful in 3m26s
Déploiement PROD / deploy (push) Successful in 8s

This commit is contained in:
2026-07-26 18:44:05 +04:00
parent 9109068b0b
commit 5899dfb856
4 changed files with 67 additions and 25 deletions
+22 -2
View File
@@ -695,6 +695,16 @@ TIP: Si vous déployez une instance indépendante, remplacez `LIBERAPAY_URL` par
NOTE: Le cache de l'API PeerTube et de WordPress (`includes/simple-cache.php`) est *toujours actif*, indépendamment de `CACHE_ENABLED`, avec des TTL par endpoint (catégories 1 h, vidéos/recherche 10 min, articles WP 15 min, comptes 5 min). Les fichiers sont stockés dans `cache/api/`.
.Sécurité
[cols="2,2,3",options="header"]
|===
| Constante | Défaut | Description
| `CSRF_SECRET`
| `'change-me-in-config-local-php'`
| Clé secrète utilisée pour signer les tokens CSRF stateless. À remplacer impérativement dans `config.local.php` par une valeur aléatoire (`php -r "echo bin2hex(random_bytes(32)) . PHP_EOL;"`)
|===
.Bloc « À propos » (pas de valeur par défaut — bloc masqué tant que non défini)
[cols="2,3",options="header"]
|===
@@ -784,7 +794,7 @@ Mise en page desktop : hero/Castopod/Funkwhale + Mastodon + WordPress s'organise
- *En-têtes* : `X-Frame-Options: SAMEORIGIN`, `X-Content-Type-Options: nosniff`, `X-XSS-Protection`, `Referrer-Policy: strict-origin-when-cross-origin`, `Permissions-Policy` restrictive, HSTS (HTTPS uniquement), CORP/COOP `same-origin`
+
NOTE: L'en-tête COEP a été *volontairement retiré* (commit `62d4d99`) : `require-corp` bloquait les embeds cross-origin de PeerTube, Mastodon, Castopod et Funkwhale.
- *CSRF* : jeton de session (`random_bytes(32)`) injecté en `<meta>`, vérifié par `hash_equals` sur l'endpoint AJAX ; vérification de l'en-tête `Origin`
- *CSRF* : jeton stateless HMAC-SHA256 (timestamp + signature, validité 1 h) injecté en `<meta>`, vérifié par `hash_equals` sur l'endpoint AJAX ; vérification de l'en-tête `Origin` ou du `Referer`
- *Anti-SSRF* : validation des URLs d'instances (schéma http/https, blocage IP privées et `localhost`), liste blanche des endpoints de l'API PeerTube, cURL sans redirections
- *Anti-XSS* : échappement systématique des sorties ; validation des entrées (UUID vidéo, requête de recherche ≤ 200 car., numéros de page, ID de catégorie 120)
@@ -1632,6 +1642,16 @@ TIP: If you deploy an independent instance, replace `LIBERAPAY_URL` with your ow
NOTE: The PeerTube API and WordPress cache (`includes/simple-cache.php`) is *always on*, regardless of `CACHE_ENABLED`, with per-endpoint TTLs (categories 1 h, videos/search 10 min, WP posts 15 min, accounts 5 min). Files are stored in `cache/api/`.
.Security
[cols="2,2,3",options="header"]
|===
| Constant | Default | Description
| `CSRF_SECRET`
| `'change-me-in-config-local-php'`
| Secret key used to sign stateless CSRF tokens. Must be replaced in `config.local.php` with a random value (`php -r "echo bin2hex(random_bytes(32)) . PHP_EOL;"`)
|===
."About" block (no default values — block hidden until defined)
[cols="2,3",options="header"]
|===
@@ -1721,7 +1741,7 @@ Desktop layout: hero/Castopod/Funkwhale + Mastodon + WordPress are arranged in c
- *Headers*: `X-Frame-Options: SAMEORIGIN`, `X-Content-Type-Options: nosniff`, `X-XSS-Protection`, `Referrer-Policy: strict-origin-when-cross-origin`, restrictive `Permissions-Policy`, HSTS (HTTPS only), CORP/COOP `same-origin`
+
NOTE: The COEP header was *deliberately removed* (commit `62d4d99`): `require-corp` broke cross-origin embeds from PeerTube, Mastodon, Castopod and Funkwhale.
- *CSRF*: session token (`random_bytes(32)`) injected as a `<meta>` tag, verified with `hash_equals` on the AJAX endpoint; `Origin` header verification
- *CSRF*: stateless HMAC-SHA256 token (timestamp + signature, 1 h validity) injected as a `<meta>` tag, verified with `hash_equals` on the AJAX endpoint; `Origin` or `Referer` header verification
- *Anti-SSRF*: instance URL validation (http/https scheme, blocking private IPs and `localhost`), allowlist of PeerTube API endpoints, cURL without redirects
- *Anti-XSS*: systematic output escaping; input validation (video UUID, search query ≤ 200 chars, page numbers, category ID 120)