hyperlane-plugin-security 23.3.1

A zero-allocation security hardening plugin for the Hyperlane framework providing prebuilt HSTS/CSP/COOP/COEP/CORP/Referrer headers, stateless HMAC-SHA256 CSRF protection, host/URI/body/path-traversal guards, and extensible SecurityRule hooks.
Documentation
# AGENTS.md — `hyperlane-plugin-security`

Concise engineering and iteration guidelines for `hyperlane-plugin-security` (`plugin/security/`).
Global rules live in [`../../.agents/skills/hyperlane/SKILL.md`](../../.agents/skills/hyperlane/SKILL.md), [`../README.md`](../README.md), and `~/.agents/skills/rust-standards/SKILL.md`.

## Scope & Module Boundaries

- **Role**: Prebuilt security response headers (HSTS/CSP/COOP/COEP/CORP/Referrer), stateless HMAC-SHA256 CSRF protection, host/URI/body/traversal request guards, and pluggable `SecurityRule`.
- **Dependencies**: Internal `hyperlane`; external `lombok-macros` (pure-Rust crypto, zero external crypto crates).
- **Layout**: `src/{lib,const,enum,fn,impl,static,struct,trait}.rs` (`SECURITY_PLUGIN` and internal crypto/header helpers stay `pub(crate)`); tests in `tests/`.

## Core Iteration Invariants

- **Hook contract & order**: `SecurityRequestHook` (`#[hyperlane::request_middleware(-105)]`, flushes rejection bytes before `Status::Reject`) and `SecurityResponseHook` (`#[hyperlane::response_middleware(-75)]`, always `Status::Continue`) MUST stay transparent when unconfigured.
- **Header hardening before inspection**: Apply compiled RFC 9110-validated security headers BEFORE `inspect_request` so error replies are hardened too; never overwrite handler-supplied headers (`!contains_key`), and strip `X-Powered-By` when enabled.
- **Guard precedence & traversal coverage**: Enforce URI length (`414`) -> body length (`413`) -> `has_path_traversal` (`400`, catching `..`, percent-encoded `%2e`/`%2E`, `\`/`%5c`, and `\0`/`%00`) -> case-insensitive `Host` allowlist (`400`) -> CSRF (`403`) -> custom `SecurityRule`s.
- **Constant-time stateless CSRF**: Exempt safe methods (`GET`/`HEAD`/`OPTIONS`/`TRACE`) and exact `exempt_paths`; verify header/cookie token equality and `<nonce>.<64-hex-mac>` via constant-time comparison and precomputed HMAC-SHA256 midstates with standard test vector coverage.

## Code & Documentation Standards

- Follow `rust-standards`: pure 9-keyword filenames, 3-section `mod.rs`, centralized imports in `src/lib.rs` and `tests/mod.rs`, `pub(crate)` struct fields with `lombok-macros` accessors (no `self.field`), explicit types on all `let`/closure bindings, zero `#[allow]`/`unwrap()`/`expect()`/`panic!()`, `pub` before `pub(crate)` in `const.rs`/`static.rs`, strict `Cargo.toml` dependency order, and comment-free tests in `tests/`.
- Keep all code, comments, docs, and commits pure English. Update `plugin/security/README.md` (and `plugin/README.md` / root `README.md` if hook order or public surface changes) in the same commit.

## Local Verification

```sh
cargo run -p hyperlane-cli -- fmt --check
cargo clippy -p hyperlane-plugin-security --all-features --all-targets -- -D warnings
cargo test -p hyperlane-plugin-security --all-features
python3 ~/.agents/skills/rust-standards/scripts/staged_file_gate.py .
python3 ~/.agents/skills/rust-standards/scripts/verify_dep_order.py .
```