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

[Bug]: Electron net.fetch can't handle non-ASCII characters in headers #42244

Open
3 tasks done
shadaxv opened this issue May 22, 2024 · 0 comments
Open
3 tasks done

[Bug]: Electron net.fetch can't handle non-ASCII characters in headers #42244

shadaxv opened this issue May 22, 2024 · 0 comments
Labels
30-x-y 31-x-y bug 🪲 component/net has-repro-gist Issue can be reproduced with code at https://gist.github.com/ status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@shadaxv
Copy link

shadaxv commented May 22, 2024

Preflight Checklist

Electron Version

30.0.6

What operating system are you using?

Windows

Operating System Version

Windows 10 22H2 19045.4291

What arch are you using?

x64

Last Known Working Electron version

Unknown

Expected Behavior

Electron should encode unsupported characters in HTTP headers so that they do not cause uncaught errors

Actual Behavior

Electron does not check HTTP headers, and because of this, Node.js throws unexpected errors. This can be worked around by encoding headers in webRequest.onHeadersReceived, but it won't work, for example, on a modified User Agent.

When net.fetch is replaced with the regular fetch from Node.js, this issue does not occur for HTTP requests (just like in web browsers). Unfortunately, in Node.js, it is not possible to set non-ASCII headers, and I cannot demonstrate this example.

I understand that using non-ASCII headers is against the HTTP standard, but sometimes servers send such headers (e.g., when a file being downloaded has a non-standard name and that name is placed in the header), and developers using Electron cannot cover all cases (such as a wrong User Agent).

image

Testcase Gist URL

https://gist.github.com/shadaxv/742cd824de5a8dfc7893c40432ee4ce1

Additional Information

There was a similar ticket, but it was closed, I am sending this as a new issue to better mark the details in the template

#39469

webRequest.onHeadersReceived workaround:

// Electron's net.fetch does not support non-ASCII characters in the headers
for (const [key, value] of Object.entries(responseHeaders)) {
  // normalize and convert all non-ASCII characters to ASCII using Buffer
  responseHeaders[key] = value.map((entry) => {
    const normalized = entry.normalize("NFKD");
    const buffer = Buffer.from(normalized, "utf8");
    return buffer.toString("ascii");
  });
}
@electron-issue-triage electron-issue-triage bot added 30-x-y has-repro-gist Issue can be reproduced with code at https://gist.github.com/ labels May 22, 2024
@clavin clavin added status/confirmed A maintainer reproduced the bug or agreed with the feature 31-x-y component/net labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30-x-y 31-x-y bug 🪲 component/net has-repro-gist Issue can be reproduced with code at https://gist.github.com/ status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
Status: 👍 Does Not Block Stable
Status: 👍 Does Not Block Stable
Development

No branches or pull requests

2 participants