0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/parallel/test-util-internal.js
Jose M. Palacios Diaz 916cfeca77
lib,src: audit process.env in lib/ for setuid binary
Wrap SafeGetenv() in util binding with the purpose of protecting
the cases when env vars are accessed with the privileges of another
user in jsland.

PR-URL: https://github.com/nodejs/node/pull/18511
Fixes: https://github.com/nodejs/node/issues/9160
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-02-16 17:42:21 +01:00

44 lines
918 B
JavaScript

'use strict';
// Flags: --expose_internals
require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const {
getHiddenValue,
setHiddenValue,
arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex,
safeGetenv
} = process.binding('util');
for (const oneEnv in process.env) {
assert.strictEqual(
safeGetenv(oneEnv),
process.env[oneEnv]
);
}
assert.strictEqual(
getHiddenValue({}, kArrowMessagePrivateSymbolIndex),
undefined);
const obj = {};
assert.strictEqual(
setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'),
true);
assert.strictEqual(
getHiddenValue(obj, kArrowMessagePrivateSymbolIndex),
'bar');
let arrowMessage;
try {
require(fixtures.path('syntax', 'bad_syntax'));
} catch (err) {
arrowMessage =
getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
}
assert(/bad_syntax\.js:1/.test(arrowMessage));