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

Update browser polyfill to include better error message #91

Closed
holm opened this issue Feb 24, 2021 · 3 comments
Closed

Update browser polyfill to include better error message #91

holm opened this issue Feb 24, 2021 · 3 comments

Comments

@holm
Copy link

holm commented Feb 24, 2021

We are currently seeing some rare instances of the error Invalid character in header field name in the wild.

The change in whatwg-fetch at JakeChampion/fetch#880 will provide us with a better error message, so we can try to understand why this happens. It would be great if the polyfill could be updated and a new version released.

Thanks.

@ThisIsMissEm
Copy link

ThisIsMissEm commented May 26, 2022

@holm I've just debugged this exact issue, and for us, it was because a header value included a \n / LF character, which the browser-ponyfill handles as being a new header, so:

content-length: 91\r\ncontent-type: application/json\r\nwww-authenticate: DPoP realm=\"Auth Server\"\nBearer realm=\"Auth Server\"\r\n

Get parsed into the following key/value pairs passed to header.append:

{ key: 'content-length', value: '91' }
{ key: 'content-type', value: 'application/json' }
{ key: 'www-authenticate', value: 'DPoP realm="Auth Server"' }
{ key: 'Bearer realm="Auth Server"', value: '' }

Though, I should note: I'm only seeing this in Firefox for some reason, where the ponyfill is being pulled in despite fetch being global there. I think this is because of 123b1a2 which seems to mean the polyfill is always used over the native fetch() implementation.

But basically, if you're encountering the Invalid character in header field name error, check that the header values do not include a \n character.

ThisIsMissEm added a commit to ThisIsMissEm/cross-fetch that referenced this issue May 26, 2022
I'm not sure why the code was written the way it is, but it appears to be forcing the polyfill to be used even in environments where the Fetch API exists natively, which isn't intentional and causes the bugs described in lquixada#91, lquixada#78, and lquixada#69.

The original commit and PR don't describe why the behaviour was changed: lquixada@123b1a2
bahlo pushed a commit to axiomhq/cross-fetch that referenced this issue Jun 3, 2022
I'm not sure why the code was written the way it is, but it appears to be forcing the polyfill to be used even in environments where the Fetch API exists natively, which isn't intentional and causes the bugs described in lquixada#91, lquixada#78, and lquixada#69.

The original commit and PR don't describe why the behaviour was changed: lquixada@123b1a2
bahlo pushed a commit to axiomhq/cross-fetch that referenced this issue Jun 3, 2022
I'm not sure why the code was written the way it is, but it appears to be forcing the polyfill to be used even in environments where the Fetch API exists natively, which isn't intentional and causes the bugs described in lquixada#91, lquixada#78, and lquixada#69.

The original commit and PR don't describe why the behaviour was changed: lquixada@123b1a2
@lquixada
Copy link
Owner

lquixada commented Jun 9, 2023

I've been working on version 4 of cross-fetch and the whatwg-fetch was updated to the latest version (3.6.2). If anyone's interested in checking it out, please run npm install [email protected] in your project to give it a try. Let me know if any issues come up.

@lquixada
Copy link
Owner

lquixada commented Jul 3, 2023

Version 4 has been officially released with [email protected]. Please check it out: npm install cross-fetch.

@lquixada lquixada closed this as completed Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants