Skip to content

Sanitized player properties - #1144

Open
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/optimole-service/1788
Open

Sanitized player properties#1144
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/optimole-service/1788

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Sanitized style-related attributes to prevent unsafe values, ensuring only declared attributes are rendered, and added comprehensive unit tests to verify correct behavior and prevent regressions. Added sanitization for primaryColor and aspectRatio attributes to ensure only valid CSS values or known options are used, falling back to safe defaults when necessary. This prevents injection of unsafe styles or scripts.

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

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

pirate-bot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Plugin build for c3b118d is ready 🛎️!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Invalid color strings bypass the intended fallback.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Secures server-rendered video-player styles and attributes.

Changes:

  • Sanitizes color, aspect-ratio, and spacing values.
  • Prevents undeclared attributes from reaching markup.
  • Adds regression tests.
File summaries
File Description
inc/video_player.php Adds defaults and style sanitization.
tests/test-video-player-block.php Tests secure rendering and fallbacks.
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.

Comment thread inc/video_player.php Outdated
Comment on lines +366 to +367
'/^[a-z]+$/i', // Named color.
'/^(?:rgb|hsl)a?\(\s*[0-9a-z.%,\/\s-]+\)$/i', // Functional notation.

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.

I have reverted the color sanitization in c3b118d, as we are already escaping its value. Therefore, there is no need to sanitize the color attribute.

@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: The changed renderer blocks the reported event-attribute injection.

The focused block tests and an Author REST render removed unsafe attributes and preserved expected output.

Validation details
  • WordPress 7.1 on PHP 8.3 passed 6 focused tests with 24 assertions.
  • An Author REST post rendered without event attributes and sanitized the aspect ratio.
  • Both changed PHP files passed syntax checks.
Untested areas
  • Browser checks were skipped because the front page had a redirect loop.
  • Complex editor spacing values lacked a resolved saved-value contract.

🤖 Automated review · run code-review-agent_6aa277f6760179.11290370.


🤖 Review agent — review posted ✅

Run code-review-agent_6aa277f6760179.11290370 · trail

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