Changeset 202910 in webkit


Ignore:
Timestamp:
Jul 7, 2016 9:24:14 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Response constructor should throw in case of bad reason phrase
https://bugs.webkit.org/show_bug.cgi?id=159508

Patch by Youenn Fablet <youenn@apple.com> on 2016-07-07
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/response/response-error-expected.txt:

Source/WebCore:

Covered by rebased test.

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::initializeWith): Validating reason phrase with new routine.
Throwing a TypeError in case of error.

  • platform/network/HTTPParsers.cpp:

(WebCore::isValidReasonPhrase): Added to validate reason phrase according
https://tools.ietf.org/html/rfc7230#section-3.1.2

  • platform/network/HTTPParsers.h:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r202909 r202910  
     12016-07-07  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response constructor should throw in case of bad reason phrase
     4        https://bugs.webkit.org/show_bug.cgi?id=159508
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/response/response-error-expected.txt:
     9
    1102016-07-07  Youenn Fablet  <youenn@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-expected.txt

    r197162 r202910  
    55PASS Throws RangeError when responseInit's status is 600
    66PASS Throws RangeError when responseInit's status is 1000
    7 FAIL Throws TypeError when responseInit's statusText is
    8  assert_throws: Expect TypeError exception
    9  function "function () { new Response("", { "statusText" : statusTex..." did not throw
    10 FAIL Throws TypeError when responseInit's statusText is Ā assert_throws: Expect TypeError exception Ā function "function () { new Response("", { "statusText" : statusTex..." did not throw
     7PASS Throws TypeError when responseInit's statusText is
     8 
     9PASS Throws TypeError when responseInit's statusText is Ā
    1110PASS Throws TypeError when building a response with body and a body status of 204
    1211PASS Throws TypeError when building a response with body and a body status of 205
  • trunk/Source/WebCore/ChangeLog

    r202909 r202910  
     12016-07-07  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response constructor should throw in case of bad reason phrase
     4        https://bugs.webkit.org/show_bug.cgi?id=159508
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by rebased test.
     9
     10        * Modules/fetch/FetchResponse.cpp:
     11        (WebCore::FetchResponse::initializeWith): Validating reason phrase with new routine.
     12        Throwing a TypeError in case of error.
     13        * platform/network/HTTPParsers.cpp:
     14        (WebCore::isValidReasonPhrase): Added to validate reason phrase according
     15        https://tools.ietf.org/html/rfc7230#section-3.1.2
     16        * platform/network/HTTPParsers.h:
     17
    1182016-07-07  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r202909 r202910  
    3535#include "ExceptionCode.h"
    3636#include "FetchRequest.h"
     37#include "HTTPParsers.h"
    3738#include "JSFetchResponse.h"
    3839#include "ScriptExecutionContext.h"
     
    8788    }
    8889
    89     // FIXME: Validate reason phrase (https://tools.ietf.org/html/rfc7230#section-3.1.2).
    9090    String statusText;
    91     if (!init.get("statusText", statusText)) {
     91    if (!init.get("statusText", statusText) || !isValidReasonPhrase(statusText)) {
    9292        ec = TypeError;
    9393        return;
  • trunk/Source/WebCore/platform/network/HTTPParsers.cpp

    r202121 r202910  
    103103}
    104104
     105// See RFC 7230, Section 3.1.2.
     106bool isValidReasonPhrase(const String& value)
     107{
     108    for (unsigned i = 0; i < value.length(); ++i) {
     109        UChar c = value[i];
     110        if (c == 0x7F || c > 0xFF || (c < 0x20 && c != '\t'))
     111            return false;
     112    }
     113    return true;
     114}
     115
    105116// See RFC 7230, Section 3.2.3.
    106117bool isValidHTTPHeaderValue(const String& value)
  • trunk/Source/WebCore/platform/network/HTTPParsers.h

    r202121 r202910  
    7070
    7171ContentDispositionType contentDispositionType(const String&);
     72bool isValidReasonPhrase(const String&);
    7273bool isValidHTTPHeaderValue(const String&);
    7374bool isValidHTTPToken(const String&);
    7475bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url);
    7576Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String&);
    76 String filenameFromHTTPContentDisposition(const String&); 
     77String filenameFromHTTPContentDisposition(const String&);
    7778String extractMIMETypeFromMediaType(const String&);
    78 String extractCharsetFromMediaType(const String&); 
     79String extractCharsetFromMediaType(const String&);
    7980void findCharsetInMediaType(const String& mediaType, unsigned int& charsetPos, unsigned int& charsetLen, unsigned int start = 0);
    8081XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL);
Note: See TracChangeset for help on using the changeset viewer.