pgjwt_rs
pgjwt_rs · JWT verification for RS256 and Ed25519 tokens inside PostgreSQL
Overview
PostgreSQL · 13, 14, 15, 16, 17, 18
Usage
Sources:
pgjwt_rs 0.1.2 verifies asymmetric JWT signatures inside PostgreSQL using RS256 or Ed25519. It deliberately performs cryptographic verification only: expiration, not-before, audience, issuer, subject, nonce, and application authorization remain the caller’s responsibility.
Verify Before Using Claims
Store trusted public keys and the server-selected algorithm separately from untrusted tokens. Join a token to a key through a trusted key identifier or issuer mapping, require valid, then apply every claim required by the application. For example, given application-owned auth.incoming_token and auth.jwt_key tables:
Do not choose k.algorithm solely from the token header. The verifier checks that the signed header matches the expected algorithm, but the application must supply that expectation from trusted configuration.
User-Facing Functions
jwt_verify_rs256(text, text): verify an RS256 signature with an SPKI PEM public key and returnheader,payload, andvalid.jwt_verify_ed25519(text, text): verify an Ed25519/EdDSA signature with an SPKI PEM public key.jwt_verify(text, text, text): dispatch usingRS256,EdDSA, orED25519supplied by trusted code.jwt_decode_payload(text): decode payload JSON without checking a signature; the returned object is marked with_unverified.
The public key must use the PUBLIC KEY PEM label, not RSA PUBLIC KEY, RSA PRIVATE KEY, or another container. Tokens larger than 16 KiB and keys larger than 8 KiB are rejected.
Security Boundaries
jwt_decode_payload is only a parsing aid for locating a candidate trusted key. Never authorize, select a tenant, or construct unrestricted key lookups from its result. The verification functions decode and return a payload even when valid is false, so callers must test valid before reading any claim.
Version 0.1.2 does not enforce exp, nbf, or aud, and it does not require exp to exist. Add explicit policy for time claims, issuer, audience, subject, token type, clock skew, key rotation, and revocation. If wrapping these functions in SECURITY DEFINER, set a fixed safe search_path, schema-qualify objects, and revoke default execution from untrusted roles. The package advertises builds for PostgreSQL 13 through 18; validate the exact pgrx artifact on the target server.