Skip to content

[2.x] fix(nicknames): sanitize display names to prevent injection in HTML notification emails#4454

Merged
imorland merged 2 commits into2.xfrom
im/fix-4399-nickname-email-injection
Mar 15, 2026
Merged

[2.x] fix(nicknames): sanitize display names to prevent injection in HTML notification emails#4454
imorland merged 2 commits into2.xfrom
im/fix-4399-nickname-email-injection

Conversation

@imorland
Copy link
Copy Markdown
Member

Summary

Fixes #4399. Port of the GHSA-3c4m-j3g4-hh25 fix from 1.x (nicknames v1.8.3) adapted for 2.x's additional HTML email rendering context.

2.x sends HTML notification emails where display names are:

  • Embedded in translation strings then passed through $formatter->convert() (markdown→HTML), allowing [CLICK](https://evil.com) to become a live <a> tag
  • Output via {!! !!} in the greeting template, allowing raw HTML injection

Changes:

  • NicknameDriver::displayName() — strips [, ], (, ), <, > from the returned name (neutralises markdown/HTML link syntax), and inserts a zero-width space after every . (breaks nasty.com domain autolinks). Covers nicknames stored before the validation rule existed.
  • UserResourceFields — adds not_regex:/[\[\]()<>]/ as a hard validation rule so these characters are rejected at save time going forward.

Test plan

  • Unit tests for NicknameDriver sanitization (10 cases: clean names, dots, brackets, parens, angle brackets, full markdown link syntax, username fallback)
  • Integration tests for validation rejection (6 injection patterns → 422) and that jane.smith still saves successfully
  • Full nicknames test suite passes (14 unit + 20 integration)

imorland and others added 2 commits March 15, 2026 08:19
…HTML notification emails

Strip markdown/HTML link syntax characters ([, ], (, ), <, >) from display
names returned by NicknameDriver, and insert a zero-width space after dots
to break domain autolinks (e.g. nasty.com). Also adds a not_regex validation
rule to reject these characters at save time, so the driver-level stripping
only needs to handle nicknames saved before this fix.

Relates to GHSA-3c4m-j3g4-hh25 (the 1.x advisory); this is the equivalent
fix for 2.x, which additionally renders display names through a markdown
formatter before output in HTML email bodies.
@imorland imorland added this to the 2.0.0-beta.8 milestone Mar 15, 2026
@imorland imorland marked this pull request as ready for review March 15, 2026 08:21
@imorland imorland requested a review from a team as a code owner March 15, 2026 08:21
@imorland imorland merged commit 231afeb into 2.x Mar 15, 2026
27 checks passed
@imorland imorland deleted the im/fix-4399-nickname-email-injection branch March 15, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] Display names are not sanitized in HTML notification emails

2 participants