-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http,https: protect against slow headers attack
CVE-2018-12122 An attacker can send a char/s within headers and exahust the resources (file descriptors) of a system even with a tight max header length protection. This PR destroys a socket if it has not received the headers in 40s. PR-URL: nodejs-private/node-private#144 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
8 changed files
with
182 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { createServer } = require('http'); | ||
const { connect } = require('net'); | ||
const { finished } = require('stream'); | ||
|
||
// This test validates that the 'timeout' event fires | ||
// after server.headersTimeout. | ||
|
||
const headers = | ||
'GET / HTTP/1.1\r\n' + | ||
'Host: localhost\r\n' + | ||
'Agent: node\r\n'; | ||
|
||
const server = createServer(common.mustNotCall()); | ||
let sendCharEvery = 1000; | ||
|
||
// 40 seconds is the default | ||
assert.strictEqual(server.headersTimeout, 40 * 1000); | ||
|
||
// Pass a REAL env variable to shortening up the default | ||
// value which is 40s otherwise this is useful for manual | ||
// testing | ||
if (!process.env.REAL) { | ||
sendCharEvery = common.platformTimeout(10); | ||
server.headersTimeout = 2 * sendCharEvery; | ||
} | ||
|
||
server.once('timeout', common.mustCall((socket) => { | ||
socket.destroy(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = connect(server.address().port); | ||
client.write(headers); | ||
client.write('X-CRASH: '); | ||
|
||
const interval = setInterval(() => { | ||
client.write('a'); | ||
}, sendCharEvery); | ||
|
||
client.resume(); | ||
|
||
finished(client, common.mustCall((err) => { | ||
clearInterval(interval); | ||
server.close(); | ||
})); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { readKey } = require('../common/fixtures'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const { createServer } = require('https'); | ||
const { connect } = require('tls'); | ||
const { finished } = require('stream'); | ||
|
||
// This test validates that the 'timeout' event fires | ||
// after server.headersTimeout. | ||
|
||
const headers = | ||
'GET / HTTP/1.1\r\n' + | ||
'Host: localhost\r\n' + | ||
'Agent: node\r\n'; | ||
|
||
const server = createServer({ | ||
key: readKey('agent1-key.pem'), | ||
cert: readKey('agent1-cert.pem'), | ||
ca: readKey('ca1-cert.pem'), | ||
}, common.mustNotCall()); | ||
|
||
let sendCharEvery = 1000; | ||
|
||
// 40 seconds is the default | ||
assert.strictEqual(server.headersTimeout, 40 * 1000); | ||
|
||
// pass a REAL env variable to shortening up the default | ||
// value which is 40s otherwise | ||
// this is useful for manual testing | ||
if (!process.env.REAL) { | ||
sendCharEvery = common.platformTimeout(10); | ||
server.headersTimeout = 2 * sendCharEvery; | ||
} | ||
|
||
server.once('timeout', common.mustCall((socket) => { | ||
socket.destroy(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = connect({ | ||
port: server.address().port, | ||
rejectUnauthorized: false | ||
}); | ||
client.write(headers); | ||
client.write('X-CRASH: '); | ||
|
||
const interval = setInterval(() => { | ||
client.write('a'); | ||
}, sendCharEvery); | ||
|
||
client.resume(); | ||
|
||
finished(client, common.mustCall((err) => { | ||
clearInterval(interval); | ||
server.close(); | ||
})); | ||
})); |