Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/node/src/requestdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ export function extractRequestData(
switch (key) {
case 'headers': {
requestData.headers = headers;

// Remove the Cookie header in case cookie data should not be included in the event
if (!include.includes('cookies')) {
delete (requestData.headers as { cookie?: string }).cookie;
}

break;
}
case 'method': {
Expand Down
31 changes: 31 additions & 0 deletions packages/node/test/requestdata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,37 @@ describe.each([oldExtractRequestData, newExtractRequestData])(
});
});

describe('headers', () => {
it('removes the `Cookie` header from requestdata.headers, if `cookies` is not set in the options', () => {
const mockReq = {
cookies: { foo: 'bar' },
headers: { cookie: 'foo=bar', otherHeader: 'hello' },
};
const optionsWithCookies = ['headers'];

const [req, options] = formatArgs(fn, mockReq, optionsWithCookies);

expect(fn(req, options as any)).toStrictEqual({
headers: { otherHeader: 'hello' },
});
});

it('includes the `Cookie` header in requestdata.headers, if `cookies` is not set in the options', () => {
const mockReq = {
cookies: { foo: 'bar' },
headers: { cookie: 'foo=bar', otherHeader: 'hello' },
};
const optionsWithCookies = ['headers', 'cookies'];

const [req, options] = formatArgs(fn, mockReq, optionsWithCookies);

expect(fn(req, options as any)).toStrictEqual({
headers: { otherHeader: 'hello', cookie: 'foo=bar' },
cookies: { foo: 'bar' },
});
});
});

describe('cookies', () => {
it('uses `req.cookies` if available', () => {
const mockReq = {
Expand Down