import { createHash } from "node:crypto"; import fs from "node:fs/promises"; import path from "node:path"; import { isPathInside } from "./path-guards.js";
export async function assertCanonicalPathWithinBase(params: {
baseDir: string;
candidatePath: string;
boundaryLabel: string;
}): Promise<void> { const baseDir = path.resolve(params.baseDir); const candidatePath = path.resolve(params.candidatePath); if (!isPathInside(baseDir, candidatePath)) { thrownew Error(`Invalid path: must stay within ${params.boundaryLabel}`);
}
const baseLstat = await fs.lstat(baseDir); if (!baseLstat.isDirectory() || baseLstat.isSymbolicLink()) { thrownew Error(`Invalid ${params.boundaryLabel}: base directory must be a real directory`);
} const baseRealPath = await fs.realpath(baseDir);
const validateDirectory = async (dirPath: string): Promise<void> => { const dirLstat = await fs.lstat(dirPath); if (!dirLstat.isDirectory() || dirLstat.isSymbolicLink()) { thrownew Error(`Invalid path: must stay within ${params.boundaryLabel}`);
} const dirRealPath = await fs.realpath(dirPath); if (!isPathInside(baseRealPath, dirRealPath)) { thrownew Error(`Invalid path: must stay within ${params.boundaryLabel}`);
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.