[PR #23295] security: Fix XSS vulnerability in authentication check-code pages #30222

Closed
opened 2026-02-21 20:47:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/23295

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Fixes #23294

Summary

This PR fixes a critical XSS vulnerability in authentication check-code pages by replacing unsafe dangerouslySetInnerHTML usage with secure React rendering patterns.

Security Issue: The application was using dangerouslySetInnerHTML with unvalidated user input from URL parameters, creating a potential XSS vulnerability that depended on i18next configuration for protection.

Fix: Replaced dangerouslySetInnerHTML with safe React rendering by separating HTML structure from user input and utilizing React's automatic HTML escaping.

Affected Files:

  • web/app/signin/check-code/page.tsx
  • web/app/reset-password/check-code/page.tsx
  • web/app/(shareLayout)/webapp-signin/check-code/page.tsx
  • web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx
  • web/i18n/en-US/login.ts

Technical Changes:

  • Replaced unsafe pattern: <span dangerouslySetInnerHTML={{ __html: t('login.checkCode.tips', { email }) }}></span>
  • With secure pattern: <span>{t('login.checkCode.tipsPrefix')}<strong>{email}</strong></span>
  • Added new translation key tipsPrefix for safe rendering
  • Removed unused tips translation key
  • Added comprehensive security test suite

Security Impact: Eliminates code-level XSS vulnerability and removes dependency on external configuration for security.

Screenshots

N/A

Note: UI appearance remains unchanged - this is a security-only fix with no visual changes

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/23295 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. Fixes #23294 ## Summary This PR fixes a critical XSS vulnerability in authentication check-code pages by replacing unsafe `dangerouslySetInnerHTML` usage with secure React rendering patterns. **Security Issue**: The application was using `dangerouslySetInnerHTML` with unvalidated user input from URL parameters, creating a potential XSS vulnerability that depended on i18next configuration for protection. **Fix**: Replaced `dangerouslySetInnerHTML` with safe React rendering by separating HTML structure from user input and utilizing React's automatic HTML escaping. **Affected Files**: - `web/app/signin/check-code/page.tsx` - `web/app/reset-password/check-code/page.tsx` - `web/app/(shareLayout)/webapp-signin/check-code/page.tsx` - `web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx` - `web/i18n/en-US/login.ts` **Technical Changes**: - Replaced unsafe pattern: `<span dangerouslySetInnerHTML={{ __html: t('login.checkCode.tips', { email }) }}></span>` - With secure pattern: `<span>{t('login.checkCode.tipsPrefix')}<strong>{email}</strong></span>` - Added new translation key `tipsPrefix` for safe rendering - Removed unused `tips` translation key - Added comprehensive security test suite **Security Impact**: Eliminates code-level XSS vulnerability and removes dependency on external configuration for security. ## Screenshots N/A *Note: UI appearance remains unchanged - this is a security-only fix with no visual changes* ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:47:05 -05:00
yindo closed this issue 2026-02-21 20:47:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30222