Skip to content

[connectors/http] prevent errors caused by multi-byte characters in paths #756

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

Merged
merged 3 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/connectors/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var qs = require('querystring');
var AgentKeepAlive = require('agentkeepalive');
var ConnectionAbstract = require('../connection');
var zlib = require('zlib');
var INVALID_PATH_REGEX = /[^\u0021-\u00ff]/

/**
* Connector used to talk to an elasticsearch node via HTTP
Expand Down Expand Up @@ -166,6 +167,11 @@ HttpConnector.prototype.request = function (params, cb) {
}
}, this);

if (INVALID_PATH_REGEX.test(reqParams.path) === true) {
cb(new TypeError('ERR_UNESCAPED_CHARACTERS: ' + reqParams.path))
return function () {}
}

request = this.hand.request(reqParams, function (_incoming) {
incoming = _incoming;
status = incoming.statusCode;
Expand Down
11 changes: 11 additions & 0 deletions test/unit/specs/http_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ describe('Http Connector', function () {
done();
});
});

it('calls back with error when http.request throws an error', function (done) {
var con = new HttpConnection(new Host('http://google.com/thisisinvalid\uffe2'));

stub(con.log, 'error');

con.request({}, function (err) {
expect(err.message).to.eql('ERR_UNESCAPED_CHARACTERS: /thisisinvalid\uffe2');
done();
});
});
});

describe('#request with incomming message error', function () {
Expand Down