Skip to content

Commit b0627be

Browse files
authored
fix(builtin): fix node patches lstat short-circuit logic (#1818)
The short-circuit logic for lstat and lstatSync needs updating after adding in guards logic. Fixes issue observed in angular-cli with webpack enhanced resolver.
1 parent 7e3f9b1 commit b0627be

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

internal/node/node_patches.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports.patcher = (fs = fs$1, root, guards) => {
8484
const origReadlinkSync = fs.readlinkSync.bind(fs);
8585
const origReaddir = fs.readdir.bind(fs);
8686
const origReaddirSync = fs.readdirSync.bind(fs);
87-
const { isEscape, isOutPath } = exports.escapeFunction(root, guards);
87+
const { isEscape } = exports.escapeFunction(root, guards);
8888
// tslint:disable-next-line:no-any
8989
fs.lstat = (...args) => {
9090
let cb = args.length > 1 ? args[args.length - 1] : undefined;
@@ -95,8 +95,7 @@ exports.patcher = (fs = fs$1, root, guards) => {
9595
if (err)
9696
return cb(err);
9797
const linkPath = path.resolve(args[0]);
98-
// if this is not a symlink or the path is not inside the root it has no way to escape.
99-
if (!stats.isSymbolicLink() || !root || isOutPath(linkPath)) {
98+
if (!stats.isSymbolicLink()) {
10099
return cb(null, stats);
101100
}
102101
return origReadlink(args[0], (err, str) => {
@@ -197,9 +196,9 @@ exports.patcher = (fs = fs$1, root, guards) => {
197196
fs.lstatSync = (...args) => {
198197
const stats = origLstatSync(...args);
199198
const linkPath = path.resolve(args[0]);
200-
// if this is not a symlink or the path is not inside the root it has no way to escape.
201-
if (!stats.isSymbolicLink() || isOutPath(linkPath))
199+
if (!stats.isSymbolicLink()) {
202200
return stats;
201+
}
203202
let linkTarget;
204203
try {
205204
linkTarget = path.resolve(path.dirname(args[0]), origReadlinkSync(linkPath));

packages/node-patches/src/fs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const patcher = (fs: any = _fs, root: string, guards: string[]) => {
5555
const origReaddir = fs.readdir.bind(fs);
5656
const origReaddirSync = fs.readdirSync.bind(fs);
5757

58-
const {isEscape, isOutPath} = escapeFunction(root, guards);
58+
const {isEscape} = escapeFunction(root, guards);
5959

6060
const logged: {[k: string]: boolean} = {};
6161

@@ -74,8 +74,7 @@ export const patcher = (fs: any = _fs, root: string, guards: string[]) => {
7474
if (err) return cb(err);
7575

7676
const linkPath = path.resolve(args[0]);
77-
// if this is not a symlink or the path is not inside the root it has no way to escape.
78-
if (!stats.isSymbolicLink() || !root || isOutPath(linkPath)) {
77+
if (!stats.isSymbolicLink()) {
7978
return cb(null, stats);
8079
}
8180

@@ -177,8 +176,9 @@ export const patcher = (fs: any = _fs, root: string, guards: string[]) => {
177176
fs.lstatSync = (...args: any[]) => {
178177
const stats = origLstatSync(...args);
179178
const linkPath = path.resolve(args[0]);
180-
// if this is not a symlink or the path is not inside the root it has no way to escape.
181-
if (!stats.isSymbolicLink() || isOutPath(linkPath)) return stats;
179+
if (!stats.isSymbolicLink()) {
180+
return stats;
181+
}
182182
let linkTarget: string;
183183
try {
184184
linkTarget = path.resolve(path.dirname(args[0]), origReadlinkSync(linkPath));

0 commit comments

Comments
 (0)