tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CookieValidation.h (3586B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_net_CookieValidation_h
      7 #define mozilla_net_CookieValidation_h
      8 
      9 #include "nsICookieValidation.h"
     10 #include "Cookie.h"
     11 
     12 class nsIConsoleReportCollector;
     13 
     14 namespace mozilla {
     15 namespace net {
     16 
     17 constexpr auto CONSOLE_CHIPS_CATEGORY = "cookiesCHIPS"_ns;
     18 constexpr auto CONSOLE_OVERSIZE_CATEGORY = "cookiesOversize"_ns;
     19 constexpr auto CONSOLE_REJECTION_CATEGORY = "cookiesRejection"_ns;
     20 constexpr auto CONSOLE_SAMESITE_CATEGORY = "cookieSameSite"_ns;
     21 constexpr auto SAMESITE_MDN_URL =
     22    "https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Set-Cookie#"
     23    u"samesitesamesite-value"_ns;
     24 
     25 class CookieValidation final : public nsICookieValidation {
     26  NS_DECL_ISUPPORTS
     27  NS_DECL_NSICOOKIEVALIDATION
     28 
     29 public:
     30  static already_AddRefed<CookieValidation> Validate(
     31      const CookieStruct& aCookieData);
     32 
     33  static already_AddRefed<CookieValidation> ValidateForHost(
     34      const CookieStruct& aCookieData, nsIURI* aHostURI,
     35      const nsACString& aBaseDomain, bool aRequireHostMatch, bool aFromHttp);
     36 
     37  static already_AddRefed<CookieValidation> ValidateInContext(
     38      const CookieStruct& aCookieData, nsIURI* aHostURI,
     39      const nsACString& aBaseDomain, bool aRequireHostMatch, bool aFromHttp,
     40      bool aIsForeignAndNotAddon, bool aPartitionedOnly,
     41      bool aIsInPrivateBrowsing);
     42 
     43  static CookieValidation* Cast(nsICookieValidation* aValidation) {
     44    return static_cast<CookieValidation*>(aValidation);
     45  }
     46 
     47  nsICookieValidation::ValidationError Result() const { return mResult; }
     48 
     49  void ReportErrorsAndWarnings(nsIConsoleReportCollector* aCRC,
     50                               nsIURI* aHostURI) const;
     51 
     52 private:
     53  explicit CookieValidation(const CookieStruct& aCookieData);
     54  ~CookieValidation() = default;
     55 
     56  void ValidateInternal();
     57 
     58  void ValidateForHostInternal(nsIURI* aHostURI, const nsACString& aBaseDomain,
     59                               bool aRequireHostMatch, bool aFromHttp);
     60 
     61  void ValidateInContextInternal(nsIURI* aHostURI,
     62                                 const nsACString& aBaseDomain,
     63                                 bool aRequireHostMatch, bool aFromHttp,
     64                                 bool aIsForeignAndNotAddon,
     65                                 bool aPartitionedOnly,
     66                                 bool aIsInPrivateBrowsing);
     67 
     68  static bool CheckNameAndValueSize(const CookieStruct& aCookieData);
     69 
     70  static bool CheckName(const CookieStruct& aCookieData);
     71 
     72  static bool CheckValue(const CookieStruct& aCookieData);
     73 
     74  static bool CheckDomain(const CookieStruct& aCookieData, nsIURI* aHostURI,
     75                          const nsACString& aBaseDomain,
     76                          bool aRequireHostMatch);
     77 
     78  static bool CheckPrefixes(const CookieStruct& aCookieData,
     79                            bool aSecureRequest);
     80 
     81  CookieStruct mCookieData;
     82 
     83  nsICookieValidation::ValidationError mResult = eOK;
     84 
     85  void RetrieveErrorLogData(uint32_t* aFlags, nsACString& aCategory,
     86                            nsACString& aKey,
     87                            nsTArray<nsString>& aParams) const;
     88 
     89  struct Warnings {
     90    bool mSameSiteLaxForced = false;
     91    bool mSameSiteLaxForcedForBeta = false;
     92    bool mSameSiteNoneRequiresSecureForBeta = false;
     93  } mWarnings;
     94 };
     95 
     96 }  // namespace net
     97 }  // namespace mozilla
     98 
     99 #endif  // mozilla_net_CookieValidation_h