ConstantTimeCsrfAuthorizer

works.iterative.server.http.impl.pac4j.ConstantTimeCsrfAuthorizer
class ConstantTimeCsrfAuthorizer extends CsrfAuthorizer

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 CsrfAuthorizer
trait Authorizer
class Object
trait Matchable
class Any

Members list

Value members

Inherited methods

def getHeaderName(): String

Attributes

Inherited from:
CsrfAuthorizer
def getParameterName(): String

Attributes

Inherited from:
CsrfAuthorizer
def isAuthorized(x$0: WebContext, x$1: SessionStore, x$2: List[UserProfile]): Boolean

Attributes

Inherited from:
CsrfAuthorizer
def isCheckAllRequests(): Boolean

Attributes

Inherited from:
CsrfAuthorizer
def setCheckAllRequests(x$0: Boolean): Unit

Attributes

Inherited from:
CsrfAuthorizer
def setHeaderName(x$0: String): Unit

Attributes

Inherited from:
CsrfAuthorizer
def setParameterName(x$0: String): Unit

Attributes

Inherited from:
CsrfAuthorizer
def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Inherited from:
CsrfAuthorizer