Quellcode-Bibliothek secret-file.ts
Interaktion und PortierbarkeitJAVA
import { randomBytes } from "node:crypto"; import fs from "node:fs"; import fsp from "node:fs/promises"; import path from "node:path"; import { resolveUserPath } from "../utils.js"; import { openVerifiedFileSync } from "./safe-open-sync.js";
if (options.rejectSymlink && previewStat.isSymbolicLink()) { return {
ok: false,
resolvedPath,
message: `${label} file at ${resolvedPath} must not be a symlink.`,
};
} if (!previewStat.isFile()) { return {
ok: false,
resolvedPath,
message: `${label} file at ${resolvedPath} must be a regular file.`,
};
} if (previewStat.size > maxBytes) { return {
ok: false,
resolvedPath,
message: `${label} file at ${resolvedPath} exceeds ${maxBytes} bytes.`,
};
}
const opened = openVerifiedFileSync({
filePath: resolvedPath,
rejectPathSymlink: options.rejectSymlink,
maxBytes,
}); if (!opened.ok) { const error = normalizeSecretReadError(
opened.reason === "validation" ? new Error("security validation failed") : opened.error,
); return {
ok: false,
resolvedPath,
error,
message: `Failed to read ${label} file at ${resolvedPath}: ${String(error)}`,
};
}
try { const stat = await fsp.lstat(finalFilePath); if (stat.isSymbolicLink()) { thrownew Error(`Private secret file ${finalFilePath} must not be a symlink.`);
} if (!stat.isFile()) { thrownew Error(`Private secret file ${finalFilePath} must be a regular file.`);
}
} catch (error) { if (!error || typeof error !== "object" || !("code" in error) || error.code !== "ENOENT") { throw error;
}
}
¤ 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.0.24Bemerkung:
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-27)
¤
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.