src: make StreamBase prototype accessors robust · nodejs/node@f7411b5 · GitHub
Skip to content

Commit f7411b5

Browse files
joyeecheungMylesBorins
authored andcommitted
src: make StreamBase prototype accessors robust
This PR makes the prototype accessors added by StreamBase::AddMethods nonenumerable and checks the signatures in the accessors so they throw instead of raising assertions when called with incompatible receivers. They could be enumerated when inspecting the prototype with util.inspect or the inspector protocol. PR-URL: #16860 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0d4f62c commit f7411b5

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/stream_base-inl.h

Lines changed: 11 additions & 4 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// This tests that the prototype accessors added by StreamBase::AddMethods
6+
// are not enumerable. They could be enumerated when inspecting the prototype
7+
// with util.inspect or the inspector protocol.
8+
9+
const assert = require('assert');
10+
11+
// Or anything that calls StreamBase::AddMethods when setting up its prototype
12+
const TTY = process.binding('tty_wrap').TTY;
13+
14+
{
15+
assert.strictEqual(TTY.prototype.propertyIsEnumerable('bytesRead'), false);
16+
assert.strictEqual(TTY.prototype.propertyIsEnumerable('fd'), false);
17+
assert.strictEqual(
18+
TTY.prototype.propertyIsEnumerable('_externalStream'), false);
19+
}
Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)