ConstantTimeCsrfAuthorizer
Replaces pac4j-core's CsrfAuthorizer.hashEquals with a UTF-8 byte comparison via java.security.MessageDigest.isEqual.
Rationale — pac4j-core 6.3.2 CsrfAuthorizer.hashEquals(a, b) returns a.hashCode() == b.hashCode(). String.hashCode() is a 32-bit int, so any attacker that can enumerate strings offline can find one with the same hash as the target token (birthday-collision ≈ 2^16 tries; targeted-collision ≈ 2^32 — both trivial modern-hardware budgets). The comparison also is not constant-time: String.hashCode() iterates over the string and short-circuits, leaking length information via timing. MessageDigest.isEqual compares the full byte arrays in constant time, closing both issues.
Register this authorizer under the standard csrfCheck name in the Pac4j Config (see Pac4jCsrfSupport.installConstantTimeCsrfAuthorizer). DefaultAuthorizationChecker consults config.getAuthorizers before falling back to pac4j-core's stock singleton, so naming this subclass csrfCheck replaces the vulnerable comparator in the default authorizer chain that Pac4jHttpSecurity.secure applies to IndirectClient sessions.
See docs/CSRF_GUIDE.md for the full picture of Pac4j session-managed CSRF wiring.
Attributes
- Graph
-
- Supertypes
-
class CsrfAuthorizertrait Authorizerclass Objecttrait Matchableclass Any