Bug 2031299 - Fix DevTols cookie header serialization for long cookies, r=jdescottes,devtools-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D294007
This commit is contained in:
Andrea Marchesini
2026-04-14 16:07:47 +00:00
committed by jdescottes@mozilla.com
parent 9d0cd05260
commit 6bd724cdcf
3 changed files with 58 additions and 2 deletions
@@ -93,8 +93,8 @@ async function getFormDataSections(
* @return {object} a headers object with updated content payload
*/
async function fetchHeaders(headers, getLongString) {
for (const { value } of headers.headers) {
headers.headers.value = await getLongString(value);
for (const header of headers.headers) {
header.value = await getLongString(header.value);
}
return headers;
}
@@ -0,0 +1,54 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
fetchHeaders,
} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js");
add_task(async function test_fetchHeaders_resolves_long_string_values() {
const longCookieValue = "a=1; ".repeat(2001);
const mockLongStringGrip = {
type: "longString",
initial: longCookieValue.substring(0, 1000),
length: longCookieValue.length,
};
const headers = {
headers: [
{ name: "User-Agent", value: "Mozilla/5.0" },
{ name: "Cookie", value: mockLongStringGrip },
],
headersSize: 12345,
};
async function mockGetLongString(value) {
if (typeof value === "object" && value.type === "longString") {
return longCookieValue;
}
return value;
}
const result = await fetchHeaders(headers, mockGetLongString);
equal(
result.headers[0].value,
"Mozilla/5.0",
"Short string header value is preserved"
);
equal(
typeof result.headers[1].value,
"string",
"Long string Cookie header value is resolved to a string"
);
equal(
result.headers[1].value,
longCookieValue,
"Long string Cookie header value is correctly resolved to its full content"
);
});
@@ -8,6 +8,8 @@ run-if = [
["test_doc-utils.js"]
["test_request-utils-fetchHeaders.js"]
["test_request-utils-fetchNetworkUpdatePacket.js"]
["test_request-utils-js-getFormattedProtocol.js"]