#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/cookies/cookie_util.h"
#include <cstdio>
#include <cstdlib>
#include <string>
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "net/base/features.h"
#include "net/base/isolation_info.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "net/cookies/cookie_access_delegate.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/cookie_switches.h"
#include "net/cookies/parsed_cookie.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "net/first_party_sets/first_party_sets_cache_filter.h"
#include "net/http/http_util.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace net::cookie_util {
namespace {
ContextType;
ContextMetadata;
base::Time MinNonNullTime() { … }
bool SaturatedTimeFromUTCExploded(const base::Time::Exploded& exploded,
base::Time* out) { … }
bool HasValidHostPrefixAttributes(const GURL& url,
bool secure,
const std::string& domain,
const std::string& path) { … }
struct ComputeSameSiteContextResult { … };
CookieOptions::SameSiteCookieContext MakeSameSiteCookieContext(
const ComputeSameSiteContextResult& result,
const ComputeSameSiteContextResult& schemeful_result) { … }
ContextMetadata::ContextRedirectTypeBug1221316
ComputeContextRedirectTypeBug1221316(bool url_chain_is_length_one,
bool same_site_initiator,
bool site_for_cookies_is_same_site,
bool same_site_redirect_chain) { … }
ComputeSameSiteContextResult ComputeSameSiteContext(
const std::vector<GURL>& url_chain,
const SiteForCookies& site_for_cookies,
const std::optional<url::Origin>& initiator,
bool is_http,
bool is_main_frame_navigation,
bool compute_schemefully) { … }
void NormalizeStrictToLaxForSet(ComputeSameSiteContextResult& result) { … }
CookieOptions::SameSiteCookieContext ComputeSameSiteContextForSet(
const std::vector<GURL>& url_chain,
const SiteForCookies& site_for_cookies,
const std::optional<url::Origin>& initiator,
bool is_http,
bool is_main_frame_navigation) { … }
bool CookieWithAccessResultSorter(const CookieWithAccessResult& a,
const CookieWithAccessResult& b) { … }
}
void FireStorageAccessHistogram(StorageAccessResult result) { … }
bool DomainIsHostOnly(const std::string& domain_string) { … }
std::string CookieDomainAsHost(const std::string& cookie_domain) { … }
std::string GetEffectiveDomain(const std::string& scheme,
const std::string& host) { … }
bool GetCookieDomainWithString(const GURL& url,
const std::string& domain_string,
CookieInclusionStatus& status,
std::string* result) { … }
base::Time ParseCookieExpirationTime(const std::string& time_string) { … }
std::string CanonPathWithString(const GURL& url,
const std::string& path_string) { … }
GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
const std::string& source_scheme) { … }
GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
bool is_https) { … }
GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
CookieSourceScheme source_scheme) { … }
GURL CookieOriginToURL(const std::string& domain, bool is_https) { … }
GURL SimulatedCookieSource(const CanonicalCookie& cookie,
const std::string& source_scheme) { … }
CookieAccessScheme ProvisionalAccessScheme(const GURL& source_url) { … }
bool IsDomainMatch(const std::string& domain, const std::string& host) { … }
bool IsOnPath(const std::string& cookie_path, const std::string& url_path) { … }
CookiePrefix GetCookiePrefix(const std::string& name) { … }
bool IsCookiePrefixValid(CookiePrefix prefix,
const GURL& url,
const ParsedCookie& parsed_cookie) { … }
bool IsCookiePrefixValid(CookiePrefix prefix,
const GURL& url,
bool secure,
const std::string& domain,
const std::string& path) { … }
bool IsCookiePartitionedValid(const GURL& url,
const ParsedCookie& parsed_cookie,
bool partition_has_nonce) { … }
bool IsCookiePartitionedValid(const GURL& url,
bool secure,
bool is_partitioned,
bool partition_has_nonce) { … }
void ParseRequestCookieLine(const std::string& header_value,
ParsedRequestCookies* parsed_cookies) { … }
std::string SerializeRequestCookieLine(
const ParsedRequestCookies& parsed_cookies) { … }
CookieOptions::SameSiteCookieContext ComputeSameSiteContextForRequest(
const std::string& http_method,
const std::vector<GURL>& url_chain,
const SiteForCookies& site_for_cookies,
const std::optional<url::Origin>& initiator,
bool is_main_frame_navigation,
bool force_ignore_site_for_cookies) { … }
NET_EXPORT CookieOptions::SameSiteCookieContext
ComputeSameSiteContextForScriptGet(const GURL& url,
const SiteForCookies& site_for_cookies,
const std::optional<url::Origin>& initiator,
bool force_ignore_site_for_cookies) { … }
CookieOptions::SameSiteCookieContext ComputeSameSiteContextForResponse(
const std::vector<GURL>& url_chain,
const SiteForCookies& site_for_cookies,
const std::optional<url::Origin>& initiator,
bool is_main_frame_navigation,
bool force_ignore_site_for_cookies) { … }
CookieOptions::SameSiteCookieContext ComputeSameSiteContextForScriptSet(
const GURL& url,
const SiteForCookies& site_for_cookies,
bool force_ignore_site_for_cookies) { … }
CookieOptions::SameSiteCookieContext ComputeSameSiteContextForSubresource(
const GURL& url,
const SiteForCookies& site_for_cookies,
bool force_ignore_site_for_cookies) { … }
bool IsPortBoundCookiesEnabled() { … }
bool IsSchemeBoundCookiesEnabled() { … }
bool IsOriginBoundCookiesPartiallyEnabled() { … }
bool IsTimeLimitedInsecureCookiesEnabled() { … }
bool IsSchemefulSameSiteEnabled() { … }
std::optional<
std::pair<FirstPartySetMetadata, FirstPartySetsCacheFilter::MatchInfo>>
ComputeFirstPartySetMetadataMaybeAsync(
const SchemefulSite& request_site,
const IsolationInfo& isolation_info,
const CookieAccessDelegate* cookie_access_delegate,
base::OnceCallback<void(FirstPartySetMetadata,
FirstPartySetsCacheFilter::MatchInfo)> callback) { … }
CookieOptions::SameSiteCookieContext::ContextMetadata::HttpMethod
HttpMethodStringToEnum(const std::string& in) { … }
bool IsCookieAccessResultInclude(CookieAccessResult cookie_access_result) { … }
CookieList StripAccessResults(
const CookieAccessResultList& cookie_access_results_list) { … }
NET_EXPORT void RecordCookiePortOmniboxHistograms(const GURL& url) { … }
NET_EXPORT void DCheckIncludedAndExcludedCookieLists(
const CookieAccessResultList& included_cookies,
const CookieAccessResultList& excluded_cookies) { … }
NET_EXPORT bool IsForceThirdPartyCookieBlockingEnabled() { … }
bool PartitionedCookiesDisabledByCommandLine() { … }
}