Skip to content
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

include $parsed_url[path] in the assessment #6995

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,14 @@ function amp_get_current_url() {
if ( isset( $parsed_url['port'] ) ) {
$current_url .= ':' . $parsed_url['port'];
}
$current_url .= '/';

$current_url .= '/' . trim($parsed_url['path'], '/') . '/' ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a site that is located at the root, wouldn't this result in // being appended?


if ( isset( $_SERVER['REQUEST_URI'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$current_url .= ltrim( wp_unslash( $_SERVER['REQUEST_URI'] ), '/' );
$current_url .= ltrim( wp_unslash( str_replace($parsed_url['path'], '', $_SERVER['REQUEST_URI']) ), '/' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unslashing should be limited to the input var:

Suggested change
$current_url .= ltrim( wp_unslash( str_replace($parsed_url['path'], '', $_SERVER['REQUEST_URI']) ), '/' );
$current_url .= ltrim( str_replace($parsed_url['path'], '', wp_unslash( $_SERVER['REQUEST_URI']) ), '/' );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, wouldn't it be a good hardening to ensure that it only removes $parsed_url['path'] from the string only when it appears at the very beginning? Let's say my install is located at /wordpress/ but the REQUEST_URI is /wordpress/category/wordpress/ then this would result in /category/ being incorrectly appended to $current_url as opposed to /category/wordpress/.

}

return esc_url_raw( $current_url );
}

Expand Down