Skip to content

Do not sanitize the plain-text organization invitation email - #52461

Merged
ssilvert merged 1 commit into
keycloak:mainfrom
sashalab:fix-org-invite-plaintext-link
Sep 30, 2026
Merged

ssilvert merged 1 commit into
keycloak:mainfrom
sashalab:fix-org-invite-plaintext-link

Conversation

@sashalab

@sashalab sashalab commented Sep 4, 2026

Copy link
Copy Markdown

Closes #52449

base/email/text/org-invite.ftl declares output_format="plainText" but still passes
the message through kcSanitize. The sanitizer HTML-encodes the invitation URL — =
becomes = and & becomes & — so the link in the text/plain part of the
invitation cannot be used. The text/html part is unaffected.

Both branches of the template are affected (with and without the invitee's name), and
so are both endpoints, invite-user and invite-existing-user.

No other plain-text email template sanitizes a message containing a link:
password-reset.ftl, email-verification.ftl, executeActions.ftl,
identity-provider-link.ftl and email-update-confirmation.ftl interpolate msg(...)
directly. (text/workflow-notification.ftl also calls kcSanitize, but it carries no
link.)

Verification

Manual, against 26.7.2 with a local mail catcher, following the reproduction in #52449:
before the change the text/plain part contained
.../login-actions/action-token?key=eyJhbGciOi...; after it, the same URL as the
text/html part.

I did not add an automated test: I could not run the integration suite in my
environment, and I would rather not submit a test I have not executed. Happy to add one
if you point me at the right test class.

@sashalab
sashalab requested a review from a team as a code owner September 4, 2026 17:24
Copilot AI balanced review requested due to automatic review settings September 4, 2026 17:24
@sashalab
sashalab requested a review from a team as a code owner September 4, 2026 17:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression lacks automated coverage for both plain-text invitation paths.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Removes HTML sanitization from plain-text organization invitation emails so invitation URLs remain usable.

Changes:

  • Directly renders localized invitation messages in both template branches.
  • Automated coverage is needed for unescaped links in anonymous and personalized plain-text invitations.
File summaries
File Description
themes/src/main/resources/theme/base/email/text/org-invite.ftl Prevents HTML encoding of plain-text invitation URLs.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@martin-kanis martin-kanis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sashalab Thank you for the PR. You are right that a plain-text emails templates do not need sanitization, same as i.e password-reset.ftl, email-verification.ftl. Therefore the fix is correct.

You just need to sign your commit with -s before this PR is merged.

Thanks!

kcSanitize HTML-encodes the invitation link (= becomes &keycloak#61;, & becomes
&) in a template whose output format is plainText, which leaves the
link in the text/plain part of the message unusable.

Closes keycloak#52449
Copilot AI balanced review requested due to automatic review settings September 30, 2026 18:11
@pedroigor
pedroigor force-pushed the fix-org-invite-plaintext-link branch from 9330d90 to ea4ac6a Compare September 30, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The URL regression needs automated coverage for both plain-text invitation variants.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@ssilvert ssilvert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ssilvert
ssilvert merged commit a3b5e33 into keycloak:main Sep 30, 2026
94 checks passed
PadzerButch pushed a commit to PadzerButch/keycloak that referenced this pull request Oct 2, 2026
…k#52461)

kcSanitize HTML-encodes the invitation link (= becomes &keycloak#61;, & becomes
&) in a template whose output format is plainText, which leaves the
link in the text/plain part of the message unusable.

Closes keycloak#52449
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants