#include "extensions/common/csp_validator.h"
#include <stddef.h>
#include <initializer_list>
#include <iterator>
#include <set>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/install_warning.h"
#include "extensions/common/manifest_constants.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
namespace extensions {
namespace csp_validator {
namespace {
const char kDefaultSrc[] = …;
const char kScriptSrc[] = …;
const char kObjectSrc[] = …;
const char kFrameSrc[] = …;
const char kChildSrc[] = …;
const char kWorkerSrc[] = …;
const char kSelfSource[] = …;
const char kNoneSource[] = …;
const char kWasmEvalSource[] = …;
const char kWasmUnsafeEvalSource[] = …;
const char kDirectiveSeparator = …;
const char kObjectSrcDefaultDirective[] = …;
const char kScriptSrcDefaultDirective[] = …;
const char kAppSandboxSubframeSrcDefaultDirective[] = …;
const char kAppSandboxScriptSrcDefaultDirective[] = …;
const char kSandboxDirectiveName[] = …;
const char kAllowSameOriginToken[] = …;
const char kAllowTopNavigation[] = …;
const char* const kHashSourcePrefixes[] = …;
const char kWhitespaceDelimiters[] = …;
Directive;
DirectiveList;
bool IsLocalHostSource(const std::string& source_lower) { … }
class DirectiveStatus { … };
bool isNonWildcardTLD(const std::string& url,
const std::string& scheme_and_separator,
bool should_check_rcd) { … }
bool IsHashSource(std::string_view source) { … }
std::string GetSecureDirectiveValues(
int options,
const std::string& directive_name,
const std::vector<std::string_view>& directive_values,
const std::string& manifest_key,
std::vector<InstallWarning>* warnings) { … }
std::string GetAppSandboxSecureDirectiveValues(
const std::string& directive_name,
const std::vector<std::string_view>& directive_values,
const std::string& manifest_key,
std::vector<InstallWarning>* warnings) { … }
SecureDirectiveValueFunction;
class CSPDirectiveToken { … };
class CSPEnforcer { … };
std::string CSPEnforcer::Enforce(const DirectiveList& directives,
std::vector<InstallWarning>* warnings) { … }
class ExtensionCSPEnforcer : public CSPEnforcer { … };
class AppSandboxPageCSPEnforcer : public CSPEnforcer { … };
}
bool ContentSecurityPolicyIsLegal(const std::string& policy) { … }
Directive::Directive(std::string_view directive_string,
std::string directive_name,
std::vector<std::string_view> directive_values)
: … { … }
CSPParser::Directive::~Directive() = default;
CSPParser::Directive::Directive(Directive&&) = default;
CSPParser::Directive& Directive::operator=(Directive&&) = default;
CSPParser::CSPParser(std::string policy) : … { … }
CSPParser::~CSPParser() = default;
void CSPParser::Parse() { … }
std::string SanitizeContentSecurityPolicy(
const std::string& policy,
std::string manifest_key,
int options,
std::vector<InstallWarning>* warnings) { … }
std::string GetSandboxedPageCSPDisallowingRemoteSources(
const std::string& policy,
std::string manifest_key,
std::vector<InstallWarning>* warnings) { … }
bool ContentSecurityPolicyIsSandboxed(
const std::string& policy, Manifest::Type type) { … }
bool DoesCSPDisallowRemoteCode(const std::string& content_security_policy,
std::string_view manifest_key,
std::u16string* error) { … }
}
}