Sanitized player properties - #1144
Conversation
There was a problem hiding this comment.
🟡 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.
| '/^[a-z]+$/i', // Named color. | ||
| '/^(?:rgb|hsl)a?\(\s*[0-9a-z.%,\/\s-]+\)$/i', // Functional notation. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ✅
- Review: APPROVED · 0 findings
- Head: c3b118d
- Duration: 12 min 10 s
Run code-review-agent_6aa277f6760179.11290370 · trail
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
primaryColorandaspectRatioattributes 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: