Skip to content

Commit

Permalink
Bug 1453318 - Disallow responses when a response header value contain…
Browse files Browse the repository at this point in the history
…s 0x00; r=kershaw,sunil,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D185160
  • Loading branch information
wisniewskit committed Aug 7, 2023
1 parent c3d6f0e commit f46b175
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 104 deletions.
1 change: 1 addition & 0 deletions dom/base/domerr.msg
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ DOM4_MSG_DEF(NotSupportedError, "The media resource indicated by the src attribu

DOM4_MSG_DEF(SyntaxError, "The URI is malformed.", NS_ERROR_DOM_MALFORMED_URI)
DOM4_MSG_DEF(SyntaxError, "Invalid header name.", NS_ERROR_DOM_INVALID_HEADER_NAME)
DOM4_MSG_DEF(SyntaxError, "Invalid header value.", NS_ERROR_DOM_INVALID_HEADER_VALUE)

/* XMLHttpRequest errors. */
DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest has an invalid context.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_INVALID_CONTEXT)
Expand Down
6 changes: 6 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12643,6 +12643,12 @@
value: 5
mirror: always

# If true, requests will be canceled if any of the response headers values has a NUL character
- name: network.http.reject_NULs_in_response_header_values
type: RelaxedAtomicBool
value: true
mirror: always

# If true, remove the resumption token when 0RTT failed.
- name: network.http.remove_resumption_token_when_early_data_failed
type: RelaxedAtomicBool
Expand Down
9 changes: 9 additions & 0 deletions netwerk/protocol/http/nsHttpResponseHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// HttpLog.h should generally be included first
#include "HttpLog.h"

#include "mozilla/StaticPrefs_network.h"
#include "mozilla/Unused.h"
#include "nsHttpResponseHead.h"
#include "nsIHttpHeaderVisitor.h"
Expand Down Expand Up @@ -594,6 +595,14 @@ nsresult nsHttpResponseHead::ParseHeaderLine_locked(
line, &hdr, &headerNameOriginal, &val))) {
return NS_OK;
}

// reject the header if there are 0x00 bytes in the value.
// (see https://github.com/httpwg/http-core/issues/215 for details).
if (StaticPrefs::network_http_reject_NULs_in_response_header_values() &&
val.FindChar('\0') >= 0) {
return NS_ERROR_DOM_INVALID_HEADER_VALUE;
}

nsresult rv;
if (originalFromNetHeaders) {
rv = mHeaders.SetHeaderFromNet(hdr, headerNameOriginal, val, true);
Expand Down
27 changes: 0 additions & 27 deletions testing/web-platform/meta/cookies/name/name-ctl.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,6 @@
[Cookie with %x7f in name is rejected (DOM).]
expected: FAIL

[Cookie with %x0 in name is rejected or modified (HTTP).]
expected: FAIL

[Cookie with %x1 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x2 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x3 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x4 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x5 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x6 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x7 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x8 in name is rejected (HTTP).]
expected: FAIL

[Cookie with %x9 in name is accepted (HTTP).]
expected: FAIL

Expand Down
20 changes: 16 additions & 4 deletions testing/web-platform/meta/cookies/name/name.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,25 @@
expected: FAIL
[Set a nameless cookie (that has an = in its value)]
expected: FAIL
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set a nameless cookie (that has multiple ='s in its value)]
expected: FAIL
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set a nameless cookie]
expected: FAIL
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set valueless cookie to its name with empty value]
expected: FAIL
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
30 changes: 0 additions & 30 deletions testing/web-platform/meta/cookies/value/value-ctl.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,6 @@
[Cookie with %xd in value is rejected (DOM).]
expected: FAIL

[Cookie with %x0 in name is rejected or modified (HTTP).]
expected: FAIL

[Cookie with %x1 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x2 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x3 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x4 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x5 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x6 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x7 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x8 in value is rejected (HTTP).]
expected: FAIL

[Cookie with %x9 in value is accepted (HTTP).]
expected: FAIL

[Cookie with %xa in name is rejected or modified (HTTP).]
expected: FAIL

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
[resources-with-0x00-in-header.window.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Expect network error for image with 0x00 in a header]
expected: FAIL

[Expect network error for frame navigation to resource with 0x00 in a header]
expected: FAIL

[Expect network error for script with 0x00 in a header]
expected: FAIL
11 changes: 0 additions & 11 deletions testing/web-platform/meta/xhr/headers-normalize-response.htm.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
[headers-normalize-response.htm]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Header value: hello\\0world]
expected: FAIL

[Header value: \\0hello world]
expected: FAIL

[Header value: \\0]
expected: FAIL

[Header value: hello world\\0]
expected: FAIL
2 changes: 2 additions & 0 deletions xpcom/base/ErrorList.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ def SUCCESS(code):
# https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policies
errors["NS_ERROR_DOM_COOP_FAILED"] = FAILURE(1041)

errors["NS_ERROR_DOM_INVALID_HEADER_VALUE"] = FAILURE(1042)

# May be used to indicate when e.g. setting a property value didn't
# actually change the value, like for obj.foo = "bar"; obj.foo = "bar";
# the second assignment throws NS_SUCCESS_DOM_NO_OPERATION.
Expand Down

0 comments on commit f46b175

Please sign in to comment.