Escaped backreferences to prevent XSS - #1138
Open
girishpanchal30 wants to merge 2 commits into
Open
Conversation
Collaborator
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Tests do not cover backslash-form backreferences or the slashed-output path targeted by the fix.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents preg_replace() backreference expansion from reintroducing unsafe content into responsive image attributes.
Changes:
- Escapes replacement-sensitive
$and\characters. - Adds XSS regression tests for affected srcset and sizes paths.
File summaries
| File | Description |
|---|---|
inc/tag_replacer.php |
Secures attribute replacement strings. |
tests/test-srcset.php |
Adds backreference-injection tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| $tag = '<img src="https://example.com/image.jpg" alt="Test" />'; | ||
| $missing_srcsets = [ | ||
| [ 'w' => 800, 'h' => 600, 'd' => 1, 's' => '$0 onload=alert(document.domain) x', 'b' => 0 ], |
selul
approved these changes
Sep 4, 2026
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.
Summary:
The 4.2.3 fix for
CVE-2026-5217escaped the srcset descriptor withesc_attr(), but the escaped value is then passed as the replacement argument ofpreg_replace(), which still expands$0/$1backreferences and can reinsert a raw double quote to break out of the attribute. Escape $ and \ withaddcslashes()right before eachpreg_replace()call inadd_missing_srcset_attributes(),enhance_existing_srcset(), andenhance_existing_sizes().All Submissions:
Closes https://github.com/Codeinwp/optimole-service/issues/1780
Other information: