MCPcopy Create free account
hub / github.com/Tele-AI/doc-ops-mcp / createSecureTempPath

Function createSecureTempPath

src/security/securityConfig.ts:48–59  ·  view source on GitHub ↗
(prefix: string, extension: string = '.tmp')

Source from the content-addressed store, hash-verified

46 * Create a secure temporary file path
47 */
48export function createSecureTempPath(prefix: string, extension: string = '.tmp'): string {
49 const tempDir = process.env.TEMP_DIR ?? os.tmpdir();
50
51 if (!isAllowedTempDir(tempDir)) {
52 throw new Error(`Temporary directory not allowed: ${tempDir}`);
53 }
54
55 const randomSuffix = generateSecureRandomSuffix();
56 const filename = `${prefix}_${randomSuffix}${extension}`;
57
58 return path.join(tempDir, filename);
59}
60
61// Dangerous character ranges (excluding tab and line feed)
62const DANGEROUS_CHARS_REGEX = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;

Callers 1

Calls 2

isAllowedTempDirFunction · 0.85

Tested by

no test coverage detected