gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

XSS attack possible inside links in paragraph block

Open thatdevgirl opened this issue 8 years ago • 4 comments

Describe the bug It is possible to inject Javascript code inside a link's href in the paragraph block.

To Reproduce

  • Create a page or post with a paragraph block.
  • Inside that paragraph block, insert HTML code with a link whose href attribute contains JS code. For example:
Here is some text.
<a href="javascript:alert('hello world!')">Click me</a>
  • Note that the link renders inside the editor.
  • Save and view the page.
  • Click on the link. The Javascript runs.

Expected behavior

The JS code inside the href attribute should be stripped out.

Additional context

  • The block does strip out <script> tags.
  • Tested on Gutenberg 4.1.1

thatdevgirl avatar Nov 06 '18 00:11 thatdevgirl

Nice work finding this!

Luciaisacomputer avatar Nov 06 '18 02:11 Luciaisacomputer

Thank you for the bug report, @thatdevgirl!

Were you testing as an admin/editor user, or as an author?

Admins and Editors are able to insert arbitrary JavaScript in a post, whereas Authors and Contributors cannot. I was able to reproduce the behaviour you described as an Admin, but not as an Author.

Similarly, I'm able to reproduce the same behaviour in the classic editor as an Admin, but not as an Author.

pento avatar Nov 06 '18 03:11 pento

Tested with WordPress 4.9.8 and Gutenberg 4.2.0-rc.1 and can confirm I can add JavaScript into a link when logged in as an Administrator or Editor role (as expected) but not as an Author or Contributor role.

designsimply avatar Nov 06 '18 04:11 designsimply

Unless this is happening as an author or contributor role this is working as expected.

I think it'd be nice if we didn't allow this so easily, but that's less-to-do with Gutenberg and more with how WordPress as a whole allows admins to post content. 🤷‍♂️

Please re-open this though, if it was happening with a user role that shouldn't be allowed to post JS in text.

tofumatt avatar Nov 06 '18 10:11 tofumatt