Skip to content

Commit

Permalink
Bugfix: Trap exceptions in URIParser.
Browse files Browse the repository at this point in the history
A user was able to crash chat.tinyclouds.org by sending it a malformed URL!
Not good.
  • Loading branch information
ry committed Sep 4, 2009
1 parent 734e86b commit 9dbd924
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ node.http.parseUri = function (str) {
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) {
var key = decode($1);
var val = decode($2);
try {
var key = decode($1);
var val = decode($2);
} catch (e) {
return;
}
uri[o.q.name][key] = val;
}
});
Expand Down
31 changes: 31 additions & 0 deletions test/mjsunit/test-http-malformed-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include("mjsunit.js");

// Make sure no exceptions are thrown when receiving malformed HTTP
// requests.
port = 9999;

nrequests_completed = 0;
nrequests_expected = 1;

var s = node.http.createServer(function (req, res) {
puts("req: " + JSON.stringify(req.uri));

res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody("Hello World");
res.finish();

if (++nrequests_completed == nrequests_expected) s.close();
});
s.listen(port);

var c = node.tcp.createConnection(port);
c.addListener("connect", function () {
c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
c.close();
});

// TODO add more!

process.addListener("exit", function () {
assertEquals(nrequests_expected, nrequests_completed);
});

0 comments on commit 9dbd924

Please sign in to comment.