Skip to content

Commit aa8e167

Browse files
committed
Icons: Store the sanitized icon content on registration.
Icons registered with inline SVG content are now stored in their sanitized form, so disallowed markup such as event handler attributes is no longer retained in the registry or returned to consumers. Developed in: WordPress#12623 Follow-up to [62748]. Props tyxla, wildworks. See #64847. git-svn-id: https://develop.svn.wordpress.org/trunk@62811 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 78aea8b commit aa8e167

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/wp-includes/class-wp-icons-registry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public function register( $icon_name, $icon_properties ) {
170170
);
171171
return false;
172172
}
173+
174+
$icon_properties['content'] = $sanitized_icon_content;
173175
}
174176

175177
$qualified_name = $collection . '/' . $unqualified_name;

tests/phpunit/tests/icons/wpIconsRegistry.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,28 @@ public function test_register_icon_with_file_path() {
258258
$this->assertStringContainsString( '<svg', $icon['content'] );
259259
}
260260

261+
/**
262+
* Should register an icon with its `content` sanitized.
263+
*
264+
* @ticket 64847
265+
*
266+
* @covers ::register
267+
*/
268+
public function test_register_icon_sanitizes_content() {
269+
$result = $this->registry->register(
270+
'test-collection/unsafe-content',
271+
array(
272+
'label' => 'Icon',
273+
'content' => '<svg viewbox="0 0 24 24" onload="alert(1)"><path d="M0 0" /></svg>',
274+
)
275+
);
276+
277+
$this->assertTrue( $result );
278+
279+
$icon = $this->registry->get_registered_icon( 'test-collection/unsafe-content' );
280+
$this->assertSame( '<svg viewbox="0 0 24 24"><path d="M0 0" /></svg>', $icon['content'] );
281+
}
282+
261283
/**
262284
* Should fail to register an icon that provides both `content` and `file_path`.
263285
*

0 commit comments

Comments
 (0)