Changeset 52478 in webkit


Ignore:
Timestamp:
Dec 21, 2009 8:47:46 PM (14 years ago)
Author:
ukai@chromium.org
Message:

2009-12-21 Fumitoshi Ukai <ukai@chromium.org>

Reviewed by Alexey Proskuryakov.

Invalid url should raise SYNTAX_ERR exception.
https://bugs.webkit.org/show_bug.cgi?id=32700

  • websocket/tests/bad-sub-protocol-expected.txt: add CONSOLE MESSAGEs
  • websocket/tests/script-tests/url-parsing.js: add invalid url tests. Also changed url from ws://127.0.0.1/ to ws://127.0.0.1:8880/websocket/tests/simple to make it sure no errors on console message for these tests by not receiving unexpected response from 127.0.0.1:80
  • websocket/tests/url-parsing-expected.txt:

2009-12-21 Fumitoshi Ukai <ukai@chromium.org>

Reviewed by Alexey Proskuryakov.

Invalid url should raise SYNTAX_ERR exception.
https://bugs.webkit.org/show_bug.cgi?id=32700

Check url is valid in WebSocket::connect.
Also log the detailed reason of websocket failures to console.

  • websockets/WebSocket.cpp: (WebCore::encodeProtocolString): (WebCore::WebSocket::connect):
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r52477 r52478  
     12009-12-21  Fumitoshi Ukai  <ukai@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Invalid url should raise SYNTAX_ERR exception.
     6        https://bugs.webkit.org/show_bug.cgi?id=32700
     7
     8        * websocket/tests/bad-sub-protocol-expected.txt: add CONSOLE MESSAGEs
     9        * websocket/tests/script-tests/url-parsing.js: add invalid url tests.
     10          Also changed url from ws://127.0.0.1/ to ws://127.0.0.1:8880/websocket/tests/simple to make it sure no errors on console message for these tests by not receiving unexpected response from 127.0.0.1:80
     11        * websocket/tests/url-parsing-expected.txt:
     12
    1132009-12-21  Dirk Pranke  <dpranke@chromium.org>
    214
  • trunk/LayoutTests/websocket/tests/bad-sub-protocol-expected.txt

    r52402 r52478  
     1CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket ''
     2CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0000'
     3CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0009'
     4CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u001B'
     5CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u007F'
     6CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0080'
     7CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u3042'
     8CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFF'
     9CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket ''
     10CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFE'
     11CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uD840\uDC0B'
    112Test WebSocket bad sub-protocol names.
    213
  • trunk/LayoutTests/websocket/tests/script-tests/url-parsing.js

    r52402 r52478  
    11description("Test WebSocket URL parsing.");
     2
     3// Invalid url will fail to be parsed.
     4shouldThrow('new WebSocket("ws://javascript:a")');
    25
    36// Can't use relative URLs - because spec says so, and because the scheme is different anyway.
    47shouldThrow('new WebSocket("/applet")');
    58
     9// Non ws URL is not allowed.
     10shouldThrow('new WebSocket("javascript:a")');
     11
    612// UA is allowed to block access to some ports, which we do.
    713shouldThrow('new WebSocket("ws://127.0.0.1:25/")');
    814
    9 // This is what we currently do, but not what the spec says (as of Editor's Draft 1 December 2009).
    10 shouldBe('(new WebSocket("ws://127.0.0.1/a/../")).URL', '"ws://127.0.0.1/"');
    11 
    12 shouldBe('(new WebSocket("ws://127.0.0.1/path?")).URL', '"ws://127.0.0.1/path?"');
    13 shouldBe('(new WebSocket("ws://127.0.0.1/path?k=v")).URL', '"ws://127.0.0.1/path?k=v"');
     15// Resolve the url string using the resolve a Web address algorithm.
     16// Use 127.0.0.1:8880 and existing ws handler to make sure we don't receive unexpected response (so no console message appears)
     17shouldBe('(new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/simple")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple"');
     18shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple?"');
     19shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?k=v")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple?k=v"');
    1420
    1521// draft-hixie-thewebsocketprotocol-60 says If /url/ has a <fragment>
  • trunk/LayoutTests/websocket/tests/url-parsing-expected.txt

    r52402 r52478  
     1CONSOLE MESSAGE: line 0: Invalid url for WebSocket ws://javascript:a
     2CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket http://127.0.0.1:8880/applet
     3CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket javascript:a
     4CONSOLE MESSAGE: line 0: WebSocket port 25 blocked
     5CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path#
     6CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path#fragment
    17Test WebSocket URL parsing.
    28
    39On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    410
     11PASS new WebSocket("ws://javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12.
    512PASS new WebSocket("/applet") threw exception Error: SYNTAX_ERR: DOM Exception 12.
     13PASS new WebSocket("javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12.
    614PASS new WebSocket("ws://127.0.0.1:25/") threw exception Error: SECURITY_ERR: DOM Exception 18.
    7 PASS (new WebSocket("ws://127.0.0.1/a/../")).URL is "ws://127.0.0.1/"
    8 PASS (new WebSocket("ws://127.0.0.1/path?")).URL is "ws://127.0.0.1/path?"
    9 PASS (new WebSocket("ws://127.0.0.1/path?k=v")).URL is "ws://127.0.0.1/path?k=v"
     15PASS (new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/simple")).URL is "ws://127.0.0.1:8880/websocket/tests/simple"
     16PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?")).URL is "ws://127.0.0.1:8880/websocket/tests/simple?"
     17PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?k=v")).URL is "ws://127.0.0.1:8880/websocket/tests/simple?k=v"
    1018PASS new WebSocket("ws://127.0.0.1/path#") threw exception Error: SYNTAX_ERR: DOM Exception 12.
    1119PASS new WebSocket("ws://127.0.0.1/path#fragment") threw exception Error: SYNTAX_ERR: DOM Exception 12.
  • trunk/WebCore/ChangeLog

    r52469 r52478  
     12009-12-21  Fumitoshi Ukai  <ukai@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Invalid url should raise SYNTAX_ERR exception.
     6        https://bugs.webkit.org/show_bug.cgi?id=32700
     7
     8        Check url is valid in WebSocket::connect.
     9        Also log the detailed reason of websocket failures to console.
     10
     11        * websockets/WebSocket.cpp:
     12        (WebCore::encodeProtocolString):
     13        (WebCore::WebSocket::connect):
     14
    1152009-12-21  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/WebCore/websockets/WebSocket.cpp

    r52402 r52478  
    4444#include "MessageEvent.h"
    4545#include "ScriptExecutionContext.h"
     46#include "StringBuilder.h"
    4647#include "WebSocketChannel.h"
    4748#include <wtf/StdLibExtras.h>
     
    4950namespace WebCore {
    5051
    51 static bool isValidProtocolString(const WebCore::String& protocol)
     52static bool isValidProtocolString(const String& protocol)
    5253{
    5354    if (protocol.isNull())
     
    6364}
    6465
     66static String encodeProtocolString(const String& protocol)
     67{
     68    StringBuilder builder;
     69    for (size_t i = 0; i < protocol.length(); i++) {
     70        if (protocol[i] < 0x20 || protocol[i] > 0x7E)
     71            builder.append(String::format("\\u%04X", protocol[i]));
     72        else if (protocol[i] == 0x5c)
     73            builder.append("\\\\");
     74        else
     75            builder.append(protocol[i]);
     76    }
     77    return builder.toString();
     78}
     79
    6580#if USE(V8)
    6681
     
    102117    m_protocol = protocol;
    103118
     119    if (!m_url.isValid()) {
     120        scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
     121        m_state = CLOSED;
     122        ec = SYNTAX_ERR;
     123        return;
     124    }
     125
    104126    if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) {
    105         LOG(Network, "Wrong url scheme for WebSocket %s", url.string().utf8().data());
     127        scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
    106128        m_state = CLOSED;
    107129        ec = SYNTAX_ERR;
     
    109131    }
    110132    if (m_url.hasFragmentIdentifier()) {
    111         LOG(Network, "URL has fragment component %s", url.string().utf8().data());
     133        scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString());
    112134        m_state = CLOSED;
    113135        ec = SYNTAX_ERR;
     
    115137    }
    116138    if (!isValidProtocolString(m_protocol)) {
    117         LOG(Network, "Wrong protocol for WebSocket %s", m_protocol.utf8().data());
     139        scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong protocol for WebSocket '" + encodeProtocolString(m_protocol) + "'", 0, scriptExecutionContext()->securityOrigin()->toString());
    118140        m_state = CLOSED;
    119141        ec = SYNTAX_ERR;
     
    121143    }
    122144    if (!portAllowed(url)) {
    123         LOG(Network, "WebSocket port %d blocked", url.port());
     145        scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, String::format("WebSocket port %d blocked", url.port()), 0, scriptExecutionContext()->securityOrigin()->toString());
    124146        m_state = CLOSED;
    125147        ec = SECURITY_ERR;
Note: See TracChangeset for help on using the changeset viewer.