Skip to content

Organization invite: link in the plain-text part of the email is HTML-escaped and unusable #52449

Closed

Description

@sashalab

Describe the bug

themes/src/main/resources/theme/base/email/text/org-invite.ftl renders the message
through kcSanitize(...) even though the template declares
<#ftl output_format="plainText">. The sanitizer HTML-encodes the invitation URL —
= becomes &#61; and & becomes &amp; — so the text/plain part of the multipart
invitation carries a link that does not work when clicked or copied from a plain-text
mail client. The text/html part of the same message is fine.

This is the only plain-text email template that sanitizes a message containing a link:
password-reset.ftl, email-verification.ftl, executeActions.ftl,
identity-provider-link.ftl and email-update-confirmation.ftl all interpolate
msg(...) directly. (text/workflow-notification.ftl also calls kcSanitize, but it
carries no link and uses ?no_esc.)

Version

26.7.2. Also reproduced on 26.7.1; text/org-invite.ftl is unchanged in main since
May 2024, so main looks affected as well.

Expected behavior

The text/plain part contains the same URL as the text/html part.

Actual behavior

http://<host>/realms/<realm>/login-actions/action-token?key&#61;eyJhbGciOiJIUzUxMiIs...

and, for an invitation to an address without an account:

http://<host>/realms/<realm>/protocol/openid-connect/registrations?response_type&#61;code&amp;client_id&#61;account&amp;token&#61;...

How to Reproduce

  1. Start Keycloak with --features=organization and an SMTP server pointing at a local
    mail catcher.
  2. Create a realm with organizationsEnabled=true.
  3. Create an organization.
  4. POST /admin/realms/{realm}/organizations/{orgId}/members/invite-user with the form
    parameter email=<address> (or invite-existing-user with id=<userId> for the
    personalized variant — both branches of the template are affected).
  5. Open the delivered message and compare the text/plain part with text/html.

Suggested fix

A plainText output format needs no HTML sanitizing:

--- a/themes/src/main/resources/theme/base/email/text/org-invite.ftl
+++ b/themes/src/main/resources/theme/base/email/text/org-invite.ftl
@@
 <#if firstName?? && lastName??>
-    ${kcSanitize(msg("orgInviteBodyPersonalized", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration), firstName, lastName))}
+    ${msg("orgInviteBodyPersonalized", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration), firstName, lastName)}
 <#else>
-    ${kcSanitize(msg("orgInviteBody", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration)))}
+    ${msg("orgInviteBody", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration))}
 </#if>

Activity

  1. added a commit that references this issue on Sep 4, 2026
    9330d90
  2. moved this from Backlog to In progress in Keycloak Roadmapon Sep 10, 2026
  3. added theissue type on Sep 23, 2026
  4. added
    kind/bug
    on Sep 23, 2026
  5. added
    area/organizations
    on Sep 23, 2026
  6. ahus1 commented on Sep 23, 2026

    @ahus1
    Member

    @sashalab - please open issues via the GitHub UI so issues get the correct types and labels. Without them, they will not be visible in the bug triage process. I fixed it manually for this issue.

  7. self-assigned this
    on Sep 29, 2026
  8. 9 remaining items

  9. ahus1 commented on Oct 1, 2026

    @ahus1
    Member

    @martin-kanis - can you please backport this, at least to 26.8?

  10. added a commit that references this issue on Oct 2, 2026
    e4c0450
  11. added a commit that references this issue on Oct 2, 2026
    8f6c22c
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 bug.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions