fix: webRequest.onBeforeSendHeaders not being able to modify reserved headers (#49242)

* fix: `webRequest.onBeforeSendHeaders` not being able to modify reserved headers

Co-authored-by: Samuel Attard <sattard@anthropic.com>

* chore: add unit test for reserved header

Co-authored-by: Samuel Attard <sattard@anthropic.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <sattard@anthropic.com>
This commit is contained in:
trop[bot]
2026-01-05 16:30:50 -05:00
committed by GitHub
parent d8687cfc9d
commit ade4c00984
3 changed files with 41 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import { ipcMain, protocol, session, WebContents, webContents } from 'electron/main';
import { ipcMain, net, protocol, session, WebContents, webContents } from 'electron/main';
import { expect } from 'chai';
import * as WebSocket from 'ws';
@@ -455,6 +455,35 @@ describe('webRequest module', () => {
}));
expect(onSendHeadersCalled).to.be.true();
});
it('can inject Proxy-Authorization header for net module requests', async () => {
// Proxy-Authorization is normally rejected by Chromium's network service
// for security reasons. However, for Electron's trusted net module,
// webRequest.onBeforeSendHeaders should be able to inject it via the
// TrustedHeaderClient code path.
const proxyAuthValue = 'Basic test-credentials';
let receivedProxyAuth: string | undefined;
const server = http.createServer((req, res) => {
receivedProxyAuth = req.headers['proxy-authorization'];
res.end('ok');
});
const { url: serverUrl } = await listen(server);
try {
ses.webRequest.onBeforeSendHeaders((details, callback) => {
const requestHeaders = details.requestHeaders;
requestHeaders['Proxy-Authorization'] = proxyAuthValue;
callback({ requestHeaders });
});
const response = await net.fetch(serverUrl, { bypassCustomProtocolHandlers: true });
expect(response.ok).to.be.true();
expect(receivedProxyAuth).to.equal(proxyAuthValue);
} finally {
server.close();
}
});
});
describe('webRequest.onSendHeaders', () => {