-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
jQuery HTML parser corrupts script content that looks like HTML tags (including strings) #2668
Comments
Thanks for the report! This is related to (and a near-duplicate of) trac-14370 and trac-14464. It is possible to address on your end with |
Yes, 14370, but not 14464 (which is not a bug). Seems the fix for 14370 was considered too big. But it ought to be possible to exclude content within <script...</script> without too much more regex? |
Above should read 'content within <script...</script>' |
This is definitely unintended behavior, but screwing up this case isn't necessarily that bad. Putting executable scripts in HTML is something we'd love to remove, or at least make it much more difficult to do, because of its security implications. It's way too easy to inject attacker content that has scripts in it. For now I think we need to just reinforce the advice that it's bad practice, and use this example as one place where it fails. |
https://github.com/jquery/jquery/pull/1374/files#diff-169760a97de5c86a886842060321d2c8R44 , though I would probably update the first part per 85ffc6d and change the |
FWIW, the use case in which I found the issue was obfuscation of contact details using AJAX with JavaScript that converts sequences of apparently random characters back into the original human readable form. I don't see anything particularly bad practice about injecting content into the DOM that has come from a trusted source via AJAX and may by design contain script, more generally. However, I can't think of a good case, other than encryption, where such sequences in string literals being modified unexpectedly would be anything other than benign (e.g. if the AJAX-returned script also contains DOM manipulation code, So I would concur that adding something to the documentation 'Additional Notes' which begin "By design, any jQuery constructor or method that accepts an HTML string..." would resolve this ticket. Perhaps: "Also note that if the HTML contains script with string literals from cryptographic functions, unexpected results may occur, e.g. Something like this would have saved me several hours debugging, as I'd already scanned the docs and scoured t'internet to see if I might be missing something in the way But I don't know what to suggest as a workaround other than what's in the jsFiddle I've updated: http://jsfiddle.net/fwaoj0eh/3/, which is working fine in my case. (I haven't looked into whether things like |
From a Content Security Policy standpoint, it's very common to disable inline scripts as a policy because it's such a common attack vector. The problem is that is is really hard for most web developers to strongly assert that the content is from a trusted source. There are so many ways to mess that up.
Characters inside the |
On your first point, why [rhetorically] is Google search results page full of inline script? |
Not at all,
https://github.com/jquery/api.jquery.com/issues/new . Thanks! |
We will put together a |
Thanks all for your input on this issue. |
With functions like
.append(html)
,.repaceWith(html)
or even just$(html)
, ifhtml
contains javascript and some content of that script looks like an HTML tag, it will be modified undesirably.E.g.
<script type='text/javascript'>
alert('<What?/>');
</script>
when used as argument for .append() or suchlike produces "<What?></What>" in the alert when it should produce "<What?/>"
Example at http://jsfiddle.net/fwaoj0eh/2/ (where you can also see benign [in this case] replacement of
<p/>
with<p></p>
), with workaround (and possible route to fix?). Bug present in jQuery 1.11.3 on all Windows browsers tested (IE7-12, FF, Chrome, Safari, Opera).The text was updated successfully, but these errors were encountered: