chromium/services/network/public/cpp/is_potentially_trustworthy.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/public/cpp/is_potentially_trustworthy.h"

#include <iterator>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/checked_math.h"
#include "base/ranges/algorithm.h"
#include "base/sequence_checker.h"
#include "base/strings/pattern.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/ip_address.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/network_switches.h"
#include "url/origin.h"
#include "url/scheme_host_port.h"
#include "url/url_canon.h"
#include "url/url_canon_ip.h"
#include "url/url_canon_stdstring.h"
#include "url/url_constants.h"
#include "url/url_util.h"

namespace network {

namespace {

// Best effort test if the hostname with wildcards can match a raw IPv4 address
// taken from a GURL (e.g., "1.2.3.4").  This excludes things like
// "0x1.0x2.0x3.0x4", since GURL will map that to 1.2.3.4. Can potentially
// incorrectly return true cases with extra 0's (e.g., "*.2.3.00").
bool PatternCanMatchIpV4Host(const std::string& hostname_pattern) {}

// Given a hostname pattern with a wildcard such as "*.foo.com", returns
// true if |hostname_pattern| meets both of these conditions:
// 1.) A string matching |hostname_pattern| is a valid hostname.
// 2.) Wildcards only appear beyond the eTLD+1. "*.foo.com" is considered
//     valid but "*.com" is not.
bool IsValidWildcardPattern(const std::string& hostname_pattern) {}

// Canonicalizes each component of |hostname_pattern|, making no changes to
// wildcard components or components that fail canonicalization. For example,
// given a |hostname_pattern| of "TeSt.*.%46oo.com", the output will be
// "test.*.foo.com".
std::string CanonicalizePatternComponents(const std::string& hostname_pattern) {}

std::vector<std::string> CanonicalizeAllowlist(
    const std::vector<std::string>& origins_and_patterns_list,
    std::vector<std::string>* rejected_patterns) {}

std::vector<std::string> ParseSecureOriginAllowlist(
    const std::string& origins_str,
    std::vector<std::string>* rejected_patterns = nullptr) {}

std::vector<std::string> ParseSecureOriginAllowlistFromCmdline() {}

bool IsAllowlisted(const std::vector<std::string>& allowlist,
                   const url::Origin& origin) {}

bool IsSchemeConsideredAuthenticated(std::string_view scheme) {}

}  // namespace

bool IsOriginPotentiallyTrustworthy(const url::Origin& origin) {}

bool IsUrlPotentiallyTrustworthy(const GURL& url) {}

// static
SecureOriginAllowlist& SecureOriginAllowlist::GetInstance() {}

std::vector<std::string> SecureOriginAllowlist::GetCurrentAllowlist() {}

void SecureOriginAllowlist::SetAuxiliaryAllowlist(
    const std::string& auxiliary_allowlist,
    std::vector<std::string>* rejected_patterns) {}

void SecureOriginAllowlist::ResetForTesting() {}

bool SecureOriginAllowlist::IsOriginAllowlisted(const url::Origin& origin) {}

// static
std::vector<std::string> SecureOriginAllowlist::CanonicalizeAllowlistForTesting(
    const std::vector<std::string>& allowlist,
    std::vector<std::string>* rejected_patterns) {}

SecureOriginAllowlist::SecureOriginAllowlist() = default;

void SecureOriginAllowlist::ParseCmdlineIfNeeded() {}

}  // namespace network