<?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>61007</bug_id>
          
          <creation_ts>2011-05-17 17:46:59 -0700</creation_ts>
          <short_desc>Allow custom schemes to use XMLHttpRequest</short_desc>
          <delta_ts>2025-01-09 10:11:44 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>XML</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>UNCONFIRMED</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=117313</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Joe Andrieu">joe</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>magreenblatt</cc>
    
    <cc>syoichi</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>405426</commentid>
    <comment_count>0</comment_count>
      <attachid>93852</attachid>
    <who name="Joe Andrieu">joe</who>
    <bug_when>2011-05-17 17:46:59 -0700</bug_when>
    <thetext>Created attachment 93852
Patch to DocumentThreadableLoader to allow custom schemes to use XMLHttpRequest

FWIW, I&apos;m using Chromium Embedded Framework, with WebKit v534.28.

Currently, URLs with custom schemes don&apos;t work with XMLHttpRequest, even with CORS supported by the scheme handler.

DocumentThreadableLoader::makeSimpleCrossOriginAccessRequest in documentthreadableloader.cpp fails because &quot;Cross origin requests are only defined for http&quot; (comment in the code) This is enforced by testing protocolInHTTPFamily().

makeSimpleCrossOriginAccessRequest is called because in the DocumentThreadableLoader constructor, cross origin requests are handled as simple, unless
1. forcePreFlight is set as an option
2. isSimpleCrossOrigianAccessRequest fails

Unfortunately, because isSimpleCrossOriginAccessRequest only uses the method and the header fields as input, it can&apos;t tell if the URL has a custom scheme.  The result is that custom schemes get treated along with &quot;SimpleCrossOriginAccessRequests&quot;, and subsequently fail the protocolInHTTPFamily() test in makeSimpleCrossOriginAccessRequest.

I&apos;d like to suggest that custom schemes are /not/ &quot;simple&quot;. In fact, if CORS is to be used with custom schemes, custom schemes must not be treated as simple in order for the preflight be triggered (although I guess I&apos;m not sure if preflight is actually required).

Considerations:
1. The easiest solution is to just add a test for protocolInHTTPFamily before calling makeSimpleCrossOriginAccessRequest. 

2. Alternatively, one could change the signature of isSimpleCrossOriginAccessRequest to pass the request and let the method check if it is a custom scheme as part of its determination.  This is probably a cleaner solution from a code maintenance standpoint, but requires changing more code now.

3. Because of potential security risks from scheme handlers that had counted on webkit to prevent any access via AJAX, perhaps we need a more robust solution. One suggestion: a registration method so that schemes can pro-actively elect to have CORS mediate requests.

I&apos;ve attached a patch for option #1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405428</commentid>
    <comment_count>1</comment_count>
      <attachid>93852</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-05-17 17:59:42 -0700</bug_when>
    <thetext>Comment on attachment 93852
Patch to DocumentThreadableLoader to allow custom schemes to use XMLHttpRequest

This needs a ChangeLog and a test, at least.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>409278</commentid>
    <comment_count>2</comment_count>
    <who name="Marshall Greenblatt">magreenblatt</who>
    <bug_when>2011-05-24 15:52:52 -0700</bug_when>
    <thetext>As an alternative approach we could do the following:

1. Add support in googleurl/src/url_util.h for registering schemes that should be treated as HTTP protocol handlers (AddHttpProtocolScheme, IsHttpProtocol). This would be similar to the existing support for registering standard protocols.

2. Change KURLGooglePrivate::initProtocolIsInHTTPFamily() to call the new url_util::IsHttpProtocol() method instead of only checking for hard-coded &quot;HTTP&quot; and &quot;HTTPS&quot; values.

This approach has the following advantages:

A. The change only affects Chromium-based clients.

B. The user must explicitly indicate that a custom scheme should be treated as an HTTP protocol handler by calling url_util::AddHttpProtocolScheme(). This addresses the concern that existing scheme handlers will see behavior changes.

C. All behavior that is currently HTTP-specific (call sites using protocolInHTTPFamily) will now recognize the new scheme with no additional changes required.

What do you think?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>409693</commentid>
    <comment_count>3</comment_count>
    <who name="Marshall Greenblatt">magreenblatt</who>
    <bug_when>2011-05-25 09:40:28 -0700</bug_when>
    <thetext>An implementation for comment#2 is available here:
http://code.google.com/p/chromiumembedded/issues/detail?id=246

I&apos;m not exactly sure how to pursue getting this committed since it spans both googleurl and webkit projects. Suggestions are welcome.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>411502</commentid>
    <comment_count>4</comment_count>
    <who name="Marshall Greenblatt">magreenblatt</who>
    <bug_when>2011-05-27 09:40:19 -0700</bug_when>
    <thetext>It was explained to me off-list that this bug is to allow custom /non-standard/ schemes to execute cross-origin XHR. Please ignore my comments #2-3 above, I was able to implement what I needed for custom /standard/ schemes by using the origin whitelist capabilities in WebSecurityPolicy.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>411536</commentid>
    <comment_count>5</comment_count>
    <who name="Joe Andrieu">joe</who>
    <bug_when>2011-05-27 10:47:06 -0700</bug_when>
    <thetext>Actually, Marshall, I think your fix may also allow non-standard schemes, as WebSecurityPolicy should support sources without hosts.  

I&apos;ll try out the Cef revision and let you know if it works for my case.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>93852</attachid>
            <date>2011-05-17 17:46:59 -0700</date>
            <delta_ts>2011-05-17 17:59:42 -0700</delta_ts>
            <desc>Patch to DocumentThreadableLoader to allow custom schemes to use XMLHttpRequest</desc>
            <filename>DocumentThreadableLoader.customSchemeAJAX.patch</filename>
            <type>text/plain</type>
            <size>813</size>
            <attacher name="Joe Andrieu">joe</attacher>
            
              <data encoding="base64">SW5kZXg6IERvY3VtZW50VGhyZWFkYWJsZUxvYWRlci5jcHANCj09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0NCi0tLSBEb2N1
bWVudFRocmVhZGFibGVMb2FkZXIuY3BwCShyZXZpc2lvbiA4MjgyNykNCisrKyBEb2N1bWVudFRo
cmVhZGFibGVMb2FkZXIuY3BwCSh3b3JraW5nIGNvcHkpDQpAQCAtOTIsNyArOTIsOCBAQA0KICAg
ICBjcm9zc09yaWdpblJlcXVlc3QtPnJlbW92ZUNyZWRlbnRpYWxzKCk7CiAgICAgY3Jvc3NPcmln
aW5SZXF1ZXN0LT5zZXRBbGxvd0Nvb2tpZXMobV9vcHRpb25zLmFsbG93Q3JlZGVudGlhbHMpOwog
Ci0gICAgaWYgKCFtX29wdGlvbnMuZm9yY2VQcmVmbGlnaHQgJiYgaXNTaW1wbGVDcm9zc09yaWdp
bkFjY2Vzc1JlcXVlc3QoY3Jvc3NPcmlnaW5SZXF1ZXN0LT5odHRwTWV0aG9kKCksIGNyb3NzT3Jp
Z2luUmVxdWVzdC0+aHR0cEhlYWRlckZpZWxkcygpKSkKKyAgICBpZiAoIW1fb3B0aW9ucy5mb3Jj
ZVByZWZsaWdodCAmJiBpc1NpbXBsZUNyb3NzT3JpZ2luQWNjZXNzUmVxdWVzdChjcm9zc09yaWdp
blJlcXVlc3QtPmh0dHBNZXRob2QoKSwgY3Jvc3NPcmlnaW5SZXF1ZXN0LT5odHRwSGVhZGVyRmll
bGRzKCkpCisJCSYmIHJlcXVlc3QudXJsKCkucHJvdG9jb2xJbkhUVFBGYW1pbHkoKSkKICAgICAg
ICAgbWFrZVNpbXBsZUNyb3NzT3JpZ2luQWNjZXNzUmVxdWVzdCgqY3Jvc3NPcmlnaW5SZXF1ZXN0
KTsKICAgICBlbHNlIHsKICAgICAgICAgbV9hY3R1YWxSZXF1ZXN0ID0gY3Jvc3NPcmlnaW5SZXF1
ZXN0LnJlbGVhc2UoKTsK
</data>
<flag name="review"
          id="87082"
          type_id="1"
          status="-"
          setter="abarth"
    />
          </attachment>
      

    </bug>

</bugzilla>