Skip to content

Enhanced srcset handling - #1219

Merged
pirate-bot merged 1 commit into
developmentfrom
bugfix/optimole-service/1904
Nov 4, 2026
Merged

pirate-bot merged 1 commit into
developmentfrom
bugfix/optimole-service/1904

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Strengthened image tag attribute handling and srcset validation to prevent unintended attribute injection and ensure only valid width descriptors are processed. Added a utility method for safely injecting image attributes, tightened descriptor validation, and introduced comprehensive tests covering edge cases and security scenarios.

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

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

Plugin build for 2b2c1bd is ready 🛎️!

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

This change is approved. The note asks you to confirm that open issue #1112 is out of scope.

Validation details
  • Files reviewed: 5/5 changed files. The row about open issue #1112 (one-viewport slot width extrapolation) stays unchecked.
  • PHPUnit 9.6.22 on PHP 8.3.36 passed all 11 added and modified tests at HEAD [R3].
  • On the base tree, each added or modified test failed or errored [R5].
  • Test_Dimension_Replacement also passed with lazyload enabled [R2].
  • The profiler script emits only width descriptors, so the new descriptor check drops no real data.
  • A security pass found no remaining injection path in the changed code.
Untested areas
  • Open issue #1112 (one-viewport slot width extrapolation) was not checked. This change does not touch that logic.
  • No browser check of the rendered image markup was run.

🤖 Automated review · run code-review-agent_6ae97be70ee424.90642072.


🤖 Review agent — review posted ✅ on 2b2c1bd8 · approved · 0 findings · 17 min

Run code-review-agent_6ae97be70ee424.90642072 · trail

Comment thread inc/tag_replacer.php
foreach ( $missing_srcsets as $srcset_data ) {
// Validate required fields
if ( ! isset( $srcset_data['w'] ) || ! isset( $srcset_data['h'] ) || ! isset( $srcset_data['s'] ) ) {
if ( ! isset( $srcset_data['w'] ) || ! isset( $srcset_data['h'] ) || ! self::is_srcset_descriptor( $srcset_data['s'] ?? null ) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

note The new check accepts every <number>w descriptor the profiler stores. Widths that the profiler extrapolates from one viewport still pass. They can still overstate slot widths in the generated sizes value, as open issue #1112 describes. Please confirm that this change is not meant to fix that issue. A separate fix for it means this change is safe. If this change was meant to close it, the fix is incomplete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed out of scope. This PR fixes optimole-service#1904 (stored XSS). It only rejects srcset descriptors that aren't plain <int>w and changes where decoding/width/height are inserted. #1112 (single-viewport width extrapolation in srcset-detector.js _generateResponsiveSizes()) is a sizing-accuracy issue in the profiler script, which this change doesn't touch. It stays open for a separate fix.

@pirate-bot
pirate-bot merged commit 6723c29 into development Nov 4, 2026
14 checks passed
@pirate-bot
pirate-bot deleted the bugfix/optimole-service/1904 branch November 4, 2026 03:01
@pirate-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 4.2.19 🎉

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 Nov 4, 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.

2 participants