|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// The permission model resolves paths to avoid path traversals, but in doing so |
| 4 | +// it potentially interprets paths differently than the operating system would. |
| 5 | +// This test demonstrates that merely enabling the permission model causes the |
| 6 | +// application to potentially access a different file than it would without the |
| 7 | +// permission model. |
| 8 | + |
| 9 | +const common = require('../common'); |
| 10 | + |
| 11 | +const assert = require('assert'); |
| 12 | +const { execFileSync } = require('child_process'); |
| 13 | +const { mkdirSync, symlinkSync, writeFileSync } = require('fs'); |
| 14 | +const path = require('path'); |
| 15 | + |
| 16 | +if (common.isWindows) |
| 17 | + assert.fail('not applicable to Windows'); |
| 18 | + |
| 19 | +const tmpdir = require('../common/tmpdir'); |
| 20 | +tmpdir.refresh(); |
| 21 | + |
| 22 | +const a = path.join(tmpdir.path, 'a'); |
| 23 | +const b = path.join(tmpdir.path, 'b'); |
| 24 | +const c = path.join(tmpdir.path, 'c'); |
| 25 | +const d = path.join(tmpdir.path, 'c/d'); |
| 26 | + |
| 27 | +writeFileSync(a, 'bad'); |
| 28 | +symlinkSync('c/d', b); |
| 29 | +mkdirSync(c); |
| 30 | +mkdirSync(d); |
| 31 | +writeFileSync(path.join(c, 'a'), 'good'); |
| 32 | + |
| 33 | +function run(...args) { |
| 34 | + const interestingPath = `${tmpdir.path}/b/../a`; |
| 35 | + args = [...args, '-p', `fs.readFileSync(${JSON.stringify(interestingPath)}, 'utf8')`]; |
| 36 | + return execFileSync(process.execPath, args, { encoding: 'utf8' }).trim(); |
| 37 | +} |
| 38 | + |
| 39 | +// Because this is a known_issues test, we cannot assert any assumptions besides |
| 40 | +// the known issue itself. Instead, do a sanity check and report success if the |
| 41 | +// sanity check fails. |
| 42 | +if (run() !== 'good') { |
| 43 | + process.exit(0); |
| 44 | +} |
| 45 | + |
| 46 | +assert.strictEqual(run('--experimental-permission', `--allow-fs-read=${tmpdir.path}`), 'good'); |
0 commit comments