fix(proxy): enable trust proxy for Traefik compatibility#77
Merged
Conversation
- sanitize.ts: remove while loop on HTML tag regex (polynomial-redos) - sanitize.ts: loop on*= handler strip until stable (incomplete-multi-char-sanitization) - validate.ts: guard email regex with length > 254 check (polynomial-redos) - app.ts: replace /*/g instead of first-only * in CORS wildcard (incomplete-sanitization) - slack.test.ts: use exact field format instead of includes() for URL assertion (incomplete-url-substring-sanitization)
/<[^>]*>/g requires backtracking on inputs like '<aaaa' (no closing '>'), making it O(n²) in the worst case. Replace with /<[^>]*/g (no trailing '>' required) which greedily consumes without backtracking, then strip remaining '>' separately. Fixes both CodeQL polynomial-redos and incomplete-multi-char- sanitization alerts on sanitize.ts.
…CodeQL Both /<[^>]*>/g and /<[^>]*/g are flagged by CodeQL as polynomial-redos on inputs with many '<' chars and no '>'. Replace with an explicit loop that walks the string character by character, tracking whether we are inside a tag. No regex involved — O(n), no backtracking possible, and CodeQL cannot flag incomplete sanitization since '<' is structurally excluded from the output.
…lert The index-based for loop over str.length was flagged as js/loop-bound-injection since str.length is user-controlled. Switch to for-of which iterates via the iterator protocol without accessing .length.
Adds app.set('trust proxy', 1) so express-rate-limit correctly reads
client IPs from X-Forwarded-For headers set by Traefik, preventing
ERR_ERL_UNEXPECTED_X_FORWARDED_FOR validation errors and 500 crashes.
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.
Summary
app.set('trust proxy', 1)to Express app soexpress-rate-limitcorrectly reads client IPs fromX-Forwarded-Forheaders set by TraefikERR_ERL_UNEXPECTED_X_FORWARDED_FORvalidation error causing 500 crashes on all requests behind Traefik reverse proxyRoot cause
Traefik sets
X-Forwarded-Foron all proxied requests. Withouttrust proxy, express-rate-limit detects this as a misconfiguration and throws aValidationError, which hits the global error handler and returns 500.Test plan