Skip to content

VideoPress: improve escaping of block attributes rendered into inline styles - #50865

Closed
vianasw wants to merge 1 commit into
trunkfrom
fix/videopress-poster-css-escaping
Closed

VideoPress: improve escaping of block attributes rendered into inline styles#50865
vianasw wants to merge 1 commit into
trunkfrom
fix/videopress-poster-css-escaping

Conversation

@vianasw

@vianasw vianasw commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

The VideoPress video block renders two author-supplied block attributes into inline CSS, and neither was escaped ideally for its context:

  • Poster URL — rendered into a background-image: url( … ). esc_url() does not escape every character that is significant inside a CSS url(), so the value is now emitted as a double-quoted CSS string (url("…")) to keep it contained.
  • maxWidth — rendered into max-width: …. It now only accepts a plain CSS length or percentage; any other value is dropped and the block falls back to full width (as with the 100% default). Note calc() is also dropped, which the dimension control does not produce.

Both are escaping/validation hardening for values that go into inline styles. Adds render regression tests.

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • Add a VideoPress block with a custom poster (preview-on-hover) and a max width; on the front end the poster and sizing still render correctly.
  • Confirm unusual poster or max-width values are handled safely — the poster stays inside url("…") and a non-length max-width is ignored rather than applied.
  • jp test php packages/videopress — the new regression tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NZ2nEAgqJJ5zmczuyFngF9

@vianasw
vianasw requested a review from a team as a code owner July 28, 2026 14:01
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/videopress-poster-css-escaping branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/videopress-poster-css-escaping

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 28, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 28, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/videopress/src/class-initializer.php 153/205 (74.63%) 10.13% -19 💚

Full summary · PHP report · JS report

@haqadn haqadn added [Status] Needs Review This PR is ready for review. [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] Needs Review This PR is ready for review. labels Jul 28, 2026
@vianasw
vianasw force-pushed the fix/videopress-poster-css-escaping branch from bb1f401 to bccb5af Compare July 31, 2026 13:35
@vianasw vianasw changed the title VideoPress: escape the block poster URL for its CSS url() context VideoPress: prevent CSS injection via the video block's poster and max-width attributes Jul 31, 2026
@vianasw
vianasw force-pushed the fix/videopress-poster-css-escaping branch from 00657eb to 3b1aecb Compare July 31, 2026 15:36
@vianasw vianasw changed the title VideoPress: prevent CSS injection via the video block's poster and max-width attributes VideoPress: improve escaping of block attributes rendered into inline styles Jul 31, 2026
… styles

The video block renders the poster URL into a CSS url() and the maxWidth
attribute into an inline style. Escape and validate both for their CSS
context: emit the poster URL as a double-quoted CSS string, and accept only
a plain CSS length or percentage for maxWidth (falling back to full width
otherwise). Adds render regression tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZ2nEAgqJJ5zmczuyFngF9
@vianasw
vianasw force-pushed the fix/videopress-poster-css-escaping branch from 3b1aecb to f6616ac Compare July 31, 2026 15:37
@vianasw

vianasw commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Closing this in favor of an internal change so it can be coordinated with related work — nothing further needed here. Thanks!

@vianasw vianasw closed this Jul 31, 2026
@vianasw
vianasw deleted the fix/videopress-poster-css-escaping branch July 31, 2026 16:00
@github-actions github-actions Bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants