← Files RivetARCHIVED FILE
node_modules/rivet-design/dist/utils/pathContainment.js
2.22 KB · Nov 7, 2026 · 13:16 UTC
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveRealPathWithinRoot = exports.isConfinedRelativePath = exports.isPathStrictlyInsideRoot = exports.isPathWithinRoot = exports.createPathContainment = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
const PATH_SEPARATORS = /[\\/]+/;
const createPathContainment = (platformPath) => {
const isOutsideRoot = (relativePath) => relativePath === '..' ||
relativePath.startsWith(`..${platformPath.sep}`) ||
platformPath.isAbsolute(relativePath);
return {
isPathWithinRoot: (root, candidate) => !isOutsideRoot(platformPath.relative(root, candidate)),
isPathStrictlyInsideRoot: (root, candidate) => {
const relativePath = platformPath.relative(root, candidate);
return relativePath !== '' && !isOutsideRoot(relativePath);
},
isConfinedRelativePath: (relativePath) => !relativePath.includes('\0') &&
!platformPath.isAbsolute(relativePath) &&
!relativePath.split(PATH_SEPARATORS).includes('..'),
};
};
exports.createPathContainment = createPathContainment;
_a = (0, exports.createPathContainment)(path_1.default), exports.isPathWithinRoot = _a.isPathWithinRoot, exports.isPathStrictlyInsideRoot = _a.isPathStrictlyInsideRoot, exports.isConfinedRelativePath = _a.isConfinedRelativePath;
const resolveRealPathWithinRoot = async ({ root, candidate, containment, }) => {
let realRoot;
let realCandidate;
try {
[realRoot, realCandidate] = await Promise.all([
promises_1.default.realpath(root),
promises_1.default.realpath(candidate),
]);
}
catch {
return null;
}
const isContained = containment === 'strict'
? (0, exports.isPathStrictlyInsideRoot)(realRoot, realCandidate)
: (0, exports.isPathWithinRoot)(realRoot, realCandidate);
return isContained ? realCandidate : null;
};
exports.resolveRealPathWithinRoot = resolveRealPathWithinRoot;
//# sourceMappingURL=pathContainment.js.mapSHA-256: 19167c05e941968c5ca9138e5a1c60c8084203383867a803686bf8658549460d