fix: sanitize input for non-HTML consumers and fix ReDoS in cache#62
Merged
fix: sanitize input for non-HTML consumers and fix ReDoS in cache#62
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
04e031a to
6029fcf
Compare
6029fcf to
2458c9a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add input sanitization for fields served to non-HTML consumers (JWT payloads, JSON API responses, email subjects) and fix a ReDoS vulnerability in cache pattern invalidation. This is PR 3 in the AUDIT-001 remediation series.
Strategy: Input sanitization is applied only to fields consumed outside HTML templates (where PR 1's output escaping handles XSS). This prevents double-encoding.
Changes
Auth Registration Sanitization (
auth.ts)/register: sanitizeusername,firstName,lastName(returned in JWT and API response)/register/form: sanitize same fields/accept-invitation: sanitizeusernameemail(Zod-validated),password(hashed, never sanitize)Media API Sanitization (
api-media.ts)/:id: sanitizealtandcaptionfields (returned in JSON API responses viaGET /api/media/:id)Email Template Subject (
email-templates-plugin/admin-routes.ts)/templates: sanitizesubjectfield (rendered as plain text in email clients)ReDoS Fix (
cache/services/cache.ts)MemoryCache.invalidatePattern()andCacheService.invalidate(): escape regex metacharacters (.+|()[]{}^$\) before glob-to-regex conversion(a+)+*could cause catastrophic backtrackingTesting
Build Verification
E2E Tests
Technical Details
4 source files changed:
src/routes/auth.tssanitizeInput()on username/firstName/lastName in 3 handlerssrc/routes/api-media.tssanitizeInput()on alt/caption in PATCH handlersrc/plugins/available/email-templates-plugin/admin-routes.tssanitizeInput()on subjectsrc/plugins/cache/services/cache.tsBreaking Changes
None. Registration fields with HTML characters will now be stored escaped. Media alt/caption will be stored escaped.
Checklist
Generated with Claude Code in Conductor