Skip to content

fix: prevent host header injection in email links#1267

Open
jwidan wants to merge 1 commit intoEqual-Vote:mainfrom
jwidan:fix/host-header-email
Open

fix: prevent host header injection in email links#1267
jwidan wants to merge 1 commit intoEqual-Vote:mainfrom
jwidan:fix/host-header-email

Conversation

@jwidan
Copy link
Collaborator

@jwidan jwidan commented Mar 9, 2026

Description

This PR patches a latent Host Header Injection vulnerability in the outbound email generation logic. While the production infrastructure currently shields the live server from this attack by enforcing explicit Host headers, the controllers implicitly trusted the client-supplied Host header at the application layer. Without the external infrastructure mitigation, this would allow anyone to hijack the email origin and inject their own domains into the hyperlinks of mass email campaigns using SendGrid.

  • Removes insecure req.get('host') usage from email controllers
  • Email base URLs now securely default to ServiceLocator.globalData().mainUrl
  • Added trailing slash stripping to prevent potential double-slash bugs
  • Rewrote && string interpolations into strict ternary operators in EmailTemplates.ts to prevent missing voter IDs from generating broken /false URLs.

@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for bettervoting ready!

Name Link
🔨 Latest commit d8fd8cd
🔍 Latest deploy log https://app.netlify.com/projects/bettervoting/deploys/69ae4fbcfe45bf0008be55d3
😎 Deploy Preview https://deploy-preview-1267--bettervoting.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant