Repository navigation
Make API URL in API promotion links safer - #1062
Merged
Merged
Conversation
Rename Utils::redirectToAPI() to Utils::getAPIUrl() since it builds a URL and doesn't redirect. - Rebuild the URL from the path and query of REQUEST_URI only, so the link is always same-origin (no //host or absolute URLs). - Escape the returned URL with secureText() so it can't break out of the href attribute (XSS). - Stop relying on QUERY_STRING, which is usually an empty string and not null, producing '/path&json' instead of '/path?json'. - APIPromotion() now parses the query string directly instead of the output of redirectToAPI(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Utils::redirectToAPI()printed the rawREQUEST_URIinto thehrefof the "API request" link, which had several problems:<>in the request URI could break out of thehrefattribute.//evil.example.com/...orhttps://evil.example.com/...produced a link to another host.QUERY_STRINGis usually an empty string, notnull, so the link became/path&jsoninstead of/path?json.QUERY_STRINGwas not set.Changes
Utils::redirectToAPI()toUtils::getAPIUrl(), since it builds a URL and doesn't redirect.Utils::getRequestPathAndQuery()helper that rebuilds the path and query fromREQUEST_URIonly (scheme, host, user info and fragment are dropped, the path always starts with a single/). It falls back to/ifREQUEST_URIis missing, not a string, or can't be parsed.getAPIUrl()escapes its output withsecureText(), so it can be printed directly in templates. It must not be used for aLocation:header, since&is returned as an HTML entity.APIPromotion()now parses the query string from the helper instead of the output ofredirectToAPI(). Its output format is unchanged, except that without a query string it no longer includes a stray/?json=parameter.Tests
Added cases for an empty query string, protocol-relative and absolute URLs, a malformed URI, a missing or non-string
REQUEST_URI, an attribute breakout attempt, andAPIPromotion()with no query string or HTML in the path. The full suite passes (320 tests).🤖 Generated with Claude Code