Skip to main content

hash_security_context

Function hash_security_context 

Source
pub fn hash_security_context(ctx: Option<&SecurityContext>) -> u64
Expand description

Hash the security context fields that affect response content.

Fields hashed: user_id, roles (sorted), tenant_id, scopes (sorted), attributes (sorted keys + JSON-serialized values).

Fields NOT hashed: request_id, ip_address, authenticated_at, expires_at, issuer, audience — these don’t affect which data the user can see.

attributes IS hashed because custom RLS policies can key on arbitrary attributes (e.g., “department”, “region”) to produce different query results for users who otherwise share the same user_id/roles/tenant_id/scopes.

Returns 0 when no security context is present (all users share one entry).