CVE-2021-20222
📋 TL;DR
This vulnerability in Keycloak's new account console allows attackers to execute malicious code via manipulated referrer URLs. It affects Keycloak deployments using the new account console interface. The flaw can compromise data confidentiality, integrity, and system availability.
💻 Affected Systems
- Keycloak
📦 What is this software?
Keycloak by Redhat
⚠️ Risk & Real-World Impact
Worst Case
Complete system compromise allowing data theft, account takeover, and potential lateral movement within the Keycloak environment.
Likely Case
Session hijacking, data exfiltration from user accounts, and potential privilege escalation within the Keycloak realm.
If Mitigated
Limited impact with proper input validation and referrer restrictions in place.
🎯 Exploit Status
Exploitation requires user interaction (clicking malicious link) but is technically simple to execute.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Keycloak 12.0.5 and later
Vendor Advisory: https://bugzilla.redhat.com/show_bug.cgi?id=1924606
Restart Required: Yes
Instructions:
1. Download Keycloak 12.0.5 or later from official sources. 2. Stop the Keycloak service. 3. Backup configuration and database. 4. Replace with patched version. 5. Restart Keycloak service. 6. Verify functionality.
🔧 Temporary Workarounds
Disable New Account Console
allRevert to legacy account console which is not vulnerable
Set 'account2' feature to disabled in Keycloak configuration
Referrer Validation
allImplement strict referrer validation at web server/proxy level
Configure web server to validate and sanitize referrer headers
🧯 If You Can't Patch
- Implement WAF rules to block malicious referrer patterns
- Isolate Keycloak instance in network segment with strict egress filtering
🔍 How to Verify
Check if Vulnerable:
Check Keycloak version: if between 12.0.0 and 12.0.4 with new account console enabled, system is vulnerable.
Check Version:
Check Keycloak server logs or admin console for version information
Verify Fix Applied:
Verify Keycloak version is 12.0.5 or later and test referrer URL handling in account console.
📡 Detection & Monitoring
Log Indicators:
- Unusual referrer URLs in access logs
- JavaScript execution errors in account console
Network Indicators:
- HTTP requests with malicious referrer headers to /auth/realms/*/account/* endpoints
SIEM Query:
source="keycloak" AND (url="*/account/*" AND referrer CONTAINS "javascript:" OR referrer CONTAINS "data:")