Closed Bug 352437 Opened 18 years ago Closed 12 years ago does not escape url


(Core :: JavaScript Engine, defect)

Not set





(Reporter: jruderman, Assigned: Ms2ger)



(Keywords: dev-doc-complete, sec-want, testcase, Whiteboard: [sg:want])


(3 files)

js> "foo".link("")
<a href="">foo</a>

In HTML, & in links needs to be escaped as &amp;
Assignee: general → jwalden+bmo
This is worse than I thought: the double-quote character (") isn't escaped either.  This caused an XSS hole in (bug 357750), where the developer assumed that was an API for creating a link from any link text and URL.  I think we should meet that assumption (rather than telling developers not to use or to escape or sanitize text passed to it), but we'd need to get other browser vendors to fix their implementations too for that problem to really go away.
Assignee: jwalden+bmo → general
As pointed out in bug 437618 the problem is not limited to .link(), it's all the HTML-helper string methods. e.g.

> javascript:"foo".anchor("hello\"><script>alert(1)</script>")
> javascript:"foo".fontcolor("hello\"><script>alert(1)</script>")
> javascript:"foo".fontsize("hello\"><script>alert(1)</script>")
> javascript:"foo".link("hello\"><script>alert(1)</script>")
Blocks: xss
Flags: wanted1.9.1?
Whiteboard: [sg:want]
It's not clear that we can fix this, but we'll mark it for investigation.
Flags: wanted1.9.1? → wanted1.9.1+
OS: Mac OS X → All
Hardware: Macintosh → All
Assignee: general → Ms2ger
Here’s a spec for the non-standard string extensions; an attempt to get
browsers to align their implementations:

It only requires escaping U+0022 QUOTATION MARK as &quot; (not U+0026
AMPERSAND as &amp;) — see note below for the reasoning behind this.


(In reply to Robert Sayre from comment #4)
> It's not clear that we can fix this, but we'll mark it for investigation.

Note that WebKit does escape U+0022 QUOTATION MARK as &quot;. It also escapes
U+0027 APOSTROPHE as &#039;, although that seems pointless. It doesn’t escape
U+0026 AMPERSAND, though. No browser does.

As it doesn’t seem to cause any compatibility problems for WebKit, it seems
possible to fix the &quot; issue. I’m afraid the &amp; “issue” is harder to
fix, as there’s no precedent.
I agree we shouldn't change &. There may be sites that "do the right thing" and escape both & and " before using these methods, that would break if we start escaping &. It also means it is harder for sites to plug their XSS hole for legacy browsers if new browsers start escaping &.

Escaping " seems like a good thing to do, IMHO.
My previous comment (comment 7) should’ve said V8 instead of WebKit.

For some reason I’m not allowed to add these URLs to the “See Also” list, so here goes:

* Safari/JavaScriptCore:
* IE/Chakra:
* Opera/Carakan: (DSK-369206/CORE-47348)
For nice code.
Attachment #639678 - Flags: review?(jorendorff)
For ever so slightly faster code
Attachment #639680 - Flags: review?(jorendorff)
For better conforming code.
Attachment #639681 - Flags: review?(jorendorff)
Comment on attachment 639680 [details] [diff] [review]
Part b: Get rid of some strlen() calls

We shouldn't optimize stuff like this. It's better to do the slow thing than to have the compiler spit out a dozen instantiations of a template.

If you really want to eliminate the strlen calls, make tagify_impl take beginLen and endLen as arguments (it can assert that those arguments are actually equal to strlen(begin) and strlen(end)), then make an inline function template that uses this trick to pass them in. Then measure the perf difference. This doesn't seem worth the effort to me though.
Attachment #639680 - Flags: review?(jorendorff)
Comment on attachment 639678 [details] [diff] [review]
Part a: Use StringBuffer

Review of attachment 639678 [details] [diff] [review]:

r=me with or without the changes.

::: js/src/jsstr.cpp
@@ +2791,1 @@
>          taglen += 2 + parlen + 1;                       /* '="param"' */

Feel free to eliminate the temporary entirely (and then the curly braces here).

@@ +2799,5 @@
>          return false;
> +
> +    sb.infallibleAppend('<');
> +
> +    MOZ_ALWAYS_TRUE(sb.appendInflated(begin, beglen));

Feel free to add methods to vm/StringBuffer.h:
    inline void infallibleAppendInflated(const char *cstr, size_t len);
    inline void infallibleAppend(JSLinearString *str);
that do this assertion.
Attachment #639678 - Flags: review?(jorendorff) → review+
Attachment #639681 - Flags: review?(jorendorff) → review+
Closed: 12 years ago
Keywords: dev-doc-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
Backed out with the mass tree revert to get rid of the OS X M5 orange:
Resolution: FIXED → ---
Closed: 12 years ago12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.