Skip to content

Commit

Permalink
Merge r235025 - Relax Request constructor around referrers
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=168649

Patch by Rob Buis <rbuis@igalia.com> on 2018-08-20
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/policies/referrer-origin-expected.txt:
* web-platform-tests/fetch/api/policies/referrer-origin-service-worker.https-expected.txt:
* web-platform-tests/fetch/api/policies/referrer-origin-worker-expected.txt:
* web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt:

Source/WebCore:

Implement remaining part of fetch change
whatwg/fetch#377, i.e.
if "parsedReferrer’s origin is not same origin with origin",
then set request’s referrer to "client", instead of
throwing an exception [1].

WebKit's new behavior matches that of Chrome and Firefox.

Testing is covered by existing wpt tests.

[1] Step 15.3.3 of https://fetch.spec.whatwg.org/#main-fetch

* Modules/fetch/FetchRequest.cpp:
(WebCore::computeReferrer):

LayoutTests:

* platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt:
  • Loading branch information
rwlbuis authored and carlosgcampos committed Aug 20, 2018
1 parent 4fdf250 commit 7e455d4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
9 changes: 9 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,12 @@
2018-08-20 Rob Buis <rbuis@igalia.com>

Relax Request constructor around referrers
https://bugs.webkit.org/show_bug.cgi?id=168649

Reviewed by Darin Adler.

* platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt:

2018-08-18 Ali Juma <ajuma@chromium.org>

[IntersectionObserver] Fire an initial dummy notification
Expand Down
12 changes: 12 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,15 @@
2018-08-20 Rob Buis <rbuis@igalia.com>

Relax Request constructor around referrers
https://bugs.webkit.org/show_bug.cgi?id=168649

Reviewed by Darin Adler.

* web-platform-tests/fetch/api/policies/referrer-origin-expected.txt:
* web-platform-tests/fetch/api/policies/referrer-origin-service-worker.https-expected.txt:
* web-platform-tests/fetch/api/policies/referrer-origin-worker-expected.txt:
* web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt:

2018-08-18 Ali Juma <ajuma@chromium.org>

[IntersectionObserver] Fire an initial dummy notification
Expand Down
@@ -1,4 +1,4 @@

PASS Request's referrer is origin
FAIL Cross-origin referrer is overridden by client origin promise_test: Unhandled rejection with value: object "TypeError: Referrer is not same-origin."
PASS Cross-origin referrer is overridden by client origin

@@ -1,5 +1,5 @@

PASS Fetch in service worker: referrer with no-referrer policy
FAIL Request's referrer is origin assert_equals: request's referrer is https://localhost:9443/ expected "https://localhost:9443/" but got "https://localhost:9443/fetch/api/policies/referrer-origin.js?pipe=sub"
FAIL Cross-origin referrer is overridden by client origin promise_test: Unhandled rejection with value: object "TypeError: Referrer is not same-origin."
FAIL Cross-origin referrer is overridden by client origin assert_equals: request's referrer is https://localhost:9443/ expected "https://localhost:9443/" but got "https://localhost:9443/fetch/api/policies/referrer-origin.js?pipe=sub"

@@ -1,4 +1,4 @@

FAIL Request's referrer is origin assert_equals: request's referrer is http://localhost:8800/ expected "http://localhost:8800/" but got "http://localhost:8800/fetch/api/policies/referrer-origin.js?pipe=sub"
FAIL Cross-origin referrer is overridden by client origin promise_test: Unhandled rejection with value: object "TypeError: Referrer is not same-origin."
FAIL Cross-origin referrer is overridden by client origin assert_equals: request's referrer is http://localhost:8800/ expected "http://localhost:8800/" but got "http://localhost:8800/fetch/api/policies/referrer-origin.js?pipe=sub"

Expand Up @@ -9,7 +9,7 @@ PASS Check method init value of head and associated getter
PASS Check referrer init value of /relative/ressource and associated getter
PASS Check referrer init value of http://localhost:8800/relative/ressource?query=true#fragment and associated getter
PASS Check referrer init value of http://localhost:8800/ and associated getter
FAIL Check referrer init value of http://test.url and associated getter Referrer is not same-origin.
PASS Check referrer init value of http://test.url and associated getter
PASS Check referrer init value of about:client and associated getter
PASS Check referrer init value of and associated getter
PASS Check referrerPolicy init value of and associated getter
Expand Down
Expand Up @@ -9,7 +9,7 @@ PASS Check method init value of head and associated getter
PASS Check referrer init value of /relative/ressource and associated getter
PASS Check referrer init value of http://localhost:8800/relative/ressource?query=true#fragment and associated getter
PASS Check referrer init value of http://localhost:8800/ and associated getter
FAIL Check referrer init value of http://test.url and associated getter Referrer is not same-origin.
PASS Check referrer init value of http://test.url and associated getter
PASS Check referrer init value of about:client and associated getter
PASS Check referrer init value of and associated getter
PASS Check referrerPolicy init value of and associated getter
Expand Down
22 changes: 22 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,25 @@
2018-08-20 Rob Buis <rbuis@igalia.com>

Relax Request constructor around referrers
https://bugs.webkit.org/show_bug.cgi?id=168649

Reviewed by Darin Adler.

Implement remaining part of fetch change
https://github.com/whatwg/fetch/pull/377, i.e.
if "parsedReferrer’s origin is not same origin with origin",
then set request’s referrer to "client", instead of
throwing an exception [1].

WebKit's new behavior matches that of Chrome and Firefox.

Testing is covered by existing wpt tests.

[1] Step 15.3.3 of https://fetch.spec.whatwg.org/#main-fetch

* Modules/fetch/FetchRequest.cpp:
(WebCore::computeReferrer):

2018-08-19 Yusuke Suzuki <yusukesuzuki@slowstart.org>

Shrink size of WebCore::Event further by reordering members
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/Modules/fetch/FetchRequest.cpp
Expand Up @@ -48,18 +48,18 @@ static std::optional<Exception> setMethod(ResourceRequest& request, const String
static ExceptionOr<String> computeReferrer(ScriptExecutionContext& context, const String& referrer)
{
if (referrer.isEmpty())
return String { "no-referrer" };
return String { "no-referrer"_s };

// FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser.
URL referrerURL = context.completeURL(referrer);
if (!referrerURL.isValid())
return Exception { TypeError, "Referrer is not a valid URL."_s };

if (referrerURL.protocolIs("about") && referrerURL.path() == "client")
return String { "client" };
return String { "client"_s };

if (!(context.securityOrigin() && context.securityOrigin()->canRequest(referrerURL)))
return Exception { TypeError, "Referrer is not same-origin."_s };
return String { "client"_s };

return String { referrerURL.string() };
}
Expand Down

0 comments on commit 7e455d4

Please sign in to comment.