Opened 11 years ago
Closed 10 years ago
#11290 closed bug (fixed)
selector interpreted as HTML
Reported by: | gibson042 | Owned by: | Timmy Willison |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9 |
Component: | core | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
#9521 and #6429 and probably others identify specific instances of a general problem: jQuery( strInput )
cannot reliably differentiate selectors from HTML.
Looking for "<" past the first character creates vulnerabilities and confusing behavior on complex input.
quickExpr
should be abandoned in favor of a simpler "parse as HTML if and only if there is a leading less-than" rule, with intentional parsing handled by the jQuery( "<div/>" ).html( strHtml ).contents()
pattern.
Change History (19)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Component: | unfiled → core |
---|---|
Milestone: | None → 1.8 |
Priority: | undecided → blocker |
Status: | new → open |
comment:3 Changed 11 years ago by
Owner: | set to Timmy Willison |
---|---|
Status: | open → assigned |
comment:4 Changed 11 years ago by
As http://bugs.jquery.com/ticket/9521#comment:24 points out, a simple "starts with <" rule will break some unit tests and is likely to cause issues in outside code. However, I think we should be willing to do that here for at least some cases.
The only issue I'm on the fence about is whether to trim leading spaces. I can imagine situations where people may have templates that end up with leading spaces, but then again it seems expensive to always pass the string through a regexp to remove them for the handful of sloppy cases that could be resolved by using $.trim()
externally.
If people *want* to parse arbitrary complex HTML and they know it's HTML, we should encourage them to use the new $.parseHTML
method per #11617. It would be best if $(html)
didn't execute scripts for example.
comment:5 Changed 11 years ago by
Given that we'll be providing jQuery.parseHTML
for explicit HTML parsing, I'd like to be as strict as possible in jQuery
.
comment:6 Changed 11 years ago by
It is possible to adjust the regex to avoid matching html when it is within brackets, parens, or quotes, as well as ignoring any escaped html characters. This would fix the case presented in this ticket as well as jQuery mobile's, @jdalton's and @mathias' issue in #9521. The other issue in #9521 is that there is a xss vulnerability when unexpected input is passed to jQuery()
. I think it is safe to say that is much lower priority, but that would also be fixed by specifying that if some selector contains characters normally recognized as html, they should be escaped. This would resolve all of the issues and be backwards-compatible, unless I've missed a case.
comment:7 Changed 11 years ago by
I've implemented what I meant and adjusted the regex so we maintain backwards-compatibility as well as restrict the unexpected behaviors from occurring. This will fix most issues. Patch incoming.
comment:8 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
When detecting html in init, ignore html characters within quotes, brackets, and parens as well as escaped characters which are valid in selectors. Fixes #11290.
Changeset: 7692ae419d4c19bd06a0ba01fc2af8d21035873c
comment:9 Changed 11 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Now it's gone too far the other way... http://jsfiddle.net/HCa89/1/
comment:10 Changed 11 years ago by
Having discussed it with gibson and Dave, we're adopting a different strategy (the starts-with rule). While ignoring html within quotes, brackets, and parens could have worked, I agree it would have come at too great a cost. Commit incoming.
comment:11 Changed 11 years ago by
Status: | reopened → assigned |
---|
comment:12 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Adjust jQuery('html') detection to only match when html starts with '<' (counting space characters). Fixes #11290
Changeset: 239fc86b01d52fd9df6d1963027ed37b4f6251fc
comment:13 Changed 11 years ago by
Revert "Adjust jQuery('html') detection to only match when html starts with '<' (counting space characters). Fixes #11290"
This reverts commit 239fc86b01d52fd9df6d1963027ed37b4f6251fc.
The consensus is that this would change behavior too abruptly. We will warn in 1.8 and do this in 1.9.
Changeset: c20e031058c6210a1ed753f75af80588f076d60d
comment:14 Changed 11 years ago by
Milestone: | 1.8 → 1.9 |
---|
comment:15 Changed 11 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:16 Changed 11 years ago by
Status: | reopened → open |
---|
comment:19 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Adjust jQuery('html') detection to only match when html starts with '<' (not counting space characters). Fixes #11290.
Changeset: 05531fc4080ae24070930d15ae0cea7ae056457d
Also (for reference), CSS lexical tokenization: