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

Conversation

danielcooperxyz
Copy link
Contributor

@danielcooperxyz danielcooperxyz commented Nov 20, 2023

We have experienced issues with the latest version of axios (1.6.3) passing through bad header objects which are not of the correct type which causes the below error from the transformRequest method in axios.

ERROR TypeError: t.getContentType is not a function at Oe.transformRequest

This PR includes a new line that will wrap the header object each time regardless of what is passed, to enforce that the correct type is then passed to the transformRequest transformer function.

Fixes #1250

@snoblenet
Copy link

hi @danielcooperxyz -- thanks for these changes -- it looks like a build is expected?

@snoblenet
Copy link

and in the mean time, how are you including this in your package.json?

@loukmane-issa
Copy link

and in the mean time, how are you including this in your package.json?

Did you get any chance at all with this? I'm experiencing the same issue and it would be a shame to have to write my own :(

Comment on lines -133 to +134
const { data, headers, method } = config;
const { data, method } = config;
const headers = new AxiosHeaders(config.headers);
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.

@BourgoisMickael
Copy link

If a maintainer could look into this quickly, it would be nice. It's just a oneliner.

Here is a workaround in the meantime:

axios.interceptors.request.use(async req => {
    const signedReq = await interceptor(req);
    signedReq.headers = new axios.AxiosHeaders(signedReq.headers);
    return signedReq;
});

@jamesmbourne
Copy link
Owner

Hey @danielcooperxyz, thanks for putting this fix in. I'll try and get this merged & released today 🤞

@jamesmbourne jamesmbourne merged commit 0f4f975 into jamesmbourne:main Feb 11, 2024
0 of 2 checks passed
Copy link

🎉 This PR is included in version 3.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jamesmbourne jamesmbourne changed the title Wrap headers with AxiosHeaders to prevent incorrect type being passed fix: Wrap headers with AxiosHeaders to prevent incorrect type being passed Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: t.getContentType is not a function at Oe.transformRequest
5 participants