Skip to content
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
17 changes: 14 additions & 3 deletions lib/ecstatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,20 @@ var ecstatic = module.exports = function (dir, options) {
return false;
}

// If any of the headers provided don't match, then don't return 304
if (modifiedSince && (new Date(Date.parse(modifiedSince))) < stat.mtime) {
return false;
// Catch "illegal access" dates that will crash v8
if (modifiedSince) {
try {
var modifiedDate = new Date(Date.parse(modifiedSince));
}
catch (err) { return false }

if (modifiedDate.toString() === 'Invalid Date') {
return false;
}
// If any of the headers provided don't match, then don't return 304
if (modifiedDate < stat.mtime) {
return false;
}
}

if (clientEtag) {
Expand Down
24 changes: 24 additions & 0 deletions test/illegal-access-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var test = require('tap').test,
ecstatic = require('../lib/ecstatic'),
http = require('http'),
path = require('path'),
request = require('request');

test('if-modified-since illegal access date', function (t) {
var dir = path.join(__dirname, 'public');
var server = http.createServer(ecstatic(dir))

t.plan(2);

server.listen(0, function () {
var opts = {
url: 'http://localhost:' + server.address().port + '/a.txt',
headers: { 'if-modified-since': '275760-09-24' }
};
request.get(opts, function (err, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
server.close(function() { t.end(); });
});
});
});