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: Wrap headers with AxiosHeaders to prevent incorrect type being passed #1248

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
Record<string, string>
>;

const removeUndefined = (obj: Record<string, any>) => {

Check warning on line 73 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 73 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type
const newObj: Record<string, any> = {};

Check warning on line 74 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 74 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

for (const [key, value] of Object.entries(obj)) {
if (value !== undefined) {
Expand All @@ -94,7 +94,7 @@
* @param options The options to be used when signing a request
* @param credentials Credentials to be used to sign the request
*/
export const aws4Interceptor = <D = any>({

Check warning on line 97 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 97 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type
instance = axios,
credentials,
options,
Expand Down Expand Up @@ -130,7 +130,8 @@
}

const { host, pathname, search } = new URL(url);
const { data, headers, method } = config;
const { data, method } = config;
const headers = new AxiosHeaders(config.headers);
Comment on lines -133 to +134
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't fix the bug everywhere, you should fix the actual headers when they are set at line 170:

https://github.com/jamesmbourne/aws4-axios/pull/1248/files#diff-bc2f1f907be8c49520a585dda7f0c100645e31e9bedf3828c3850fdf8389e619R170

config.headers = signingOptions.headers as AxiosHeaders;

This should not be casted but should be a real AxiosHeaders instance. Otherwise this lib will still break axios for every other uses outside this lib.


const transformRequest = getTransformer(config);

Expand All @@ -149,7 +150,7 @@
put,
patch,
...headersToSign
} = headers as any as InternalAxiosHeaders;

Check warning on line 153 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 153 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type
// Axios type definitions do not match the real shape of this object

const signingOptions: AWS4Request = {
Expand All @@ -160,7 +161,7 @@
service: options?.service,
signQuery: options?.signQuery,
body: transformedData,
headers: removeUndefined(headersToSign) as any,

Check warning on line 164 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 164 in src/interceptor.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type
};

const resolvedCredentials = await credentialsProvider.getCredentials();
Expand Down