Repository navigation
Do not throw when a redirect URL has a malformed escape sequence - #223
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
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.
Problem
safeRedirectpasses the target URL throughdecodeURIbefore it builds the redirect.decodeURIthrows aURIErrorwhen the string contains a malformed escape sequence such as%zz. Areturn-urlquery parameter or a room URL with such a sequence makes theset-usernameaction and the root loader fail with a 500 instead of redirecting.For example, open
/set-username?return-url=%2Froom%2F100%25zzwithout a display name set and submit the form. The action throwsURIError: URI malformed.Solution
Decode through a small helper that falls back to the raw value when
decodeURIthrows. The existing scheme check runs on that value unchanged.Testing
npx vitest --watch false app/utils/safeReturnUrl.test.tsThe new test file covers a normal redirect, the existing scheme check, and two URLs with a malformed sequence. Without the change, the two malformed cases fail with
URIError: URI malformed. With the change, all four tests pass.