Skip to content

Escaped URL to prevent XSS#1047

Merged
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/optimole-service/1688
Apr 3, 2026
Merged

Escaped URL to prevent XSS#1047
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/optimole-service/1688

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Escaped the page profiler URL to prevent cross-site scripting.

Closes https://github.com/Codeinwp/optimole-service/issues/1688

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@pirate-bot
Copy link
Copy Markdown
Collaborator

pirate-bot commented Apr 2, 2026

Plugin build for 537fc2f is ready 🛎️!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent XSS by escaping the “page profiler URL” that gets injected into the inline optimizer/profiler script.

Changes:

  • Escapes the current page URL when replacing Profile::PLACEHOLDER_URL inside the optimizer script payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

inc/manager.php Outdated
Comment on lines 456 to 460
$hmac = wp_hash( $profile_id . $time . $this->get_current_url(), 'nonce' );
$js_optimizer = str_replace(
[ Profile::PLACEHOLDER, Profile::PLACEHOLDER_MISSING, Profile::PLACEHOLDER_TIME, Profile::PLACEHOLDER_HMAC, Profile::PLACEHOLDER_URL ],
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac, $this->get_current_url() ],
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac, esc_url( esc_js( $this->get_current_url() ) ) ],
$js_optimizer
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This change alters how the page profiler URL placeholder is rendered into the inline optimizer script, but there doesn’t appear to be any unit coverage asserting that replace_content() outputs a valid optimizer payload when the profiler is enabled (e.g., that pageProfileUrl is correctly escaped and remains consistent with the HMAC inputs). Consider adding a PHPUnit test that enables the profiler, runs replace_content(), and asserts the produced script contains a correctly encoded URL value (and does not contain HTML entity encoding that would change the value).

Copilot uses AI. Check for mistakes.
@vytisbulkevicius vytisbulkevicius merged commit c570b42 into development Apr 3, 2026
12 checks passed
@vytisbulkevicius vytisbulkevicius deleted the bugfix/optimole-service/1688 branch April 3, 2026 07:44
@pirate-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 4.2.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants