<?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>27150</bug_id>
          
          <creation_ts>2014-10-24 04:15:35 +0000</creation_ts>
          <short_desc>CORS preflight flag handling in the HTTP fetch algorithm doesn&apos;t look right</short_desc>
          <delta_ts>2014-10-29 05:32:40 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>Fetch</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</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>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Takeshi Yoshino">tyoshino</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>mike</cc>
          
          <qa_contact>sideshowbarker+fetchspec</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>113684</commentid>
    <comment_count>0</comment_count>
    <who name="Takeshi Yoshino">tyoshino</who>
    <bug_when>2014-10-24 04:15:35 +0000</bug_when>
    <thetext>In the substep 1 of the step 3 (handling CORS preflight flag),

It looks that this step is saying that if all of the first 4 lines at the top (including &quot;the CORS preflight flag is set&quot;) are met, we must run the CORS preflight fetch.

But looking at the last 2 substeps,

----

- either request&apos;s method is a not simple method or request&apos;s mode is CORS-with-forced-preflight, and

- there is at least one header name in request&apos;s header list for which there is no header name cache match using request and for which the header is not a simple header

----

it looks wrong that these two conditions (bullet points) are concatenated with AND.

I guess CORS-with-forced-preflight check, method check, and header check should be concatenated with OR.

Suggested rewrite:

If the CORS preflight flag is set and
- request&apos;s mode is CORS-with-forced-preflight, or
- there is no method cache match for request&apos;s method using request and request&apos;s method is not a simple method, or
- there is at least one header name in request&apos;s header list for which there is no header name cache match using request and which is not a simple header</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113704</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-24 15:21:45 +0000</bug_when>
    <thetext>That proposal does not work. Even if mode is CORS-with-forced-preflight, if there&apos;s a cache match there&apos;s no need to do a preflight.

My proposal:

If the /CORS preflight flag/ is set and one of these conditions is true:

* There is no method cache match for request&apos;s method using request and either request&apos;s method is a not simple method or request&apos;s mode is CORS-with-forced-preflight.

* There is at least one header name in request&apos;s header list for which there is no header name cache match using request and for which the header is not a simple header.

Then preflight...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113713</commentid>
    <comment_count>2</comment_count>
    <who name="Takeshi Yoshino">tyoshino</who>
    <bug_when>2014-10-24 16:42:22 +0000</bug_when>
    <thetext>(In reply to Anne from comment #1)
&gt; That proposal does not work. Even if mode is CORS-with-forced-preflight, if
&gt; there&apos;s a cache match there&apos;s no need to do a preflight.

I see!

&gt; My proposal:
&gt; 
&gt; If the /CORS preflight flag/ is set and one of these conditions is true:
&gt; 
&gt; * There is no method cache match for request&apos;s method using request and
&gt; either request&apos;s method is a not simple method or request&apos;s mode is
&gt; CORS-with-forced-preflight.
&gt; 
&gt; * There is at least one header name in request&apos;s header list for which there
&gt; is no header name cache match using request and for which the header is not
&gt; a simple header.

(The same about the current text, but) I couldn&apos;t parse the second &quot;for which&quot;. So, I rewrote it to &quot;and which is not a simple header&quot;.

&gt; 
&gt; Then preflight...

OK. But I wonder if it works correctly for the following case,
- method cache match (therefore, the first bullet point is false)
- there&apos;re a simple headers with no header cache match
This happens when e.g. a server builds the Access-Control-Allow-Headers header by scanning the items listed in received Access-Control-Request-Headers and returning only allowed ones of them.


--- Request 1 ---

GET / HTTP/1.1

HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, HEAD
Access-Control-Allow-Headers: 
...

--- Request 2 ---

POST / HTTP/1.1
Content-Type: text/plain


Here, the two bullet points are both false even if CORS-with-forced-preflight is set.


Memo:
Force preflight was introduced on this revision.
http://dev.w3.org/cvsweb/2006/waf/access-control/Overview.src.html#rev1.196
The thread led to the change:
http://lists.w3.org/Archives/Public/public-webapps/2008JulSep/0069.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113785</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-27 17:10:27 +0000</bug_when>
    <thetext>If there is a method cache match we already know the server is okay with CORS and we do not have to check again. In that case we only have to check for headers and such.

The forced-preflight bit is about minimizing exposure of a server that might be unaware of CORS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113786</commentid>
    <comment_count>4</comment_count>
    <who name="Takeshi Yoshino">tyoshino</who>
    <bug_when>2014-10-27 17:14:11 +0000</bug_when>
    <thetext>(In reply to Anne from comment #3)
&gt; If there is a method cache match we already know the server is okay with
&gt; CORS and we do not have to check again. In that case we only have to check
&gt; for headers and such.
&gt; 
&gt; The forced-preflight bit is about minimizing exposure of a server that might
&gt; be unaware of CORS.

OK. Then, the fix looks good.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113832</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-28 14:02:13 +0000</bug_when>
    <thetext>Thanks.

https://github.com/whatwg/fetch/commit/5f6b29fc82dff98aed4fc5ad71d2bcf4713e32f1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114202</commentid>
    <comment_count>6</comment_count>
    <who name="Takeshi Yoshino">tyoshino</who>
    <bug_when>2014-10-29 05:32:40 +0000</bug_when>
    <thetext>Thanks. The commit looks good.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>