Medium firefox Logic Error 🔧 Commit mapped

Overview

Medium
Severity
CVSS
No
Exploited ITW
Fixed
Fix Status
Impactmoderate
DescriptionSetting a nameless cookie with an equals sign in the value shadowed other cookies. Even if the nameless cookie was set over HTTP and the shadowed cookie included the <code>Secure</code> attribute.
ComponentNetworking
Bug ClassLogic Error
Tracker1964767
Fix commit17cf450fd383 (firefox) +19/-0
CISA KEVNot listed
CreditedUku Sõrmus
Disclosed2025-07-22

Changed Functions

FunctionChangeNotes
if
netwerk/cookie/CookieValidation.cpp
modified

Files Changed

  • modules/libpref/init/StaticPrefList.yaml
  • netwerk/cookie/CookieValidation.cpp
  • testing/web-platform/meta/cookies/name/name.html.ini
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
index ce9bd259a86..6cab7827923 100644
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -13136,6 +13136,12 @@
   value: true
   mirror: always
 
+# When true, Firefox will reject nameless cookies that contain `=` in value.
+- name: network.cookie.block_nameless_with_equal_char
+  type: RelaxedAtomicBool
+  value: true
+  mirror: always
+
 # If we should attempt to race the cache and network.
 - name: network.http.rcwn.enabled
   type: bool
diff --git a/netwerk/cookie/CookieValidation.cpp b/netwerk/cookie/CookieValidation.cpp
index f1d4147af97..004cb6e3422 100644
--- a/netwerk/cookie/CookieValidation.cpp
+++ b/netwerk/cookie/CookieValidation.cpp
@@ -547,10 +547,19 @@ bool CookieValidation::CheckValue(const CookieStruct& aCookieData) {
   const auto* start = aCookieData.value().BeginReading();
   const auto* end = aCookieData.value().EndReading();
 
+  bool shouldBlockEqualInNamelessCookie =
+      aCookieData.name().IsEmpty() &&
+      StaticPrefs::network_cookie_block_nameless_with_equal_char();
+
   auto charFilter = [&](unsigned char c) {
     if (StaticPrefs::network_cookie_blockUnicode() && c >= 0x80) {
       return true;
     }
+
+    if (c == '=' && shouldBlockEqualInNamelessCookie) {
+      return true;
+    }
+
     return std::find(std::begin(illegalCharacters), std::end(illegalCharacters),
                      c) != std::end(illegalCharacters);
   };
diff --git a/testing/web-platform/meta/cookies/name/name.html.ini b/testing/web-platform/meta/cookies/name/name.html.ini
index 39785c86831..cf11472bb02 100644
--- a/testing/web-platform/meta/cookies/name/name.html.ini
+++ b/testing/web-platform/meta/cookies/name/name.html.ini
@@ -3,3 +3,7 @@
     expected:
       if (os == "mac") and not debug: FAIL
       [FAIL, PASS]
+  [Set a nameless cookie (that has an = in its value)]
+    expected: FAIL
+  [Set a nameless cookie (that has multiple ='s in its value)]
+    expected: FAIL
Loading diff…

Regression Test / PoC

shipped with the fix
diff --git a/testing/web-platform/meta/cookies/name/name.html.ini b/testing/web-platform/meta/cookies/name/name.html.ini
index 39785c86831..cf11472bb02 100644
--- a/testing/web-platform/meta/cookies/name/name.html.ini
+++ b/testing/web-platform/meta/cookies/name/name.html.ini
@@ -3,3 +3,7 @@
     expected:
       if (os == "mac") and not debug: FAIL
       [FAIL, PASS]
+  [Set a nameless cookie (that has an = in its value)]
+    expected: FAIL
+  [Set a nameless cookie (that has multiple ='s in its value)]
+    expected: FAIL
Loading diff…