Skip to content

Commit a035634

Browse files
author
Stefan Teneff
committed
fixes #1706
When the client sends authorization header and the configuration options have `auth`, the authorization header is not sent to the upstream. This way the http-proxy will behave based on the configuration provided, not the data sent from client
1 parent 9b96cd7 commit a035634

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/http-proxy/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
4747
}
4848

4949
if (options.auth) {
50+
delete outgoing.headers.authorization;
5051
outgoing.auth = options.auth;
5152
}
5253

test/lib-http-proxy-passes-web-incoming-test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,40 @@ describe('#createProxyServer.web() using own http server', function () {
453453
http.request('http://127.0.0.1:8081', function() {}).end();
454454
});
455455

456+
describe("with an authorization header from client", function () {
457+
const headers = {
458+
'authorization': "Bearer " + new Buffer("mock-jwt-token").toString('base64'),
459+
};
460+
461+
it.only("should proxy the request with the Authorization header set", function (done) {
462+
var proxy = httpProxy.createProxyServer({
463+
target: "http://127.0.0.1:8080",
464+
auth: "user:pass",
465+
});
466+
467+
function requestHandler(req, res) {
468+
proxy.web(req, res);
469+
}
470+
471+
var proxyServer = http.createServer(requestHandler);
472+
473+
var source = http.createServer(function (req, res) {
474+
source.close();
475+
proxyServer.close();
476+
var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64');
477+
expect(req.method).to.eql("GET");
478+
expect(auth.toString()).to.eql("user:pass");
479+
done();
480+
});
481+
482+
proxyServer.listen("8081");
483+
source.listen("8080");
484+
485+
http.request("http://127.0.0.1:8081", { headers }, function () {}).end();
486+
});
487+
});
488+
489+
456490
it('should proxy requests to multiple servers with different options', function (done) {
457491
var proxy = httpProxy.createProxyServer();
458492

0 commit comments

Comments
 (0)