csrf-defense
/csrf-defense
Blokuje cross-site request forgery przez ciasteczka SameSite, tokeny anty-CSRF na sesję i ścisłą dyscyplinę metod HTTP, przy endpointach zmieniających stan uwierzytelnianych ciasteczkami.
- Autor
- Amey-Thakur ↗
- Repozytorium
- AI-SKILLS ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 05.09.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 05.09.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Blokuje cross-site request forgery przez ciasteczka SameSite, tokeny anty-CSRF na sesję i ścisłą dyscyplinę metod HTTP, przy endpointach zmieniających stan uwierzytelnianych ciasteczkami.
Oryginalny opis (EN)
Block cross-site request forgery with SameSite cookies, per-session anti-CSRF tokens, and strict HTTP method discipline so a forged cross-origin request cannot act as the user. Use when building state-changing endpoints authenticated by cookies.
Jak działa
- Method
- Checks
- Boundaries
Podgląd SKILL.md
--- name: csrf-defense description: Block cross-site request forgery with SameSite cookies, per-session anti-CSRF tokens, and strict HTTP method discipline so a forged cross-origin request cannot act as the user. Use when building state-changing endpoints authenticated by cookies. --- # CSRF defense Cross-site request forgery abuses the browser's habit of attaching your cookies to every request to your site, including one triggered by a malicious page. The user is authenticated, so the forged request succeeds. The defense proves a request came from your own application, not merely from a browser that happens to hold a valid cookie. ## Method 1. **Set session cookies to SameSite=Lax or Strict.** `SameSite=Lax` stops the cookie from riding along on cross-site POSTs, which kills most CSRF outright. Use `Strict` for high-value sessions where following a link should require re-establishing context. This is your baseline, not your only layer. 2. **Add anti-CSRF tokens for state-changing requests.** Issue an unpredictable per-session or per-request token, embed it in forms, and read it back from a header or body field. Reject any POST, PUT, PATCH, or DELETE whose token is missing or wrong. An attacker's page cannot read your token, so it cannot forge the request. 3. **Keep GET safe and side-effect free.** Never change state on a GET. Reserve mutations for POST, PUT, PATCH, DELETE. Method discipline is what lets SameSite and token checks target the requests that matter; a state-changing GET slips past both. 4. **Pick the synchronizer or double-submit pattern deliberately.** The synchronizer token stores the value server-side; double-submit puts it in both a cookie and a request header and compares them, useful for stateless APIs. Choose one and apply it consistently rather than mixing half of each. 5. **Verify Origin and Referer on sensitive actions.** For requests that move money or change credentials, check that the `Origin` (or `Referer`) header matches your host, and reject a mismatch. It is a cheap second signal that costs an attacker a header the browser will not let them forge. 6. **Exempt token auth, not cookie auth.** APIs authenticated by a bearer token in an `Authorization` header are not CSRF-prone, because the browser does not attach that header automatically. Confirm the endpoint truly requires the header and does not also accept the cookie, or the exemption reopens the hole. ## Checks - Do your session cookies carry `SameSite=Lax` or stricter, confirmed in the response headers? - Does every state-changing endpoint reject a request with a missing or altered CSRF token? - Can you confirm no GET endpoint mutates state? ## Boundaries CSRF defense assumes the session itself is sound; it does nothing against a stolen token or an XSS payload running on your own origin, which bypasses same-origin protections entirely. Login and logout forms need CSRF protection too. For pure token-in-header APIs with no cookie auth, these controls are unnecessary rather than optional.
Wersje
W bazie nie ma innych skilli o nazwie csrf-defense.
Migawka bazy z 13.11.2026 · wersja paczki 7cd09607be8c (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 2 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100csrf-protection
Wdraża ochronę przed CSRF przez tokeny synchronizujące, double-submit cookies i atrybuty SameSite, przy zabezpieczaniu formularzy i endpointów zmieniających stan. - 100csrf-tokens-samesite-protection-mechanisms
Chroni endpointy WWW przed fałszowaniem żądań między witrynami, używając tokenów synchronizujących i atrybutu SameSite. - 90frontend-security
Wdraża zabezpieczenia frontendu: nagłówki CSP, SRI dla zewnętrznych zasobów, bezpieczne ciasteczka, tokeny CSRF i kodowanie wyjścia. - 100secure-cookie-attributes-samesite-secure-httponly
Zabezpiecza ciasteczka sesyjne przed przechwyceniem i CSRF, ustawiając atrybuty Secure, HttpOnly i SameSite. - 90csrf
Wykrywa formularze i endpointy zmieniające stan bez ochrony CSRF oraz sprawdza konfigurację ciasteczek sesji. - 100validating-csrf-protection
Sprawdza implementacje ochrony przed CSRF pod kątem luk, przy przeglądzie bezpieczeństwa formularzy i operacji zmieniających stan.