Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding id as a valid attribute for amp-iframe #1147

Merged
merged 4 commits into from Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions includes/sanitizers/class-amp-iframe-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function sanitize() {
* @type string $sandbox <iframe> `sandbox` attribute - Pass along if found; default to value of self::SANDBOX_DEFAULTS
* @type string $class <iframe> `class` attribute - Pass along if found
* @type string $sizes <iframe> `sizes` attribute - Pass along if found
* @type string $id <iframe> `id` attribute - Pass along if found
* @type int $frameborder <iframe> `frameborder` attribute - Filter to '0' or '1'; default to '0'
* @type bool $allowfullscreen <iframe> `allowfullscreen` attribute - Convert 'false' to empty string ''
* @type bool $allowtransparency <iframe> `allowtransparency` attribute - Convert 'false' to empty string ''
Expand All @@ -135,6 +136,7 @@ private function filter_attributes( $attributes ) {
case 'sandbox':
case 'class':
case 'sizes':
case 'id':
Copy link
Member

Choose a reason for hiding this comment

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

Instead of just allowing id we should probably obtain all attributes that are allowed on amp-iframe, including data-* ones. For non-data-* attributes, the list of attributes can be obtained via AMP_Allowed_Tags_Generated::get_allowed_tag( 'amp-iframe' ). The list of globally-allowed attributes can be obtained via AMP_Allowed_Tags_Generated::get_allowed_attributes()...

On second thought, we it would be better to just copy all of the attributes over from the iframe because then the whitelist sanitizer can then report when invalid attributes are present, as opposed to silently stripping them out.

$out[ $name ] = $value;
break;

Expand Down
5 changes: 5 additions & 0 deletions tests/test-amp-iframe-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function get_data() {
'<amp-iframe src="https://example.com/iframe" width="500" height="281" sandbox="allow-scripts allow-same-origin" layout="intrinsic" class="amp-wp-enforced-sizes"></amp-iframe>',
),

'iframe_with_id_attribute' => array(
'<iframe src="https://example.com/iframe" id="myIframe"></iframe>',
'<amp-iframe src="https://example.com/iframe" id="myIframe" sandbox="allow-scripts allow-same-origin" height="400" layout="fixed-height"></amp-iframe>',
),

'iframe_with_protocol_relative_url' => array(
'<iframe src="//example.com/video/132886713"></iframe>',
'<amp-iframe src="https://example.com/video/132886713" sandbox="allow-scripts allow-same-origin" height="400" layout="fixed-height"></amp-iframe>',
Expand Down