Skip to content

Commit 2e9650c

Browse files
fix: Error Redactor Case-Insensitive Matching (#613)
1 parent def4ec9 commit 2e9650c

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

core/packages/gaxios/src/common.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,17 @@ export function defaultErrorRedactor<T = any>(data: {
369369

370370
for (const key of Object.keys(headers)) {
371371
// any casing of `Authentication`
372-
if (/^authentication$/.test(key)) {
372+
if (/^authentication$/i.test(key)) {
373373
headers[key] = REDACT;
374374
}
375375

376376
// any casing of `Authorization`
377-
if (/^authorization$/.test(key)) {
377+
if (/^authorization$/i.test(key)) {
378378
headers[key] = REDACT;
379379
}
380380

381381
// anything containing secret, such as 'client secret'
382-
if (/secret/.test(key)) {
382+
if (/secret/i.test(key)) {
383383
headers[key] = REDACT;
384384
}
385385
}
@@ -394,9 +394,9 @@ export function defaultErrorRedactor<T = any>(data: {
394394
const text = obj[key];
395395

396396
if (
397-
/grant_type=/.test(text) ||
398-
/assertion=/.test(text) ||
399-
/secret/.test(text)
397+
/grant_type=/i.test(text) ||
398+
/assertion=/i.test(text) ||
399+
/secret/i.test(text)
400400
) {
401401
obj[key] = REDACT;
402402
}

core/packages/gaxios/test/test.getch.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
GaxiosResponse,
2727
GaxiosPromise,
2828
} from '../src';
29-
import {GAXIOS_ERROR_SYMBOL} from '../src/common';
29+
import {GAXIOS_ERROR_SYMBOL, Headers} from '../src/common';
3030
import {pkg} from '../src/util';
3131
import qs from 'querystring';
3232
import fs from 'fs';
@@ -772,8 +772,11 @@ describe('🎏 data handling', () => {
772772

773773
const config: GaxiosOptions = {
774774
headers: {
775-
authentication: 'My Auth',
776-
authorization: 'My Auth',
775+
Authentication: 'My Auth',
776+
/**
777+
* Ensure casing is properly handled
778+
*/
779+
AUTHORIZATION: 'My Auth',
777780
'content-type': 'application/x-www-form-urlencoded',
778781
random: 'data',
779782
},
@@ -821,8 +824,8 @@ describe('🎏 data handling', () => {
821824
assert(e.config.headers);
822825
assert.deepStrictEqual(e.config.headers, {
823826
...config.headers, // non-redactables should be present
824-
authentication: REDACT,
825-
authorization: REDACT,
827+
Authentication: REDACT,
828+
AUTHORIZATION: REDACT,
826829
});
827830

828831
// config redactions - data
@@ -847,11 +850,17 @@ describe('🎏 data handling', () => {
847850
// response redactions
848851
assert(e.response);
849852
assert.deepStrictEqual(e.response.config, e.config);
850-
assert.deepStrictEqual(e.response.headers, {
853+
854+
const expectedHeaders: Headers = {
851855
...responseHeaders, // non-redactables should be present
852856
authentication: REDACT,
853857
authorization: REDACT,
854-
});
858+
};
859+
860+
delete expectedHeaders['AUTHORIZATION'];
861+
delete expectedHeaders['Authentication'];
862+
863+
assert.deepStrictEqual(e.response.headers, expectedHeaders);
855864
assert.deepStrictEqual(e.response.data, {
856865
...response, // non-redactables should be present
857866
assertion: REDACT,

0 commit comments

Comments
 (0)