does not escape url

RESOLVED FIXED in mozilla17



13 years ago
7 years ago


(Reporter: jruderman, Assigned: Ms2ger)


({dev-doc-complete, sec-want, testcase})

Dependency tree / graph
Bug Flags:
wanted1.9.1 +

Firefox Tracking Flags

(Not tracked)


(Whiteboard: [sg:want])


(3 attachments)



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

In HTML, & in links needs to be escaped as &amp;
Assignee: general → jwalden+bmo

Comment 1

13 years ago
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.


11 years ago
Assignee: jwalden+bmo → general


11 years ago
Duplicate of this bug: 437618
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]

Comment 4

11 years ago
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


10 years ago
Duplicate of this bug: 536837
Duplicate of this bug: 649818


7 years ago
Assignee: general → Ms2ger

Comment 7

7 years ago
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.

Comment 8

7 years ago
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.

Comment 9

7 years ago
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+
Last Resolved: 7 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 → ---
Last Resolved: 7 years ago7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.