From 156549d8ffa8ec3d5015ce81574c6119bfdc9934 Mon Sep 17 00:00:00 2001 From: Roee Kasher Date: Wed, 19 Jul 2017 06:30:07 +0300 Subject: [PATCH] http: disable OutgoingMessage pipe method OutgoingMessage should be a write-only stream, and it shouldn't be piped. This commit disables the `pipe` method by throwing an exception (if this method is called). PR-URL: https://github.com/nodejs/node/pull/14358 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Gireesh Punathil --- lib/_http_outgoing.js | 4 ++++ test/parallel/test-outgoing-message-pipe.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/parallel/test-outgoing-message-pipe.js diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 1c570284ef5ccb..7a63406d51575b 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -889,6 +889,10 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() { this.flushHeaders(); }, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001'); +OutgoingMessage.prototype.pipe = function pipe() { + // OutgoingMessage should be write-only. Piping from it is disabled. + this.emit('error', new Error('Cannot pipe, not readable')); +}; module.exports = { OutgoingMessage diff --git a/test/parallel/test-outgoing-message-pipe.js b/test/parallel/test-outgoing-message-pipe.js new file mode 100644 index 00000000000000..2030d8f43b09be --- /dev/null +++ b/test/parallel/test-outgoing-message-pipe.js @@ -0,0 +1,15 @@ +'use strict'; +const assert = require('assert'); +const common = require('../common'); +const OutgoingMessage = require('_http_outgoing').OutgoingMessage; + +// Verify that an error is thrown upon a call to `OutgoingMessage.pipe`. + +const outgoingMessage = new OutgoingMessage(); +assert.throws( + common.mustCall(() => { outgoingMessage.pipe(outgoingMessage); }), + (err) => { + return ((err instanceof Error) && /Cannot pipe, not readable/.test(err)); + }, + 'OutgoingMessage.pipe should throw an error' +);