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

Conversation

magneticmg
Copy link

There are instances where a wordpress install is implemented as a backend but served as though in a subdirectory path.
i.e. backend is https://some.wordpress.install/ but served to the user as https://example.com/blog/. This fix makes sure to add the path of the home_url and removes that part from the $_SERVER['REQUEST_URI']. This way, the right uri is always preserved, otherwise it breaks.

There are instances where a wordpress install is implemented as a backend but served as though in a subdirectory path. 
i.e. backend is https://some_wordpress_install/ but served to the user as https://example.com/blog/. This fix makes sure to add the path of the home_url and removes that part from the $_SERVER['REQUEST_URI']. This way, the right uri is always preserved, otherwise it breaks.
@CLAassistant
Copy link

CLAassistant commented Mar 23, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Cameron Barr seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@westonruter
Copy link
Member

Could you add some tests to demonstrate the issue and ensure it works as expected?


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']) ), '/' );

@@ -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.

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/.

@magneticmg
Copy link
Author

Thank you for the follow up. I will amend the PR shortly and run those tests. Thank you

@westonruter westonruter added this to the v2.3 milestone Apr 14, 2022
@westonruter westonruter modified the milestones: v2.3, v2.3.1 May 26, 2022
@westonruter westonruter modified the milestones: v2.3.1, v2.4 Jan 12, 2023
@westonruter westonruter removed this from the v2.4 milestone Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants