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]: Non-standard behavior: Electron alter the response header Content-Disposition #34916

Closed
3 tasks done
9percent opened this issue Jul 14, 2022 · 3 comments
Closed
3 tasks done

Comments

@9percent
Copy link

Preflight Checklist

Electron Version

17.4.10

What operating system are you using?

Windows

Operating System Version

Windows 11 with latest updates

What arch are you using?

x64

Last Known Working Electron version

15.3.0

Expected Behavior

If web server response a blob with file name specified in Content-Disposition with encoding, for example:
server response header include:
content-disposition: "attachment; filename*=UTF-8''filename.xlsx"
Electron should pass server response header Content-Disposition as it is in XMLHttpRequest so app JavaScript can handle it correctly, should not change it's value.

Actual Behavior

Due to the change in the PR: #31669
response header value content-disposition will be replaced if the value contains encoding info.
content-disposition: "attachment; filename*=UTF-8''filename.txt"
will be changed to:
content-disposition: "attachment; filename=\"filename.txt\""
If I inspect web request with dev tool, I can see the network panel shows the response header with original value, but in the JS XMLHttpRequest handler, I can only get the altered value instead, this should not happen as it is not expected when we need to handle the file name in the header with JS code.

Testcase Gist URL

No response

Additional Information

The commit:
24b02d6
The PR:
#31669
Some doc online:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

@isailaandrei
Copy link
Contributor

Hey, sharing repro steps to make this more actionable:

Electron Fiddle Code:
const {app, BrowserWindow} = require('electron')
function createWindow () {
app.on('session-created', session => {
session.webRequest.onHeadersReceived((details, callback) => {
console.log(details.responseHeaders);
callback({ responseHeaders: details.responseHeaders });
});
});
const mainWindow = new BrowserWindow({
width: 800,
height: 600
})
mainWindow.loadURL('http://localhost:1337/')
}
app.whenReady().then(createWindow);

Netcat command:
nc -l -p 1337 < http.txt

http.txt file:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Disposition: attachment; filename*=UTF-8''filename.txt
Content-Length: 3

foo

Result:
MicrosoftTeams-image

Although RFC6266 says both formats (with or without encoding) are valid, the version with encoding is newer and should have priority because it contains more information. So I agree it's somewhat unexpected behaviour for Electron to transform the new filename version to the old one.

@codebytere tagging you since you're the last one to touch that code, although I can see someone else actually introduced this content-disposition processing code. Curious to get your opinion on this. Thank you!

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Oct 25, 2022
@github-actions
Copy link
Contributor

This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2022
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

2 participants