Escaped backreferences to prevent XSS - #1138
Conversation
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 ], |
|
🤖 Review agent — review posted ✅
Run |
pirate-bot
left a comment
There was a problem hiding this comment.
Approved: The escaping blocks backreference expansion and preserves slashed output.
All eight focused regression tests passed on PHP 8.3.
Validation details
- PHP 8.3, WordPress 7.1, and PHPUnit 9.6.22 passed eight tests with 20 assertions.
- Static tracing connected descriptor data to both changed
srcsetsinks. - The trust-boundary pass found no changed-code security defect.
Untested areas
- Full suites, linters, and builds remain for CI.
- The planner returned no plan because its test hunk was abbreviated.
🤖 Automated review · run code-review-agent_6a9fe7ae670439.09386836.
|
🎉 This PR is included in version 4.2.12 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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: