Commit c7f1fbc0 authored by Domenic Denicola's avatar Domenic Denicola Committed by Commit Bot

Origin policy: remove dead code

This seems to be leftover from a Blink-side implementation of origin
policy. The classes defined in these files are not referenced elsewhere
in the Chromium codebase and are not involved in our current origin
policy implementation.

https://crbug.com/1060184 tracks adding a new fuzzer for the modern
implementation, to replace the one deleted here (that is currently
fuzzing dead code).

Fixes: 1056673
Change-Id: Idccac39753caa275c62f303a5f635cf6f74235b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079258Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Auto-Submit: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749582}
parent 294ef0ca
{
"content-security-policy": {
"policy": "does not matter",
"disposition": "enforce",
"allow-override": true,
}
}
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"\"content-security-policy\""
"\"policy\""
"\"disposition\""
"\"enforce\""
"\"report-only\""
"\"allow-override\""
"true"
"false"
......@@ -37,18 +37,6 @@ fuzzer_test("origin_trial_token_fuzzer") {
seed_corpus = "//content/test/data/fuzzer_corpus/origin_trial_token_data/"
}
fuzzer_test("origin_policy_parser_fuzzer") {
sources = [ "origin_policy_parser_fuzzer.cc" ]
deps = [
"//base",
"//base:i18n",
"//content/test:test_support",
]
dict =
"//content/test/data/fuzzer_dictionaries/origin_policy_parser_fuzzer.dict"
seed_corpus = "//content/test/data/fuzzer_corpus/origin_policy_parser_data/"
}
fuzzer_test("renderer_fuzzer") {
sources = [ "renderer_fuzzer.cc" ]
deps = [ ":fuzzer_support" ]
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/public/common/origin_policy/origin_policy.h" // nogncheck
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "base/strings/string_piece.h"
#include <stddef.h>
#include <stdint.h>
struct IcuEnvironment {
IcuEnvironment() { CHECK(base::i18n::InitializeICU()); }
base::AtExitManager at_exit_manager;
};
// Initialize ICU, which is required by the URL parser.
IcuEnvironment* env = new IcuEnvironment();
namespace content {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
blink::OriginPolicy::From(
base::StringPiece(reinterpret_cast<const char*>(data), size));
return 0;
}
} // namespace content
......@@ -106,9 +106,6 @@ jumbo_source_set("common") {
"notifications/notification_mojom_traits.cc",
"notifications/notification_resources.cc",
"notifications/platform_notification_data.cc",
"origin_policy/origin_policy.cc",
"origin_policy/origin_policy_parser.cc",
"origin_policy/origin_policy_parser.h",
"origin_trials/trial_token.cc",
"origin_trials/trial_token_validator.cc",
"page/page_zoom.cc",
......@@ -193,7 +190,6 @@ jumbo_source_set("common_unittests_sources") {
"messaging/message_port_descriptor_unittest.cc",
"mime_util/mime_util_unittest.cc",
"notifications/notification_mojom_traits_unittest.cc",
"origin_policy/origin_policy_unittest.cc",
"origin_trials/trial_token_unittest.cc",
"origin_trials/trial_token_validator_unittest.cc",
"test/run_all_unittests.cc",
......
vogelheim@chromium.org
mkwst@chromium.org
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/public/common/origin_policy/origin_policy.h"
#include "third_party/blink/common/origin_policy/origin_policy_parser.h"
namespace blink {
OriginPolicy::~OriginPolicy() {}
std::unique_ptr<OriginPolicy> OriginPolicy::From(
base::StringPiece manifest_text) {
return OriginPolicyParser::Parse(manifest_text);
}
OriginPolicy::OriginPolicy() {}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/common/origin_policy/origin_policy_parser.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace blink {
std::unique_ptr<OriginPolicy> OriginPolicyParser::Parse(
base::StringPiece text) {
OriginPolicyParser parser;
if (!parser.DoParse(text))
return nullptr;
return std::move(parser.policy_);
}
OriginPolicyParser::OriginPolicyParser() {}
OriginPolicyParser::~OriginPolicyParser() {}
bool OriginPolicyParser::DoParse(base::StringPiece policy_text) {
policy_ = base::WrapUnique(new OriginPolicy);
if (policy_text.empty())
return false;
std::unique_ptr<base::Value> json =
base::JSONReader::ReadDeprecated(policy_text);
if (!json || !json->is_dict())
return false;
base::Value* csp = json->FindKey("content-security-policy");
bool csp_ok = !csp || ParseContentSecurityPolicies(*csp);
base::Value* features = json->FindKey("feature-policy");
bool features_ok = !features || ParseFeaturePolicies(*features);
base::Value* first_party_set = json->FindKey("first-party-set");
bool first_party_set_ok =
!first_party_set || ParseFirstPartySet(*first_party_set);
return csp_ok && features_ok && first_party_set_ok;
}
bool OriginPolicyParser::ParseContentSecurityPolicies(
const base::Value& policies) {
if (!policies.is_list())
return false;
bool ok = true;
for (const auto& csp : policies.GetList()) {
ok &= ParseContentSecurityPolicy(csp);
}
return ok;
}
bool OriginPolicyParser::ParseContentSecurityPolicy(const base::Value& csp) {
if (!csp.is_dict())
return false;
const auto* policy = csp.FindKeyOfType("policy", base::Value::Type::STRING);
if (!policy)
return false;
const auto* report_only =
csp.FindKeyOfType("report-only", base::Value::Type::BOOLEAN);
policy_->csp_.push_back(
{policy->GetString(), report_only && report_only->GetBool()});
return true;
}
bool OriginPolicyParser::ParseFeaturePolicies(const base::Value& policies) {
if (!policies.is_list())
return false;
bool ok = true;
for (const auto& feature : policies.GetList()) {
ok &= ParseFeaturePolicy(feature);
}
return ok;
}
bool OriginPolicyParser::ParseFeaturePolicy(const base::Value& policy) {
if (!policy.is_string())
return false;
policy_->features_.push_back(policy.GetString());
return true;
}
// This will not fail policy parsing, even if the first party set field can't
// be parsed. Therefore this function always returns true.
bool OriginPolicyParser::ParseFirstPartySet(
const base::Value& first_party_set) {
if (!first_party_set.is_list())
return true;
for (const auto& first_party : first_party_set.GetList()) {
if (!ParseFirstPartyOrigin(first_party)) {
policy_->first_party_set_.clear();
return true;
}
}
return true;
}
bool OriginPolicyParser::ParseFirstPartyOrigin(const base::Value& first_party) {
if (!first_party.is_string())
return false;
GURL first_party_url(first_party.GetString());
if (!first_party_url.is_valid() || first_party_url.is_empty())
return false;
policy_->first_party_set_.insert(url::Origin::Create(first_party_url));
return true;
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_COMMON_ORIGIN_POLICY_ORIGIN_POLICY_PARSER_H_
#define THIRD_PARTY_BLINK_COMMON_ORIGIN_POLICY_ORIGIN_POLICY_PARSER_H_
#include "third_party/blink/public/common/origin_policy/origin_policy.h"
#include <string>
#include "base/macros.h"
namespace base {
class Value;
} // namespace base
namespace blink {
class OriginPolicyParser {
public:
// Parse the given origin policy.
// Returns an empty unique_ptr if parsing fails.
static std::unique_ptr<OriginPolicy> Parse(base::StringPiece);
private:
OriginPolicyParser();
~OriginPolicyParser();
bool DoParse(base::StringPiece);
bool ParseContentSecurityPolicies(const base::Value&);
bool ParseContentSecurityPolicy(const base::Value&);
bool ParseFeaturePolicies(const base::Value&);
bool ParseFeaturePolicy(const base::Value&);
bool ParseFirstPartySet(const base::Value&);
bool ParseFirstPartyOrigin(const base::Value&);
std::unique_ptr<OriginPolicy> policy_;
DISALLOW_COPY_AND_ASSIGN(OriginPolicyParser);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_COMMON_ORIGIN_POLICY_ORIGIN_POLICY_PARSER_H_
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