<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>30241</bug_id>
          
          <creation_ts>2009-10-08 17:12:32 -0700</creation_ts>
          <short_desc>Inconsistent URL encoding/decoding of JavaScript URLs.</short_desc>
          <delta_ts>2011-08-19 13:39:15 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>37641</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Bates">dbates</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>153577</commentid>
    <comment_count>0</comment_count>
      <attachid>40919</attachid>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2009-10-08 17:12:32 -0700</bug_when>
    <thetext>Created attachment 40919
Example

JavaScript URLs that are URL encoded via FrameLoader::completeURL are not properly decoded before eventually being passed to both the XSSAuditor and ScriptController::evaluate, because the method KURL::decodeURLEscapeSequences is NOT the inverse function of KURL::parse().

In particular, this occurs in FrameLoader::requestFrame:
http://trac.webkit.org/browser/trunk/WebCore/loader/FrameLoader.cpp#L348
where the completeURL() is called on |scriptURL| before it is passed to frame-&gt;loader()-&gt;executeIfJavaScriptURL().

Remarks:
The call flow of FrameLoader::completeURL is:
FrameLoader::completeURL -&gt; Document::completeURL -&gt; KURL::KURL(const KURL&amp; base, const String&amp; relative, ...) -&gt; KURL::init - &gt; KURL::parse

The issue is that KURL::parse uses the method KURL::appendEscapingBadChars, which as its name implies escapes only bad characters.

One such bad character is the space character. Consider the JavaScript URL, &quot;javascript: &apos;%0A&apos;&quot; (*). Calling KURL::parse on this (directly or implicitly via one of the functions in the above call chain) will result in a KURL object that represents the URL, &quot;javascript:%20&apos;%46&apos;&quot; (**). Notice, this result differs from the fully URL encoded result of &quot;javascript:%20%27%2546%27&quot;. Decoding the string form of (**) using KURL::decodeURLEscapeSequences produces the result: &quot;javascript: &apos;F&apos;&quot;. Clearly, this is not the inverse of the (**).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>153580</commentid>
    <comment_count>1</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2009-10-08 17:21:22 -0700</bug_when>
    <thetext>(*) should be &quot;javascript: &apos;%46&apos;&quot;

(In reply to comment #0)
&gt; Created an attachment (id=40919) [details]
&gt; Example
&gt; 
&gt; JavaScript URLs that are URL encoded via FrameLoader::completeURL are not
&gt; properly decoded before eventually being passed to both the XSSAuditor and
&gt; ScriptController::evaluate, because the method KURL::decodeURLEscapeSequences
&gt; is NOT the inverse function of KURL::parse().
&gt; 
&gt; In particular, this occurs in FrameLoader::requestFrame:
&gt; http://trac.webkit.org/browser/trunk/WebCore/loader/FrameLoader.cpp#L348
&gt; where the completeURL() is called on |scriptURL| before it is passed to
&gt; frame-&gt;loader()-&gt;executeIfJavaScriptURL().
&gt; 
&gt; Remarks:
&gt; The call flow of FrameLoader::completeURL is:
&gt; FrameLoader::completeURL -&gt; Document::completeURL -&gt; KURL::KURL(const KURL&amp;
&gt; base, const String&amp; relative, ...) -&gt; KURL::init - &gt; KURL::parse
&gt; 
&gt; The issue is that KURL::parse uses the method KURL::appendEscapingBadChars,
&gt; which as its name implies escapes only bad characters.
&gt; 
&gt; One such bad character is the space character. Consider the JavaScript URL,
&gt; &quot;javascript: &apos;%0A&apos;&quot; (*). Calling KURL::parse on this (directly or implicitly
&gt; via one of the functions in the above call chain) will result in a KURL object
&gt; that represents the URL, &quot;javascript:%20&apos;%46&apos;&quot; (**). Notice, this result
&gt; differs from the fully URL encoded result of &quot;javascript:%20%27%2546%27&quot;.
&gt; Decoding the string form of (**) using KURL::decodeURLEscapeSequences produces
&gt; the result: &quot;javascript: &apos;F&apos;&quot;. Clearly, this is not the inverse of the (**).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>454040</commentid>
    <comment_count>2</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-08-19 13:39:15 -0700</bug_when>
    <thetext>This bug is fixed in the new architecture.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>40919</attachid>
            <date>2009-10-08 17:12:32 -0700</date>
            <delta_ts>2009-10-08 17:12:32 -0700</delta_ts>
            <desc>Example</desc>
            <filename>KURL-parse-bug.html</filename>
            <type>text/html</type>
            <size>698</size>
            <attacher name="Daniel Bates">dbates</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8L2hlYWQ+Cjxib2R5Pgo8cD5UaGlzIHRlc3QgY2FuIGJlIHVzZWQgdG8g
ZGVtb25zdHJhdGUgdGhlIFVSTCBlbmNvZGluZyBidWcgaW4gS1VSTDo6cGFyc2UuIE1ha2Ugc3Vy
ZSB0aGUgc3RhdHVzIGJhciBvZiB0aGlzIGJyb3dzZXIgd2luZG93IGlzIHZpc2libGUuIElmIG5v
dCwgc2VsZWN0IFZpZXctPlNob3cgU3RhdHVzIEJhci48L3A+CjxhIGhyZWY9ImphdmFzY3JpcHQ6
YWxlcnQoJ2EgJTI1NDYnKSI+SG92ZXIgb3ZlciB0aGlzIGxpbmsgYW5kIGxvb2sgYXQgdGhlIHN0
YXR1cyBiYXI8L2E+CjxwPigqKSBZb3Ugd2lsbCBzZWUgdGhlIHRleHQ6IFJ1biBzY3JpcHQgJnF1
b3Q7YWxlcnQoJ2ElMjAlMjU0NicpJnF1b3Q7PC9wPgo8cD5WaWV3IHRoZSBzb3VyY2UgY29kZSBv
ZiB0aGlzIHBhZ2UsIGxvb2tpbmcgYXQgdGhlIHRoZSBocmVmIHByb3BlcnR5IG9mIHRoZSBhYm92
ZSBsaW5rIGl0IHJlYWRzOiBqYXZhc2NyaXB0OmFsZXJ0KCdhICUyNTQ2Jyk8L3A+CjxwPk5vdGlj
ZSB0aGUgc3BhY2UgY2hhcmFjdGVyIChsb2NhdGVkIGJldHdlZW4gdGhlICdhJyBhbmQgdGhlICcl
JyBjaGFyYWN0ZXIgaW4gdGhlIGhyZWYgcHJvcGVydHkgc3RyaW5nKSBpcyBlbmNvZGVkIHRvICUy
MCBpbiAoKikuIEJ1dCwgdGhlICclMjUnIGlzIE5PVCBlbmNvZGVkIHRvICclMjUyNScuPC9wPgo8
L2JvZHk+CjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>