Repository navigation
Description
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 = and & becomes & — 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=eyJhbGciOiJIUzUxMiIs...
and, for an invitation to an address without an account:
http://<host>/realms/<realm>/protocol/openid-connect/registrations?response_type=code&client_id=account&token=...
How to Reproduce
- Start Keycloak with
--features=organizationand an SMTP server pointing at a local
mail catcher. - Create a realm with
organizationsEnabled=true. - Create an organization.
POST /admin/realms/{realm}/organizations/{orgId}/members/invite-userwith the form
parameteremail=<address>(orinvite-existing-userwithid=<userId>for the
personalized variant — both branches of the template are affected).- Open the delivered message and compare the
text/plainpart withtext/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>Metadata
Metadata
Assignees
Labels
Type
Fields
Projects
- StatusShow more project fieldsDone
Activity
Do not sanitize the plain-text organization invitation email
ahus1 commentedon Sep 23, 2026
@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.
9 remaining items
ahus1 commentedon Oct 1, 2026
@martin-kanis - can you please backport this, at least to 26.8?
Do not sanitize the plain-text organization invitation email
Do not sanitize the plain-text organization invitation email (keycloa…