<?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>21147</bug_id>
          
          <creation_ts>2013-02-27 16:40:45 +0000</creation_ts>
          <short_desc>WebSocket API could provide a method to get the HTTP response code when it&apos;s not 101</short_desc>
          <delta_ts>2013-03-04 19:57:45 +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>WebSocket API (editor: Ian Hickson)</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Iñaki Baz Castillo">ibc</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>annevk</cc>
    
    <cc>art.barstow</cc>
    
    <cc>brian.raymor</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>public-webapps</cc>
    
    <cc>toyoshim</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83811</commentid>
    <comment_count>0</comment_count>
    <who name="Iñaki Baz Castillo">ibc</who>
    <bug_when>2013-02-27 16:40:45 +0000</bug_when>
    <thetext>If the WebSocket connection fails due to a non 101 HTTP response code from the server, there is no way to know the exact HTTP code. This could be useful.

For example:

&lt;pre&gt;
var conn = new WebSocket(&quot;ws://non-a-websocket-server:80&quot;);

// Let&apos;s assume HTTP 400 is replied.

// This would print &quot;400&quot;:
console.log(conn.httpStatusCode);
&lt;/pre&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83837</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-28 18:45:58 +0000</bug_when>
    <thetext>Should that not be left to the developer console?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83838</commentid>
    <comment_count>2</comment_count>
    <who name="Iñaki Baz Castillo">ibc</who>
    <bug_when>2013-02-28 21:03:49 +0000</bug_when>
    <thetext>Well, the browser console already shows the HTTP status code of the non 101 response, but the JavaScript application can not get it.

What I consider useful is that the JS code can get the HTTP status code to inform the user (for example 403 could mean &quot;You are not authorized to connect to this WebSocket server&quot;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83918</commentid>
    <comment_count>3</comment_count>
    <who name="Takashi Toyoshima">toyoshim</who>
    <bug_when>2013-03-04 06:04:52 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; What I consider useful is that the JS code can get the HTTP status code to
&gt; inform the user (for example 403 could mean &quot;You are not authorized to
&gt; connect to this WebSocket server&quot;).

It might be useful, but at the same time, it means that a malicious script can attack an arbitrary HTTP page using HTTP auth by using WebSocket. From the viewpoint of security, I believe that we should not expose HTTP response code to JavaScript.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83922</commentid>
    <comment_count>4</comment_count>
    <who name="Iñaki Baz Castillo">ibc</who>
    <bug_when>2013-03-04 08:47:42 +0000</bug_when>
    <thetext>How could a malicious script attack an arbitrary HTTP page using HTTP auth by using WebSocket? The script cannot add the required Authorization or Proxy-Authorization header at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83923</commentid>
    <comment_count>5</comment_count>
    <who name="Takashi Toyoshima">toyoshim</who>
    <bug_when>2013-03-04 09:08:27 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; The script cannot add the required Authorization or
&gt; Proxy-Authorization header at all.

I missed the point. You are right.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83927</commentid>
    <comment_count>6</comment_count>
    <who name="Iñaki Baz Castillo">ibc</who>
    <bug_when>2013-03-04 09:54:06 +0000</bug_when>
    <thetext>I can imagine the following usecase:

- A website offers to visitors WebSocket access to a thirdy party provider (i.e. via the inclusion of JS code provided by the WS service).

- But the website has not payed to the WS provider during last months so its &quot;LICENSE_KEY&quot; is not valid anymore.

- The visitor tries to use the WS service. The JS code attempts a WS connection to &quot;ws://service-provider.net?LICENSE_KEY=qwuyt87qghe&quot; and gets a 403 &quot;Not Authorized&quot;.

- The JS code then shows it to the web user in a friendly way.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83957</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-03-04 19:57:45 +0000</bug_when>
    <thetext>That would be a bad way of doing things. If it&apos;s a WebSocket connection, use the WebSocket protocol to send back the error, not HTTP. WebSocket isn&apos;t really anything to de with HTTP, it just happens to be compatible for legacy reasons (to make it easier to use one port with both protocols).

We can&apos;t expose stuff from arbitrary cross-origin HTTP servers. It would let you do all kinds of things like intranet inspection, etc.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>