8000 [CVE-2026-37980] Stored XSS in select-organization.ftl - FreeMarker HTML-escape insufficient in inline JS handler · Issue #48049 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
  • Description

    @ahus1

    Description

    A stored cross-site scripting (XSS) issue exists in the organization selection login page (select-organization.ftl). When an organization alias contains malicious JavaScript code, FreeMarker's HTMLOutputFormat escapes the value for HTML attribute context, but this escaping is insufficient when the attribute is an inline JavaScript onclick handler.

    The browser HTML-decodes entities before passing the value to the JavaScript engine, allowing the injected script to execute. This occurs because the template uses ${organization.alias} directly in an onclick attribute without JavaScript-specific escaping.

    Prerequisites:

    • User must have manage-realm or manage-organizations permission to create organizations with malicious aliases
    • Organizations feature must be enabled in the realm

    Version Affected

    26.5.5 and potentially other versions

    Steps to Reproduce

    1. Log in as a user with manage-realm or manage-organizations permission
    2. Create a new organization with an alias containing JavaScript code
    3. Navigate to the login page where organization selection is displayed
    4. Click on the organization entry
    5. Observe that the JavaScript code executes in the browser

    Expected Behavior

    Organization aliases should be properly escaped for JavaScript context when used in inline event handlers. The system should either:

    • Use JavaScript-specific escaping for values in onclick handlers
    • Avoid inline event handlers entirely and use event listeners instead
    • Validate organization aliases to prevent JavaScript-unsafe characters

    Actual Behavior

    The organization alias is only HTML-escaped, which is insufficient for inline JavaScript context. The browser decodes HTML entities before executing the JavaScript, allowing the injected code to run.

    Additional Context

    This issue has been assigned CVE-2026-37980 for tracking purposes.

    While this requires elevated administrative permissions (manage-realm or manage-organizations), it could be problematic in scenarios where:

    • Organization names are provisioned automatically via API/automation that assumes all characters are safe
    • A compromised admin account could use this to escalate access to other realms
    • Multiple administrators with different trust levels manage organizations

    The team is planning a comprehensive review of FreeMarker templates to identify similar context-specific escaping issues.


    This issue was originally tracked in the private repository. Migrated by @ahus1.

    Activity

    1. added
      kind/cveIssues identified as CVEs on third-party dependencies, or issues which Keycloak is not affected
      area/organizationsOrganizations — multi-tenancy, members, managed IdPs, domains, invitations
      on Apr 14, 2026
    2. added theissue type on Apr 14, 2026
    3. ahus1 commented on Apr 14, 2026

      @ahus1
      MemberAuthor

      @pedroigor the embargo has been lifted. Please provide a fix in upstream as discussed previously thanks!

    4. added a commit that references this issue on Apr 15, 2026
      3c596dd
    5. added a commit that references this issue on Apr 20, 2026
      15727dd
    6. 2 remaining items

    7. added a commit that references this issue on Apr 23, 2026
      eb2aa59
    8. added a commit that references this issue on Jun 24, 2026
      a784182
    9. added a commit that references this issue on Jul 20, 2026
      4834155
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Type

    Fields

    No fields configured for cve.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

    • 0