CVE-2025-9162 Overview
A flaw exists in the org.keycloak/keycloak-model-storage-service component of Keycloak. The KeycloakRealmImport custom resource substitutes placeholders within imported realm documents, potentially referencing environment variables. This substitution process allows injection attacks when crafted realm documents are processed.
An authenticated attacker with high privileges can leverage this behavior to inject malicious content during the realm import procedure. The result is unintended data exposure within the Keycloak environment, classified under [CWE-526] (Exposure of Sensitive Information Through Environmental Variables).
Critical Impact
Attackers with administrative access to realm imports can extract sensitive environment variable contents from the Keycloak host, exposing secrets such as credentials, tokens, and configuration data.
Affected Products
- Red Hat build of Keycloak (see Red Hat advisories RHSA-2025:15336, 15337, 15338, 15339)
- Red Hat Single Sign-On operator components
- Upstream org.keycloak/keycloak-model-storage-service module
Discovery Timeline
- 2025-08-21 - CVE CVE-2025-9162 published to NVD
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2025-9162
Vulnerability Analysis
Keycloak's Operator processes KeycloakRealmImport custom resources to bootstrap realm configuration from declarative documents. During this processing, the model-storage service performs placeholder substitution on values within the imported document. The substitution engine resolves references that can point to environment variables available to the Keycloak process.
An attacker who can submit or modify realm import documents can craft placeholders that dereference sensitive environment variables. Because the substitution happens server-side with the privileges of the Keycloak Operator, the resolved values are written into realm entities and become accessible through normal realm inspection paths.
The issue impacts confidentiality of the host environment. It does not require user interaction and can be triggered over the network by an authenticated administrator submitting a crafted resource.
Root Cause
The root cause is unsafe placeholder expansion during realm import. The substitution logic does not restrict which variables can be resolved and does not distinguish between attacker-controlled input and trusted configuration sources. Environment variables containing secrets are consequently reachable from user-supplied realm documents.
Attack Vector
Exploitation requires network access to the Kubernetes or OpenShift API surface exposing the KeycloakRealmImport custom resource, plus privileges to create or modify that resource. The attacker embeds environment-variable placeholder syntax inside realm fields. When the Operator reconciles the resource, the substituted values are persisted into the realm, where the attacker retrieves them through standard Keycloak admin APIs.
No verified public exploit code is available. See the Red Hat CVE Details page and Red Hat Bug Report #2389396 for authoritative technical details.
Detection Methods for CVE-2025-9162
Indicators of Compromise
- KeycloakRealmImport custom resources containing placeholder syntax that references environment variables such as ${env:...} or similar substitution tokens in unexpected fields.
- Realm entities (client secrets, display names, attributes) whose stored values match known environment variable contents of the Keycloak pod.
- Unusual admin API reads targeting realm attributes or client configuration shortly after a realm import event.
Detection Strategies
- Audit Kubernetes and OpenShift API server logs for create and update operations on keycloakrealmimports.k8s.keycloak.org resources, correlating actor identity with the resource contents.
- Inspect committed KeycloakRealmImport manifests in GitOps repositories for placeholder syntax that references environment variables or system properties.
- Compare imported realm field values against the Keycloak container's environment to identify substitutions that resolved to secrets.
Monitoring Recommendations
- Enable Keycloak admin event logging and forward events to a centralized log platform for retention and analysis.
- Alert on any change to KeycloakRealmImport resources performed by non-pipeline identities.
- Monitor Keycloak Operator pod logs for realm import reconciliation events and correlate with subsequent admin API activity.
How to Mitigate CVE-2025-9162
Immediate Actions Required
- Apply the patched Keycloak Operator packages referenced in the Red Hat advisories RHSA-2025:15336 through RHSA-2025:15339 and RHSA-2025:16399 / RHSA-2025:16400.
- Restrict RBAC permissions on the keycloakrealmimports custom resource to a minimal set of trusted service accounts and cluster administrators.
- Rotate any secrets that were exposed to the Keycloak Operator through environment variables if realm imports from untrusted sources have occurred.
Patch Information
Red Hat has issued fixed builds tracked in RHSA-2025:15336, RHSA-2025:15337, RHSA-2025:15338, RHSA-2025:15339, RHSA-2025:16399, and RHSA-2025:16400. Upstream fixes are tracked through the Red Hat CVE record.
Workarounds
- Remove sensitive values from the Keycloak Operator pod environment and source them from Kubernetes Secrets mounted only where needed at runtime.
- Review and reject realm import documents that contain placeholder substitution tokens targeting environment variables.
- Enforce admission controls (for example, OPA Gatekeeper or Kyverno policies) that validate KeycloakRealmImport content before the Operator reconciles it.
# Example Kyverno policy fragment: reject realm imports containing env placeholder syntax
# Adapt to your cluster's policy engine and testing process before enforcement.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-keycloak-env-placeholders
spec:
validationFailureAction: enforce
rules:
- name: no-env-substitution-in-realm-import
match:
any:
- resources:
kinds:
- KeycloakRealmImport
validate:
message: "KeycloakRealmImport must not contain environment variable placeholders."
pattern:
spec:
realm:
"=(*)": "!*${env:*"
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

