Keycloak open redirect: wildcard redirect URIs can be exploited to steal tokens
Keycloak clients configured with a wildcard redirect URI could be tricked into accepting a redirect URI pointing at an attacker-controlled host, because the validator URL-decoded the value and matched only a prefix. An attacker could send a crafted authorisation link so a victim's authorisation code or access token was delivered to the attacker's site.
securityblog.omegapoint.se
Published on securityblog.omegapoint.se
This post covers the technical details of CVE-2023-6927 which allows an attacker to create malicious Keycloak authorization request URLs that bypass the redirect URI validation. This can be exploited to steal a victim’s authorization code or access token, depending on the client configuration.
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 redirect validator URL-decoded the supplied redirect URI and compared only a prefix against the wildcard pattern, so an encoded userinfo section could hide an attacker-controlled host.
Impact
A victim's authorisation code or access token could be sent to an attacker-controlled site; Firefox shows a warning before the form post, while Chrome redirects without any prompt.
What the attacker needed
Client with wildcard redirect URI; victim clicks a crafted link; victim signs in to Keycloak
The fix
The issue was fixed in Keycloak 23.0.4, and the authors recommend strict string matching of redirect URIs instead of wildcards.
How it was found
- Configure or find a Keycloak client whose redirect URI ends with a wildcard.
- Craft an authorisation request whose redirect_uri is URL-encoded so the validator sees the expected prefix.
- Send the crafted link to a victim and have them sign in.
- The victim's browser is redirected to the attacker's host with the code or token attached.
- Exchange the stolen code for an access token where the client is public.
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.
When you sign in to a site using another service (like 'sign in with Google'), the service sends you back to the site afterwards with a short-lived code. The site tells the service in advance which return addresses are allowed. Here the check on that return address was too loose, so an attacker could make the service send the code to their own website instead, and then use it to log in as the victim.
What is Open redirect?
A trusted site forwards users to any address an attacker picks; rarely paid alone, often the missing link in a chain.