Commit 91ade58a authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

[Origin] Make DefaultPortForScheme consistent (blink vs url)

They were differing for the 'ftps' scheme. This was handled by blink/,
but not for url/. Chrome never supported the 'ftps', so I chose to
remove it on one side instead of adding it on the other.

There is a new fuzzer checking an origin stays SameOrigin with itself
after a round trip inside blink:
third_party/blink/renderer/platform/weborigin/security_origin_fuzzer.cc

Bug: 888079
Change-Id: Idf8813e03449461c4d22d4f5ede662cb58ef185f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2509754
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825310}
parent d51e0a1c
......@@ -44,12 +44,12 @@ bool IsDefaultPortForProtocol(uint16_t port, const WTF::String& protocol) {
return protocol == "https" || protocol == "wss";
case 21:
return protocol == "ftp";
case 990:
return protocol == "ftps";
}
return false;
}
// Please keep blink::DefaultPortForProtocol and url::DefaultPortForProtocol in
// sync.
uint16_t DefaultPortForProtocol(const WTF::String& protocol) {
if (protocol == "http" || protocol == "ws")
return 80;
......@@ -57,8 +57,6 @@ uint16_t DefaultPortForProtocol(const WTF::String& protocol) {
return 443;
if (protocol == "ftp")
return 21;
if (protocol == "ftps")
return 990;
return 0;
}
......
......@@ -40,6 +40,7 @@ PLATFORM_EXPORT bool IsDefaultPortForProtocol(uint16_t port,
const WTF::String& protocol);
// Returns 0 for unknown protocols. |protocol| must be lower case.
// Based on https://url.spec.whatwg.org/#default-port
PLATFORM_EXPORT uint16_t DefaultPortForProtocol(const WTF::String& protocol);
// Returns true if the port of the |url| is allowed for the scheme of the |url|.
......
......@@ -21,13 +21,13 @@ TEST(KnownPortsTest, IsDefaultPortForProtocol) {
{80, "ws", true},
{443, "wss", true},
{21, "ftp", true},
{990, "ftps", true},
// Unknown ones.
{5, "foo", false},
{80, "http:", false},
{443, "http", false},
{21, "ftps", false},
{990, "ftps", false},
{990, "ftp", false},
// With upper cases.
......@@ -52,13 +52,13 @@ TEST(KnownPortsTest, DefaultPortForProtocol) {
{80, "ws"},
{443, "wss"},
{21, "ftp"},
{990, "ftps"},
// Unknown ones.
{0, "foo"},
{0, "http:"},
{0, "HTTP"},
{0, "Https"},
{0, "ftps"},
};
for (const TestCase& test : inputs)
......
......@@ -500,7 +500,7 @@ bool CanonicalizePort(const base::char16* spec,
Component* out_port);
// Returns the default port for the given canonical scheme, or PORT_UNSPECIFIED
// if the scheme is unknown.
// if the scheme is unknown. Based on https://url.spec.whatwg.org/#default-port
COMPONENT_EXPORT(URL)
int DefaultPortForScheme(const char* scheme, int scheme_len);
......
......@@ -108,9 +108,11 @@ bool DoCanonicalizeStandardURL(const URLComponentSource<CHAR>& source,
} // namespace
// Returns the default port for the given canonical scheme, or PORT_UNSPECIFIED
// if the scheme is unknown.
//
// Please keep blink::DefaultPortForProtocol and url::DefaultPortForProtocol in
// sync.
int DefaultPortForScheme(const char* scheme, int scheme_len) {
int default_port = PORT_UNSPECIFIED;
switch (scheme_len) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment