Skip to content

http: appendHeader() mutates the array passed to setHeader() #67526

Closed

Description

@Ethan-Arrowood

Version

v26.13.1

Platform

Darwin 27.2.0 Darwin Kernel Version 27.2.0: Wed Oct 14 23:44:56 PDT 2026; root:xnu-13432.41.4~25/RELEASE_ARM64_T6041 arm64

Subsystem

http, http2

What steps will reproduce the bug?

const http = require('node:http');

const opts = { method: 'GET', httpVersionMajor: 1, httpVersionMinor: 1 };

const res = new http.ServerResponse(opts);
const cookies = ['a=1'];
res.setHeader('Set-Cookie', cookies);
res.appendHeader('Set-Cookie', 'b=2');
console.log(cookies); // orig array is modified

const res2 = new http.ServerResponse(opts);
res2.setHeader('Set-Cookie', Object.freeze(['a=1']));
res2.appendHeader('Set-Cookie', 'b=2'); // throws an error trying to mutate the frozen array in previous line

How often does it reproduce? Is there a required condition?

This bug occurs anytime an array is passed to setHeader() or to appendHeader() on a header that isn't set yet.

What is the expected behavior? Why is that the expected behavior?

From the code example, cookies stays [ 'a=1' ], and appending to a frozen array works. appendHeader() should change the response's headers, not the array I passed in. setHeader() accepts a frozen array, so a later appendHeader() shouldn't throw either.

What do you see instead?

[ 'a=1', 'b=2' ]
TypeError: Cannot add property 1, object is not extensible

Additional information

I have a fix and am opening a PR momentarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions