Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: extensions/browser/content_verifier.cc

Issue 1315713009: Fix content verification failures on unusual content script paths (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix windows compile error Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/extensions/content_verifier/dot_slash_paths/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/content_verifier.cc
diff --git a/extensions/browser/content_verifier.cc b/extensions/browser/content_verifier.cc
index eaafe8f403bb2175063aa12d9ab6fe82cbceca63..3c778929e031266086fd9e60eec329b9efd07b87 100644
--- a/extensions/browser/content_verifier.cc
+++ b/extensions/browser/content_verifier.cc
@@ -24,6 +24,31 @@ namespace {
ContentVerifier::TestObserver* g_test_observer = NULL;
+// This function converts paths like "//foo/bar", "./foo/bar", and
+// "/foo/bar" to "foo/bar". It also converts path separators to "/".
+base::FilePath NormalizeRelativePath(const base::FilePath& path) {
+ if (path.ReferencesParent())
+ return base::FilePath();
+
+ std::vector<base::FilePath::StringType> parts;
+ path.GetComponents(&parts);
+ if (parts.empty())
+ return base::FilePath();
+
+ // Remove the first component if it is '.' or '/' or '//'.
+ const base::FilePath::StringType separators(
+ base::FilePath::kSeparators, base::FilePath::kSeparatorsLength);
+ if (!parts[0].empty() &&
+ (parts[0] == base::FilePath::kCurrentDirectory ||
+ parts[0].find_first_not_of(separators) == std::string::npos))
+ parts.erase(parts.begin());
+
+ // Note that elsewhere we always normalize path separators to '/' so this
+ // should work for all platforms.
+ return base::FilePath(
+ base::JoinString(parts, base::FilePath::StringType(1, '/')));
+}
+
} // namespace
// static
@@ -73,8 +98,10 @@ ContentVerifyJob* ContentVerifier::CreateJobFor(
if (!data)
return NULL;
+ base::FilePath normalized_path = NormalizeRelativePath(relative_path);
+
std::set<base::FilePath> paths;
- paths.insert(relative_path);
+ paths.insert(normalized_path);
if (!ShouldVerifyAnyPaths(extension_id, extension_root, paths))
return NULL;
@@ -82,7 +109,7 @@ ContentVerifyJob* ContentVerifier::CreateJobFor(
// a cache of ContentHashReader's that we hold onto past the end of each job.
return new ContentVerifyJob(
new ContentHashReader(extension_id, data->version, extension_root,
- relative_path, delegate_->GetPublicKey()),
+ normalized_path, delegate_->GetPublicKey()),
base::Bind(&ContentVerifier::VerifyFailed, this, extension_id));
}
@@ -116,29 +143,6 @@ void ContentVerifier::VerifyFailed(const std::string& extension_id,
}
}
-static base::FilePath MakeImagePathRelative(const base::FilePath& path) {
- if (path.ReferencesParent())
- return base::FilePath();
-
- std::vector<base::FilePath::StringType> parts;
- path.GetComponents(&parts);
- if (parts.empty())
- return base::FilePath();
-
- // Remove the first component if it is '.' or '/' or '//'.
- const base::FilePath::StringType separators(
- base::FilePath::kSeparators, base::FilePath::kSeparatorsLength);
- if (!parts[0].empty() &&
- (parts[0] == base::FilePath::kCurrentDirectory ||
- parts[0].find_first_not_of(separators) == std::string::npos))
- parts.erase(parts.begin());
-
- // Note that elsewhere we always normalize path separators to '/' so this
- // should work for all platforms.
- return base::FilePath(
- base::JoinString(parts, base::FilePath::StringType(1, '/')));
-}
-
void ContentVerifier::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
@@ -156,7 +160,7 @@ void ContentVerifier::OnExtensionLoaded(
scoped_ptr<std::set<base::FilePath>> image_paths(
new std::set<base::FilePath>);
for (const auto& path : original_image_paths) {
- image_paths->insert(MakeImagePathRelative(path));
+ image_paths->insert(NormalizeRelativePath(path));
}
scoped_ptr<ContentVerifierIOData::ExtensionData> data(
« no previous file with comments | « chrome/test/data/extensions/content_verifier/dot_slash_paths/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698