Skip to content

Commit da84c08

Browse files
authored
feat(sanitization): Redact 'Cookie' request header by default (#4815)
This is done by adding 'cookie' to the sanitizeFieldNames default set. Refs: #4006
1 parent 255146c commit da84c08

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

docs/reference/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ require('elastic-apm-node').start({
751751
## `sanitizeFieldNames` [sanitize-field-names]
752752

753753
* **Type:** Array
754-
* **Default:** `['password', 'passwd', 'pwd', 'secret', '*key', '*token*', '*session*', '*credit*', '*card*', '*auth*', 'set-cookie', '*principal*', 'pw', 'pass', 'connect.sid']`
754+
* **Default:** `['password', 'passwd', 'pwd', 'secret', '*key', '*token*', '*session*', '*credit*', '*card*', '*auth*', 'set-cookie', '*principal*', 'pw', 'pass', 'connect.sid', 'cookie']`
755755
* **Env:** `ELASTIC_APM_SANITIZE_FIELD_NAMES`
756756
* [![dynamic config](images/dynamic-config.svg "") ](/reference/configuring-agent.md#dynamic-configuration) **Central config name:** `sanitize_field_names`
757757

docs/release-notes/index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,40 @@ To check for security updates, go to [Security announcements for the Elastic sta
2626
%
2727
% ### Fixes [next-fixes]
2828

29+
## Next [next]
30+
% **Release date:** Month day, year
31+
32+
### Features and enhancements [next-features-enhancements]
33+
34+
* Redact the `Cookie` HTTP request header by default, because it is often sensitive.
35+
36+
The `Cookie` pattern has been added to the [`sanitizeFieldNames`](/reference/configuration.md#sanitize-field-names) configuration variable. This means that when headers are captured (if `captureHeaders` is enabled, as it is by default), the `Cookie` header will be fully redacted:
37+
38+
```
39+
http.request.headers.cookie: "[REDACTED]"
40+
```
41+
42+
The result in earlier versions was to parse the Cookie header and redact only those fields that matched patterns in `sanitizeFieldNames`, for example:
43+
44+
```
45+
http.request.headers.cookie: "foo=bar; sessionid=REDACTED"
46+
```
47+
48+
To restore the previous behavior, specify a `sanitizeFieldNames` configuration value that does *not* include 'cookie'. For example:
49+
50+
```js
51+
require('elastic-apm-node').start({
52+
// ...
53+
sanitizeFieldNames: ['password', 'passwd', 'pwd', 'secret', '*key', '*token*', '*session*', '*credit*', '*card*', '*auth*', 'set-cookie', '*principal*', 'pw', 'pass', 'connect.sid']
54+
});
55+
```
56+
57+
or:
58+
59+
```
60+
export ELASTIC_APM_SANITIZE_FIELD_NAMES=password,passwd,pwd,secret,*key,*token*,*session*,*credit*,*card*,*auth*,set-cookie,*principal*,pw,pass,connect.sid
61+
```
62+
2963
## 4.14.0 [4-14-0]
3064
**Release date:** Sep 25, 2025
3165

lib/config/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ const CONFIG_SCHEMA = [
324324
'pw',
325325
'pass',
326326
'connect.sid',
327+
// Additional ones added to the Node.js APM agent.
328+
'cookie', // The "Cookie" HTTP request header is often sensitive.
327329
],
328330
envVar: 'ELASTIC_APM_SANITIZE_FIELD_NAMES',
329331
centralConfigName: 'sanitize_field_names',

test/instrumentation/transaction.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ test('#_encode() - http request meta data', function (t) {
584584
host: 'example.com',
585585
'user-agent': 'user-agent-header',
586586
'content-length': 42,
587-
cookie: 'cookie1=foo; cookie2=bar; session-id=REDACTED',
587+
cookie: '[REDACTED]',
588588
'x-foo': 'bar',
589589
'x-bar': 'baz',
590590
},

test/sanitize-field-names/_fixtures.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = [
5959
'set-cookie': 'twelve',
6060
'X-Authy-Thing': 'thirteen',
6161
'X-Ms-Client-Principal': 'fourteen',
62+
Cookie: 'fifteen=value',
6263
keepmeRequest: 'request',
6364
},
6465
responseHeaders: {
@@ -76,6 +77,7 @@ module.exports = [
7677
'set-cookie': 'twelve',
7778
'X-Authy-Thing': 'thirteen',
7879
'X-Ms-Client-Principal': 'fourteen',
80+
Cookie: 'fifteen=value',
7981
keepmeResponse: 'response',
8082
},
8183
formFields: {
@@ -93,6 +95,7 @@ module.exports = [
9395
'set-cookie': 'twelve',
9496
'X-Authy-Thing': 'thirteen',
9597
'X-Ms-Client-Principal': 'fourteen',
98+
Cookie: 'fifteen',
9699
keepmeForm: 'formFields',
97100
},
98101
},
@@ -113,6 +116,7 @@ module.exports = [
113116
'set-cookie',
114117
'X-Authy-Thing',
115118
'X-Ms-Client-Principal',
119+
'Cookie',
116120
],
117121
defined: { keepmeRequest: 'request' },
118122
},
@@ -132,6 +136,7 @@ module.exports = [
132136
'set-cookie',
133137
'X-Authy-Thing',
134138
'X-Ms-Client-Principal',
139+
'Cookie',
135140
],
136141
defined: { keepmeResponse: 'response' },
137142
},
@@ -151,6 +156,7 @@ module.exports = [
151156
'set-cookie',
152157
'X-Authy-Thing',
153158
'X-Ms-Client-Principal',
159+
'Cookie',
154160
],
155161
defined: { keepmeForm: 'formFields' },
156162
},
@@ -176,6 +182,7 @@ module.exports = [
176182
'set-cookie': 'twelve',
177183
'X-Authy-Thing': 'thirteen',
178184
'X-Ms-Client-Principal': 'fourteen',
185+
Cookie: 'fifteen=value',
179186
keepmeRequest: 'request',
180187
},
181188
responseHeaders: {
@@ -193,6 +200,7 @@ module.exports = [
193200
'set-cookie': 'twelve',
194201
'X-Authy-Thing': 'thirteen',
195202
'X-Ms-Client-Principal': 'fourteen',
203+
Cookie: 'fifteen=value',
196204
keepmeResponse: 'response',
197205
},
198206
formFields: {
@@ -210,6 +218,7 @@ module.exports = [
210218
'set-cookie': 'twelve',
211219
'X-Authy-Thing': 'thirteen',
212220
'X-Ms-Client-Principal': 'fourteen',
221+
Cookie: 'fifteen',
213222
keepmeForm: 'formFields',
214223
},
215224
},
@@ -230,6 +239,7 @@ module.exports = [
230239
'set-cookie',
231240
'X-Authy-Thing',
232241
'X-Ms-Client-Principal',
242+
'Cookie',
233243
],
234244
defined: { keepmeRequest: 'request' },
235245
},
@@ -249,6 +259,7 @@ module.exports = [
249259
'set-cookie',
250260
'X-Authy-Thing',
251261
'X-Ms-Client-Principal',
262+
'Cookie',
252263
],
253264
defined: { keepmeResponse: 'response' },
254265
},
@@ -268,6 +279,7 @@ module.exports = [
268279
'set-cookie',
269280
'X-Authy-Thing',
270281
'X-Ms-Client-Principal',
282+
'Cookie',
271283
],
272284
defined: { keepmeForm: 'formFields' },
273285
},

0 commit comments

Comments
 (0)