Security hardening: path validation, input clamping, safe JSON, file locking
Implements security improvements inspired by PR #16 (credit: MO2k4): - Add validatePathWithinRoot() to prevent path traversal attacks in extraction and context building - Clamp MCP tool inputs (limit, depth, maxDepth) to sane ranges - Use atomic writes (temp file + rename) for config saves - Add symlink cycle detection in directory scanning to prevent infinite loops - Replace all JSON.parse calls in db/queries.ts with safeJsonParse fallbacks to handle corrupted database metadata gracefully - Add cross-process FileLock for DB write operations (indexAll, indexFiles, sync) to prevent concurrent writes from CLI, MCP server, and git hooks - Remove unused path import from context/index.ts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
38fac1ff28
commit
932c567d18
+5
-1
@@ -154,7 +154,11 @@ export function saveConfig(projectRoot: string, config: CodeGraphConfig): void {
|
||||
delete (toSave as Partial<CodeGraphConfig>).rootDir;
|
||||
|
||||
const content = JSON.stringify(toSave, null, 2);
|
||||
fs.writeFileSync(configPath, content, 'utf-8');
|
||||
|
||||
// Atomic write: write to temp file then rename to prevent partial/corrupt configs
|
||||
const tmpPath = configPath + '.tmp';
|
||||
fs.writeFileSync(tmpPath, content, 'utf-8');
|
||||
fs.renameSync(tmpPath, configPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user