Summary
authentik's SAML NameID handling allowed XML comments to be injected into the NameID value, causing authentik to interpret only the portion before the comment.
In deployments using a SAML Source where users can influence their NameID, this parsing flaw could allow an attacker to impersonate other accounts and gain unauthorized access.
Affected context
This vulnerability affects authentik instances configured with a SAML Source where:
- The SAML assertion's NameID is used to identify or map users (e.g., username or email).
- XML Signing is enabled, so assertions are accepted as cryptographically valid.
- Users can control or influence their NameID value at the SAML identity provider (IdP).
Under these conditions, authentik's NameID extraction logic may misinterpret a crafted NameID containing XML comments, leading to incorrect user mapping and potential account compromise.
Exploit preconditions
- Attack surface: SAML authentication endpoint of the authentik instance.
- Required access:
- A valid account on the SAML Source (IdP) that is trusted by authentik.
- Ability to modify or influence the NameID value (often username or email) in the IdP profile or configuration.
- Trigger point: Processing of a SAML assertion during login where the NameID element contains an attacker-crafted value with an embedded XML comment.
- Why exploitation is possible:
- The NameID parsing logic does not robustly handle comments within the XML text.
- Authentik treats only the part of the NameID before the XML comment as the effective identifier, enabling an attacker to craft a NameID that maps to a different user's identifier.
- XML signature validation confirms the assertion's integrity, but does not prevent semantic manipulation of the NameID content.
Why this happens
The core issue stems from improper handling of XML content within security-sensitive fields, specifically the NameID in a SAML assertion.
Instead of treating the NameID as a simple, fully-validated string, authentik's extraction logic allowed XML comments to alter how the value was interpreted, effectively truncating the identifier at the comment boundary.
This maps to:
- CWE-91: XML Injection – XML structures (comments) injected into data fields are processed in a way that changes application logic.
- CWE-287: Improper Authentication – Authentication decisions are made based on an incorrectly parsed identity value.
- CWE-436: Interpretation Conflict – A mismatch between how the IdP/user intends the identifier to be interpreted and how authentik actually parses it, leading to security-relevant discrepancies.
The abstract insecure pattern is: relying on XML-parsed identity attributes without normalizing and validating them as opaque, unambiguous strings before using them in authentication and account-mapping logic.
Potential impact
- Attacker may impersonate other user accounts within the authentik-managed applications.
- Attacker could gain access to higher-privileged accounts if those accounts are mappable via crafted NameID values.
- Compromise of sensitive data and resources accessible to the impersonated users.
- Potential escalation to broader system compromise depending on the permissions of targeted accounts.
- Undermining of trust in SAML-based single sign-on for the affected environment.
General mitigation guidance
Effective mitigation focuses on treating identity attributes from SAML as opaque, fully-normalized strings and hardening XML handling:
- Normalize and sanitize NameID and similar attributes by stripping or rejecting XML markup constructs, including comments, before use in authentication or user mapping.
- Enforce strict schema validation for SAML assertions, disallowing unexpected constructs within identifiers and ensuring NameID content matches a constrained pattern (e.g., RFC-compliant email or username format).
- Use SAML and XML libraries that provide safe, defensive parsing modes and emphasize treating data-bearing elements as text rather than as mixed XML content.
- Implement robust, deterministic account-linking rules that do not rely on ambiguous or partially parsed identity attributes.
- Apply least-privilege principles to mapped accounts and limit the blast radius of any single account compromise.
- Include defense-in-depth checks (such as additional attribute verification or step-up authentication) before granting access to high-privilege roles.
How teams detect issues like this
Detection commonly involves both code-level and configuration-level analysis:
- Static analysis patterns:
- Flag use of XML parsing APIs that allow comments or mixed content in fields that drive authentication or authorization.
- Identify locations where NameID or other identity attributes are parsed or split based on XML structure rather than treated as plain strings.
- Code review signals:
- Authentication logic that assumes XML-parsed text nodes are safe identifiers without normalization or validation.
- Complex handling of SAML NameID or attributes that includes string concatenation, trimming, or manual parsing of XML constructs.
- Inconsistent interpretation of the same identity attribute between different components (e.g., IdP configuration vs SP mapping logic).
- Policy and runtime monitoring:
- Enforce security guidelines for SSO integration, requiring schema validation and normalization of identity attributes.
- Log and review authentication events for unusual patterns, such as multiple distinct users apparently sharing similar identifiers or unexpected account linkages.
- Automated SAST/IAST tools can be configured to detect risky XML processing in authentication paths, and security tests can include malformed SAML assertions to exercise parsing behavior.

