New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security] Preserve URI fragment in HttpUtils::generateUri() #24203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ class HttpUtils | |
public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatcher = null) | ||
{ | ||
$this->urlGenerator = $urlGenerator; | ||
if ($urlMatcher !== null && !$urlMatcher instanceof UrlMatcherInterface && !$urlMatcher instanceof RequestMatcherInterface) { | ||
if (null !== $urlMatcher && !$urlMatcher instanceof UrlMatcherInterface && !$urlMatcher instanceof RequestMatcherInterface) { | ||
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.'); | ||
} | ||
$this->urlMatcher = $urlMatcher; | ||
|
@@ -150,7 +150,12 @@ public function generateUri($request, $path) | |
// fortunately, they all are, so we have to remove entire query string | ||
$position = strpos($url, '?'); | ||
if (false !== $position) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that necessary? What about a path like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragment gets stripped only if there is a query string, otherwise the urlGenerator result is returned directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification, but maybe we should add a test for that too to prevent regressions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases there is always a query string, because it uses the attributes from the request to build it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xabbuh Test added |
||
$fragment = parse_url($url, PHP_URL_FRAGMENT); | ||
$url = substr($url, 0, $position); | ||
// fragment must be preserved | ||
if ($fragment) { | ||
$url .= "#$fragment"; | ||
} | ||
} | ||
|
||
return $url; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this comment too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dedicated comment added just before fragment handling