Skip to content

Commit

Permalink
[Import Maps] Do not allow prefix matching for non-special schemes
Browse files Browse the repository at this point in the history
Reflecting
WICG/import-maps#227

Bug: 848607, WICG/import-maps#166
Change-Id: Ide80e105fc57dfa35a66051b241b699fa969fcec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491594
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833322}
GitOrigin-RevId: 895e1cd024248d79a79cc0c2f5ec1fa99e8245b2
  • Loading branch information
hiroshige-g authored and copybara-github committed Dec 3, 2020
1 parent c58c29a commit 898c4a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
9 changes: 9 additions & 0 deletions blink/renderer/core/script/import_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ base::Optional<KURL> ImportMap::ResolveImportsMatch(
return ResolveImportsMatchInternal(key, exact, debug_message);
}

// <spec step="1.2">... either asURL is null, or asURL is special</spec>
if (parsed_specifier.GetType() == ParsedSpecifier::Type::kURL &&
!SchemeRegistry::IsSpecialScheme(parsed_specifier.GetUrl().Protocol())) {
*debug_message = "Import Map: \"" + key +
"\" skips prefix match because of non-special URL scheme";

return base::nullopt;
}

// Step 1.2.
if (auto prefix_match = MatchPrefix(parsed_specifier, specifier_map)) {
return ResolveImportsMatchInternal(key, *prefix_match, debug_message);
Expand Down
7 changes: 7 additions & 0 deletions blink/renderer/platform/weborigin/scheme_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ bool SchemeRegistry::IsFetchScheme(const String& scheme) {
scheme == "http" || scheme == "https";
}

// https://url.spec.whatwg.org/#special-scheme
bool SchemeRegistry::IsSpecialScheme(const String& scheme) {
DCHECK_EQ(scheme, scheme.LowerASCII());
return scheme == "ftp" || scheme == "file" || scheme == "http" ||
scheme == "https" || scheme == "ws" || scheme == "wss";
}

void SchemeRegistry::RegisterURLSchemeAsFirstPartyWhenTopLevel(
const String& scheme) {
DCHECK_EQ(scheme, scheme.LowerASCII());
Expand Down
3 changes: 3 additions & 0 deletions blink/renderer/platform/weborigin/scheme_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class PLATFORM_EXPORT SchemeRegistry {
// https://fetch.spec.whatwg.org/#fetch-scheme
static bool IsFetchScheme(const String& scheme);

// https://url.spec.whatwg.org/#special-scheme
static bool IsSpecialScheme(const String& scheme);

// Schemes which override the first-/third-party checks on a Document.
static void RegisterURLSchemeAsFirstPartyWhenTopLevel(const String& scheme);
static void RemoveURLSchemeAsFirstPartyWhenTopLevel(const String& scheme);
Expand Down

This file was deleted.

0 comments on commit 898c4a5

Please sign in to comment.