This vulnerability analysis is based on a flaw in Keycloak's realm import functionality, where placeholder substitution can be exploited to inject sensitive information from environment variables. The issue lies within the AbstractFileBasedImportProvider class, which is responsible for processing imported realm documents.
The root cause of the vulnerability is the use of StringSubstitutor to replace placeholders in the realm data. By default, StringSubstitutor can resolve environment variables, allowing an attacker with permissions to import a realm to craft a malicious realm document. This document can contain placeholders that reference environment variables on the Keycloak server, such as database credentials or other secrets. When the realm is imported, these placeholders are replaced with the actual values of the environment variables, which are then stored in the Keycloak configuration.
The patch for this vulnerability introduces a change that disables the environment variable substitution feature of StringSubstitutor by calling setEnableSubstitutionInVariables(false). This ensures that only explicitly provided values can be used for substitution, preventing the injection of sensitive data from the environment.
The vulnerable function is createProvider, which is responsible for creating the import provider and performing the placeholder substitution. During an exploit, this function would be called, and its name would appear in a runtime profile or stack trace.
For a security engineer, it is crucial to understand that any user with realm import permissions could potentially exploit this vulnerability to gain access to sensitive information stored in the environment variables of the Keycloak server. Upgrading to a patched version of Keycloak is the recommended mitigation.