Repository navigation
fix(security): restrict iframe allow policy to low-risk features - #25
Conversation
Release 1.2.1
Users without unfiltered_html could set an arbitrary `allow` value and delegate camera, microphone, geolocation or display-capture to any embedded origin. - Filter `allow` directives against an allowlist (filterable on the front end with `blockparty_iframe_allowed_features`) and drop origin lists, in PHP and in the editor preview. - Stop rendering the obsolete `allowpaymentrequest` attribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
return in_array( $attribute_name, self::ALLOWED_ATTRIBUTES, true )
|| str_starts_with( $attribute_name, 'aria-' )
|| str_starts_with( $attribute_name, 'data-' );Same in Generated by Claude Code |
Render the editor preview through BlockRenderer so iframe attribute filtering lives in PHP only, and the `blockparty_iframe_allowed_features` filter applies to the preview too. - Use ServerSideRender (default import, WordPress 6.7 compatible) with skipBlockSupportAttributes; drop convertAttributesToProps(), sanitizeAllowValue() and the JS ALLOWED_FEATURES list. - Make the nested preview markup fill the block wrapper in the editor. - Check aria-*/data-* attribute prefixes with str_starts_with() and startsWith() instead of a regex. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, applied in 123e26a, following this suggestion: Side effect: a bare Generated by Claude Code |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 123e26a. Configure here.
The server-side preview used the saved block attributes, while "View" shows the form before "Add iframe" saves it. A new block or a "Replace" edit then previewed an empty or stale iframe. Merge the form state into the attributes sent to ServerSideRender, as the former JS preview did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
skipBlockSupportAttributes keeps `style.dimensions`, so the server-side preview markup got the aspect ratio again inside the block wrapper and overflowed it. Drop `align` and `style` from the preview attributes: the editor wrapper already applies them. Co-Authored-By: Claude Opus 5.5 <[email protected]>

Fixes #24
What
allowvalues are filtered against a Permissions Policy feature allowlist:accelerometer,autoplay,clipboard-write,encrypted-media,fullscreen,gyroscope,picture-in-picture,web-share.srcorigin.blockparty_iframe_allowed_featuresto extend the list.allowpaymentrequestis removed from the allowlists.ServerSideRender, so it goes throughBlockRendererlike the front end (suggestion on #24). Filtering lives in PHP only, and the filter applies to the preview too. The JSALLOWED_FEATURES,sanitizeAllowValue()andconvertAttributesToProps()are removed;parseIframeCode()andisSafeIframeUrl()only help with input.alignandstyleare not sent to the preview: the editor wrapper already applies them, andskipBlockSupportAttributeskeepsstyle.dimensions.@wordpress/server-side-renderdependency (6.20.0, default import for WordPress 6.7–6.8 compatibility).aria-*/data-*attributes are checked withstr_starts_with()/startsWith()instead of a regex (review suggestion).savestays unfiltered on purpose. It must reproduce the old markup for block validation and is never mounted.Tests
No automated test suite exists in the repo. Checks run locally:
npm run lint:js src,phpcs,npm run build.Manual test in the block editor (WordPress 7.1.4,
wp-env, admin account):allow="camera *; fullscreen; microphone https://evil.test; autoplay",onloadanddata-test→ preview and front end both renderallow="fullscreen; autoplay"anddata-test, noonload.<iframe … allow="geolocation *; picture-in-picture" onload="…">, "View" without "Add iframe" → preview shows the typed iframe withallow="picture-in-picture"only.Not tested: contributor account,
blockparty_iframe_allowed_featuresin the preview.Review notes
allow="camera; microphone"(for example, some video-call embeds) lose those permissions. Sites that need them can extend the list with the filter.block-rendererREST endpoint (debounced while typing).🤖 Generated with Claude Code
Note
Medium Risk
Security-sensitive iframe attribute handling changes behavior for existing embeds that relied on broad
allowvalues; editor preview now depends on server render.Overview
Tightens iframe Permissions Policy delegation so contributors without
unfiltered_htmlcannot pass sensitiveallowfeatures (camera, microphone, geolocation, payment, etc.). Only a fixed low-risk feature set is kept, origin lists in directives are stripped, empty values drop the attribute, and obsoleteallowpaymentrequestis no longer output.Editor preview now uses server-side rendering via
ServerSideRender, so the sameBlockRendererpath filters attributes for both front end and preview. Client-side preview attribute conversion (convertAttributesToProps) is removed; paste parsing still uses a convenience allowlist in JS.Adds
blockparty_iframe_allowed_featuresto extend the PHP feature list,@wordpress/server-side-renderas a dependency, and editor SCSS so the nested preview fills block dimensions.Reviewed by Cursor Bugbot for commit e9d9e51. Bugbot is set up for automated code reviews on this repo. Configure here.