feat(csrf): add generic Origin/Referer CSRF guard to dunite-core #36
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/DEV-526-csrf-middleware"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Adds a generic Origin / Referer CSRF guard to
dunite-core::middleware(OriginGuard), alongside the existingRequestIdMiddlewareandSecurityHeaders. This is the shared home for the guard bunyip-api carries locally; a8n's API side (which today has no API-level CSRF layer) can adopt the same crate with no platform change.The guard is the bunyip implementation made framework-neutral: the app-specific bits are now constructor parameters, so the crate holds no product strings.
origins: &[String]- the allow-list (the same values the CORS layer echoes). Unparseable entries are logged and dropped, matching how the CORS layer tolerates a bad entry.exempt_prefixes: &[&str]- request-path prefixes skipped entirely (endpoints cross-origin by design that carry their own auth: an OAuth/OIDC surface gated by PKCE+state+nonce, an HMAC-signed webhook).ambient_cookies: &[&str]- cookie names that authenticate without proof of intent; a request carrying none has no CSRF surface.Behaviour
Identical to the source implementation: safe methods pass, exempt prefixes pass, a request with no ambient cookie passes,
Originis checked against the serialized origin allow-list with aRefererhost+port fallback, the literalnullorigin fails closed, and a request with neither header passes (a server-to-server hop, not a browser write). Rejections return 403 withcode: CSRF_ORIGIN_REJECTED. All eleven unit tests moved into the crate, parameterized via the new constructor args.Docs
middleware/mod.rs,lib.rs,dunite-core/Cargo.tomldescription, and the crates block inCLAUDE.mdupdated to list the CSRF guard next to request-id / security-headers.Validation
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspaceall green in the pinnedrust-builder-glibc:v1.0.1-rust1.94image.Consumer follow-up
bunyip-api swaps its
bunyip_api::csrf::OriginGuardfordunite_core::middleware::OriginGuardand deletes its copy in a bunyip PR that bumps the dunite pin to this merged rev (DEV-526, tracked under BUNYIP-340).#DEV-526