Keycloak Pentesting

Published
Length
3 min read

Luis Felipe Dias

All posts

You perform keycloak pentesting by checking realm rules, token scopes, and client roles for gaps. Testers try to log in with weak tokens and gain extra rights across apps. Many teams set up a central identity server to handle user logins. Still, broad roles often give one user access to every database and server. When an attacker steals one token, they can read or write data everywhere. How keycloak pentesting works in practice A test starts by mapping all public endpoints on the identity ser

Keycloak: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You perform keycloak pentesting by checking realm rules, token scopes, and client roles for gaps. Testers try to log in with weak tokens and gain extra rights across apps. Many teams set up a central identity server to handle user logins. Still, broad roles often give one user access to every database and server. When an attacker steals one token, they can read or write data everywhere.

How keycloak pentesting works in practice

A test starts by mapping all public endpoints on the identity server. Testers look for open realms that allow anyone to sign up for an account. When open sign-up is active, an outsider can create a basic user profile right away. Next, the tester checks what tokens that new user gets after logging in.

Tokens hold claims that tell downstream apps what a user can do. Testers inspect these tokens to see if they list too many client roles. They also check if the server checks token signatures the right way. If an app skips signature checks, a tester can fake a token and gain admin rights.

Testers also review redirect rules on each client app during the review. Weak redirect rules let attackers steal login codes when a user signs in. They send a fake link to a team member and grab the returned token. Finally, testers check if admin consoles face the public web without strict login rules.

What native identity setup solves and what it misses

A central identity server does a great job of checking who a person is. It stops teams from making separate passwords for every single tool they run. You can turn off a user account in one place when someone leaves. It also lets you require multi-factor checks before anyone gets a login token.

Still, the identity server only decides who logs in at the start. It does not watch what a user does after the app accepts the token. Once an engineer or service logs in, they hold full rights for that role. The identity server cannot see the SQL queries or shell commands they run next.

Keycloak: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

This leaves a big gap during an active attack or a routine mistake. A valid token lets a user query a database and pull customer emails or card numbers. Native role checks cannot rewrite sensitive fields like phone numbers or national IDs in results. They also cannot pause a drop table command to ask a manager for approval.

How to reduce risk after your test

Start by locking down your admin console so only internal networks can reach it. Turn off self-registration on all realms that are meant for internal staff only. Check every client app and make sure redirect rules match exact domain names. Never use wildcards in redirect paths, because attackers use them to steal tokens.

Next, shrink the lifespan of your access tokens so stolen keys expire fast. Remove broad realm roles and give each app its own small set of permissions. Audit your service accounts often and delete any old keys that teams no longer use. Then, add runtime controls to check queries and commands after the login step finishes.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What is the most common flaw found during a Keycloak test?

Testers most often find weak redirect rules and broad token scopes on client apps. These flaws let attackers steal valid tokens and use them on other internal tools.

Does fixing token roles protect my databases from bad queries?

No, token roles only control who can log in to the database or app. They do not inspect or block dangerous queries once the session is active.

How often should teams test their identity server setup?

Teams should test their setup whenever they add a new realm or client app. Running a full review twice a year helps catch role creep early.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.