Add HTML sanitization profiles for human-input emails #22218

Open
opened 2026-02-21 20:16:12 -05:00 by yindo · 0 comments
Owner

Originally created by @Blackoutta on GitHub (Feb 13, 2026).

Originally assigned to: @Blackoutta on GitHub.

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

We send human-input emails where the content is authored by untrusted users. Today the HTML is rendered and sent without sanitization, which makes XSS/HTML injection possible in email clients and downstream surfaces. We need a secure, configurable sanitization step that preserves rich HTML (images, tables, styles) but prevents script/event-handler/JS URL attacks. We also need a strict mode for high-security environments and a free mode for backward compatibility.

here is a screenshot showing the potentially malicious content that users might input on web UI. Although many email clients will invalidate code like this, but it is still safer to sanitize on dify server side.
code in hitl email input block:
Image

2. Additional context or comments

Proposed solution:

  • Add NH3-based sanitizer with profiles: strict (no remote), balanced (remote + tables/styles), free (no sanitization).
  • Allow cid: in strict for inline attachments, disallow data:.
  • Sanitize subject to strip control chars (header injection hardening).
  • Apply sanitizer to both test-send and background email task paths.
  • Add unit tests for sanitizer behavior and profiles.

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @Blackoutta on GitHub (Feb 13, 2026). Originally assigned to: @Blackoutta on GitHub. ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. We send human-input emails where the content is authored by untrusted users. Today the HTML is rendered and sent without sanitization, which makes XSS/HTML injection possible in email clients and downstream surfaces. We need a secure, configurable sanitization step that preserves rich HTML (images, tables, styles) but prevents script/event-handler/JS URL attacks. We also need a strict mode for high-security environments and a free mode for backward compatibility. here is a screenshot showing the potentially malicious content that users might input on web UI. Although many email clients will invalidate code like this, but it is still safer to sanitize on dify server side. code in hitl email input block: <img width="1092" height="1208" alt="Image" src="https://github.com/user-attachments/assets/d672fd6d-3022-4dd4-9bab-cb12b07c439f" /> ### 2. Additional context or comments Proposed solution: - Add NH3-based sanitizer with profiles: strict (no remote), balanced (remote + tables/styles), free (no sanitization). - Allow `cid:` in strict for inline attachments, disallow `data:`. - Sanitize subject to strip control chars (header injection hardening). - Apply sanitizer to both test-send and background email task paths. - Add unit tests for sanitizer behavior and profiles. ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo added the 💪 enhancement label 2026-02-21 20:16:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22218