Authentication bypass in pac4j-JWT using only the RSA public key
The pac4j-JWT authenticator accepted a JWE token encrypted with the server's RSA public key, which is not secret, and then trusted the claims inside without verifying a signature. An attacker who knows the public key could craft a token claiming admin roles and be authenticated as that user.
codeant.ai
Published on codeant.ai
public class Poc { public static void main(String[] args) throws Exception {
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the authenticator treats a JWE encrypted with the public key as trusted and does not require a valid signature over the inner claims.
Impact
An attacker could authenticate as an arbitrary user, including an administrator, without any secret key.
What the attacker needed
Knowledge of the server's RSA public key; ability to submit a token to the authenticator
How it was found
- Generate an RSA key pair representing the server's keys.
- Configure the JwtAuthenticator with RSA encryption and signature using that key pair.
- Build a JWT claims set with an admin subject and admin roles.
- Encrypt the inner JWT as a JWE using only the RSA public key.
- Pass the crafted token to the authenticator and observe it is accepted as the admin user.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A JWT is a token that proves who you are. Normally the server signs it with a private key so nobody can change it. Here the library let anyone encrypt a token with the public key, which is meant to be shared, and then believed whatever was inside, so a fake admin token was accepted.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.