Commit d7e4b389 authored by Andrea Marchesini's avatar Andrea Marchesini Committed by amarchesini@mozilla.com
Browse files

Bug 1955685 - Improve cookie validation - part 2 - nsICookieValidation in...

Bug 1955685 - Improve cookie validation - part 2 - nsICookieValidation in cookieManager.addNative, r=edgul,cookie-reviewers,geckoview-reviewers,nalexander,glandium

Differential Revision: https://phabricator.services.mozilla.com/D244895
parent 576074a5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -314,6 +314,7 @@
@RESPATH@/res/locale/layout/MediaDocument.properties
@RESPATH@/res/locale/layout/xmlparser.properties
@RESPATH@/res/locale/dom/dom.properties
@RESPATH@/res/locale/necko/necko.properties
#ifdef XP_MACOSX
@RESPATH@/res/MainMenu.nib/
#endif
+3 −1
Original line number Diff line number Diff line
@@ -4785,7 +4785,9 @@ static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = {
    "chrome://global/locale/security/security.properties",
    "chrome://necko/locale/necko.properties",
    "resource://gre/res/locale/layout/HtmlForm.properties",
    "resource://gre/res/locale/dom/dom.properties"};
    "resource://gre/res/locale/dom/dom.properties",
    "resource://gre/res/locale/necko/necko.properties",
};

/* static */
nsresult nsContentUtils::EnsureStringBundle(PropertiesFile aFile) {
+1 −0
Original line number Diff line number Diff line
@@ -1312,6 +1312,7 @@ class nsContentUtils {
    eNECKO_PROPERTIES,
    eFORMS_PROPERTIES_en_US,
    eDOM_PROPERTIES_en_US,
    eNECKO_PROPERTIES_en_US,
    PropertiesFile_COUNT
  };
  static nsresult ReportToConsole(
+12 −21
Original line number Diff line number Diff line
@@ -356,10 +356,9 @@ bool CookieStoreParent::SetRequestOnMainThread(
    const nsAString& aValue, bool aSession, int64_t aExpires,
    const nsAString& aPath, int32_t aSameSite, bool aPartitioned,
    const nsID& aOperationID) {
  MOZ_ASSERT(NS_IsMainThread());
  AssertIsOnMainThread();
  nsresult rv;

  bool requireMatch = false;
  NS_ConvertUTF16toUTF8 domain(aDomain);
  nsAutoCString domainWithDot;

@@ -380,7 +379,6 @@ bool CookieStoreParent::SetRequestOnMainThread(
    if (NS_FAILED(rv)) {
      return false;
    }
    requireMatch = true;
  }
  domainWithDot.Append(domain);

@@ -415,35 +413,28 @@ bool CookieStoreParent::SetRequestOnMainThread(
  notificationWatcher->CallbackWhenNotified(aOperationID, notificationCb);

  OriginAttributes attrs(aOriginAttributes);

  nsCOMPtr<nsICookieValidation> validation;
  rv = service->AddNative(
      aCookieURI, domainWithDot, NS_ConvertUTF16toUTF8(aPath),
      NS_ConvertUTF16toUTF8(aName), NS_ConvertUTF16toUTF8(aValue),
      /* secure: */ true,
      /* http-only: */ false, aSession, aSession ? INT64_MAX : aExpires, &attrs,
      aSameSite, nsICookie::SCHEME_HTTPS, aPartitioned, /* from http: */ false,
      &aOperationID, [&](mozilla::net::CookieStruct& aCookieStruct) -> bool {
        AssertIsOnMainThread();

        RefPtr<CookieValidation> validation = CookieValidation::ValidateForHost(
            aCookieStruct, aCookieURI, domain, requireMatch, false);
        MOZ_ASSERT(validation);

        if (validation->Result() == nsICookieValidation::eOK) {
          return true;
        }
      &aOperationID, getter_AddRefs(validation));

  if (NS_WARN_IF(NS_FAILED(rv))) {
    if (rv == NS_ERROR_ILLEGAL_VALUE && validation &&
        CookieValidation::Cast(validation)->Result() !=
            nsICookieValidation::eOK) {
      RefPtr<ContentParent> contentParent = aParent->GetContentParent();
        if (!contentParent) {
          return false;
        }

      if (contentParent) {
        contentParent->KillHard(
            "CookieStore does not accept invalid cookies in the parent "
            "process");
        return false;
      });
      }
    }

  if (NS_WARN_IF(NS_FAILED(rv))) {
    return false;
  }

+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@
@BINPATH@/res/locale/layout/MediaDocument.properties
@BINPATH@/res/locale/layout/xmlparser.properties
@BINPATH@/res/locale/dom/dom.properties
@BINPATH@/res/locale/necko/necko.properties

#ifndef MOZ_ANDROID_EXCLUDE_FONTS
@BINPATH@/res/fonts/*
Loading