Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error Redactor Case-Insensitive Matching #613

Merged
merged 2 commits into from
Apr 3, 2024
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
12 changes: 6 additions & 6 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@
}

export interface Headers {
[index: string]: any;

Check warning on line 122 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}
export type GaxiosPromise<T = any> = Promise<GaxiosResponse<T>>;

Check warning on line 124 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

export interface GaxiosXMLHttpRequest {
responseURL: string;
}

export interface GaxiosResponse<T = any> {

Check warning on line 130 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
config: GaxiosOptions;
data: T;
status: number;
Expand All @@ -149,7 +149,7 @@
* Optional method to override making the actual HTTP request. Useful
* for writing tests.
*/
adapter?: <T = any>(

Check warning on line 152 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
options: GaxiosOptions,
defaultAdapter: (options: GaxiosOptions) => GaxiosPromise<T>
) => GaxiosPromise<T>;
Expand All @@ -170,8 +170,8 @@
| 'TRACE'
| 'PATCH';
headers?: Headers;
data?: any;

Check warning on line 173 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
body?: any;

Check warning on line 174 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
/**
* The maximum size of the http response content in bytes allowed.
*/
Expand All @@ -182,13 +182,13 @@
maxRedirects?: number;
follow?: number;
multipart?: GaxiosMultipartOptions[];
params?: any;

Check warning on line 185 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
paramsSerializer?: (params: {[index: string]: string | number}) => string;
timeout?: number;
/**
* @deprecated ignored
*/
onUploadProgress?: (progressEvent: any) => void;

Check warning on line 191 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
responseType?:
| 'arraybuffer'
| 'blob'
Expand All @@ -202,7 +202,7 @@
retry?: boolean;
// Should be instance of https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
// interface. Left as 'any' due to incompatibility between spec and abort-controller.
signal?: any;

Check warning on line 205 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
size?: number;
/**
* Implementation of `fetch` to use when making the API call. By default,
Expand Down Expand Up @@ -240,7 +240,7 @@
*
* @experimental
*/
export type RedactableGaxiosResponse<T = any> = Pick<

Check warning on line 243 in src/common.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
GaxiosResponse<T>,
'config' | 'data' | 'headers'
>;
Expand Down Expand Up @@ -369,17 +369,17 @@

for (const key of Object.keys(headers)) {
// any casing of `Authentication`
if (/^authentication$/.test(key)) {
if (/^authentication$/i.test(key)) {
headers[key] = REDACT;
}

// any casing of `Authorization`
if (/^authorization$/.test(key)) {
if (/^authorization$/i.test(key)) {
headers[key] = REDACT;
}

// anything containing secret, such as 'client secret'
if (/secret/.test(key)) {
if (/secret/i.test(key)) {
headers[key] = REDACT;
}
}
Expand All @@ -394,9 +394,9 @@
const text = obj[key];

if (
/grant_type=/.test(text) ||
/assertion=/.test(text) ||
/secret/.test(text)
/grant_type=/i.test(text) ||
/assertion=/i.test(text) ||
/secret/i.test(text)
) {
obj[key] = REDACT;
}
Expand Down
23 changes: 16 additions & 7 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
GaxiosResponse,
GaxiosPromise,
} from '../src';
import {GAXIOS_ERROR_SYMBOL} from '../src/common';
import {GAXIOS_ERROR_SYMBOL, Headers} from '../src/common';
import {pkg} from '../src/util';
import qs from 'querystring';
import fs from 'fs';
Expand Down Expand Up @@ -772,8 +772,11 @@ describe('🎏 data handling', () => {

const config: GaxiosOptions = {
headers: {
authentication: 'My Auth',
authorization: 'My Auth',
Authentication: 'My Auth',
/**
* Ensure casing is properly handled
*/
AUTHORIZATION: 'My Auth',
'content-type': 'application/x-www-form-urlencoded',
random: 'data',
},
Expand Down Expand Up @@ -821,8 +824,8 @@ describe('🎏 data handling', () => {
assert(e.config.headers);
assert.deepStrictEqual(e.config.headers, {
...config.headers, // non-redactables should be present
authentication: REDACT,
authorization: REDACT,
Authentication: REDACT,
AUTHORIZATION: REDACT,
});

// config redactions - data
Expand All @@ -847,11 +850,17 @@ describe('🎏 data handling', () => {
// response redactions
assert(e.response);
assert.deepStrictEqual(e.response.config, e.config);
assert.deepStrictEqual(e.response.headers, {

const expectedHeaders: Headers = {
...responseHeaders, // non-redactables should be present
authentication: REDACT,
authorization: REDACT,
});
};

delete expectedHeaders['AUTHORIZATION'];
delete expectedHeaders['Authentication'];

assert.deepStrictEqual(e.response.headers, expectedHeaders);
assert.deepStrictEqual(e.response.data, {
...response, // non-redactables should be present
assertion: REDACT,
Expand Down
Loading