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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>17242</bug_id>
          
          <creation_ts>2012-05-30 07:28:04 +0000</creation_ts>
          <short_desc>Consider doing anonymous requests as a constructor argument rather than as a separate constructor</short_desc>
          <delta_ts>2012-10-11 09:52:16 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>XHR</component>
          <version>unspecified</version>
          <rep_platform>PC</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jonas Sicking (Not reading bugmail)">jonas</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>adrianba</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>mjs</cc>
    
    <cc>ojan</cc>
    
    <cc>public-webapps</cc>
    
    <cc>travil</cc>
    
    <cc>w3c</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>68296</commentid>
    <comment_count>0</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-05-30 07:28:04 +0000</bug_when>
    <thetext>I propose that we do anonymous requests using something like:

new XMLHttpRequest({ anon: true });

rather than the current

new AnonXMLHttpRequest();


That way we can more easily add other &quot;constructors&quot; which affect the security model that an XHR object uses.

For example, in B2G we are adding the ability for apps to get permission to get low-level network access and do things like open raw sockets. As a convenience, we&apos;d also like to expose the XMLHttpRequest API since that exposes no additional functionality but is a much easier to use API. In that scenario we need the ability to instantiate an XHR object which never sends cookies, but also is allowed to make network requests cross site without relying on CORS.

See https://bugzilla.mozilla.org/show_bug.cgi?id=692677#c39</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68301</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-05-30 08:51:00 +0000</bug_when>
    <thetext>Nobody has implemented AnonXMLHttpRequest to my knowledge. So the first question should be whether we want to have it at all I think.

Then, secondly, if we add an object to initialize XMLHttpRequest, maybe we should give that &quot;url&quot;, &quot;method&quot;, ... parameters?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68331</commentid>
    <comment_count>2</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-05-30 23:07:27 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Nobody has implemented AnonXMLHttpRequest to my knowledge. So the first
&gt; question should be whether we want to have it at all I think.

I don&apos;t feel strongly either way, but I don&apos;t see a rush to drop it either. Is keeping it in a lot of maintenance work for the spec? I&apos;m a little bummed/annoyed none of the proponents of this stepped up to implement it given how strongly they fought for it.

&gt; Then, secondly, if we add an object to initialize XMLHttpRequest, maybe we
&gt; should give that &quot;url&quot;, &quot;method&quot;, ... parameters?

Yes, that would be great.

I have a minor aesthetic preference for the initialization object over the new constructor, and while we&apos;re at it, a mild preference for naming the property &quot;anonymous&quot; instead of &quot;anon&quot;. I don&apos;t think this is a case where shortness will have much impact on the convenience or uptake of the API (unlike, e.g. querySelector --&gt; find).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68379</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-05-31 09:02:39 +0000</bug_when>
    <thetext>I&apos;m not really sure what it means to do:

x = new XMLHttpRequest({ url: &quot;...&quot; });

Does that mean you don&apos;t have to call .open on such an XHR object? If so, does that mean that you can only use it for one request?

I&apos;m not necessarily against such a design, I&apos;m just trying to understand what is proposed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68380</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-05-31 09:05:52 +0000</bug_when>
    <thetext>The idea would be that you can avoid invoking open() indeed. Maybe even send(). So it would work just like EventSource. You just pass the information to the constructor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68381</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-05-31 09:06:53 +0000</bug_when>
    <thetext>Not sure whether we should restrict invoking open() on such instances though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68473</commentid>
    <comment_count>6</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-06-01 05:16:46 +0000</bug_when>
    <thetext>Hope I&apos;m beating a dead horse since I know this has been discussed before, but we could forego XHR entirely and just create a new class that doesn&apos;t have any of the baggage where there are no invalid states that need errors thrown (only invalid combinations of options, e.g. data + method=GET).

HttpRequest(url, options) or even just Request(url, options), in theory the latter is future-compatible should we want to support protocols other than http.

The only method it has is abort.

&quot;options&quot; allows the following properties: anonymous, on* (e.g. onloadstart, etc), method, headers, asBinary, responseType, timeoutMS, withCredentials, data. Should it have username/password? Obviously, no way to do sync requests.

An HttpRequest instance has the following properties: status, statusText, response, responseHeaders.

headers/responseHeaders is a dictionary. I think the rest are self-explanatory. Not really sure how the upload related stuff would fit in here. I suppose you could have onupload* events on the options dictionary.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68474</commentid>
    <comment_count>7</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-06-01 05:17:13 +0000</bug_when>
    <thetext>Lol. That is to say, hope I&apos;m *not* beating a dead horse.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75687</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-09 14:54:13 +0000</bug_when>
    <thetext>So yeah, that is a dead horse. We try to avoid introducing new APIs that does largely the same thing, because the costs (implementation, tests, potential for even more divergence) outweigh the benefit.

So far however there does not appear to be much interest in AnonXMLHttpRequest at all. I marked it as such in the specification: http://xhr.spec.whatwg.org/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75758</commentid>
    <comment_count>9</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-10-10 00:23:12 +0000</bug_when>
    <thetext>FWIW, we&apos;ve experimentally added the proposal in comment 0 to Firefox 16 which was released earlier today. Feel free to test it!

There&apos;s a know bug where explicitly set username/passwords aren&apos;t sent for anonymous requests. This should be fixed in Firefox 18.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75814</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-10 10:42:54 +0000</bug_when>
    <thetext>I tried both anon:true and anonymous:true and in both I can set withCredentials to true, so if you implemented anonymous mode, it&apos;s buggy. You did not like the suggestion of spelling it out (Ojan suggested anonymous) since it&apos;s an object member? I think that would be better.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75815</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-10 10:44:48 +0000</bug_when>
    <thetext>Username and password are supposed to throw in anonymous mode too by the way. Are you guys even reading the specification when implementing or just doing willy nilly and then telling us later? This has happened a few times now, I don&apos;t really like it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75893</commentid>
    <comment_count>12</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-10-10 22:19:06 +0000</bug_when>
    <thetext>There&apos;s a reason I said experimental.

Why should anonymous requests throw for explicitly specified username/passwd?

While setting .withCredentials to true doesn&apos;t throw, it should still not be adding any credentials I&apos;d hope.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75930</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-11 03:54:24 +0000</bug_when>
    <thetext>Because when you start including username/password, they&apos;re no longer anonymous. However, we similarly forbid username/password for cross-origin requests, and maybe we should start allowing that again too, as it will require a preflight request for the Authorization header anyway.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75938</commentid>
    <comment_count>14</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-10-11 06:00:50 +0000</bug_when>
    <thetext>I&apos;ve always thought &quot;anonymous&quot; as meaning &quot;UA won&apos;t add user identifying information&quot;.

There&apos;s no way we can make &quot;anonymous&quot; requests meaning &quot;no user identifying information will be included&quot; since the page can add user identifying information in the URL or in the headers. Indeed, this is quite common I believe when making &quot;anonymous&quot; cross-site requests.


With regards to &quot;anon&quot; vs. &quot;anonymous&quot; I feel like one of the most common complaints we get from JS authors is too long and inconvenient names.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75945</commentid>
    <comment_count>15</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-11 07:23:03 +0000</bug_when>
    <thetext>https://github.com/whatwg/xhr/commit/d43a3637bf99933df33712d14dc8fdef7a29bea7
http://xhr.spec.whatwg.org/

I&apos;ll look into fixing comment 13 and comment 14 a little later.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75954</commentid>
    <comment_count>16</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-11 09:52:16 +0000</bug_when>
    <thetext>https://github.com/whatwg/xhr/commit/08fb7d6b1d0d28116710e9db231e709b3890fca3
http://xhr.spec.whatwg.org/

Now everything should be in order. You can always use the user/password arguments as the dictionary attack is fiction. After all, the server needs to opt in to the Authorization header.

This commit also cleans up how the user/password arguments are defined in IDL and prose.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>