mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-01 20:55:25 +09:00
fix(config-protection): check MultiEdit edits[].file_path targets
Fixes #3761. config-protection only read tool_input.file_path, so a MultiEdit with the config path inside edits[] edited an existing ruff.toml/.eslintrc without the block. Check every effective target and block if any is an existing protected config.
This commit is contained in:
1 parent
25278e7d7b
commit
ed2f02dd06
2 files changed
+78
-4
No files matched your search
@@ -157,9 +157,32 @@ function run(inputOrRaw, options = {}) {
|
||||
}
|
||||
|
||||
const input = parseInput(inputOrRaw);
|
||||
const filePath = input?.tool_input?.file_path || input?.tool_input?.file || '';
|
||||
if (!filePath) return { exitCode: 0 };
|
||||
for (const filePath of targetPaths(input?.tool_input)) {
|
||||
const blocked = checkTarget(filePath);
|
||||
if (blocked) return blocked;
|
||||
}
|
||||
return { exitCode: 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Every path the tool call would write. A MultiEdit entry may carry its own
|
||||
* `file_path`; one without falls back to the top-level path, the same rule
|
||||
* GateGuard applies (#3761). Checking only the top-level path let a batch
|
||||
* edit an existing config through `edits[].file_path`.
|
||||
*/
|
||||
function targetPaths(toolInput) {
|
||||
const shared = toolInput?.file_path || toolInput?.file || '';
|
||||
const paths = new Set();
|
||||
if (typeof shared === 'string' && shared) paths.add(shared);
|
||||
const edits = Array.isArray(toolInput?.edits) ? toolInput.edits : [];
|
||||
for (const edit of edits) {
|
||||
const entryPath = edit && typeof edit === 'object' ? edit.file_path : undefined;
|
||||
if (typeof entryPath === 'string' && entryPath) paths.add(entryPath);
|
||||
}
|
||||
return [...paths];
|
||||
}
|
||||
|
||||
function checkTarget(filePath) {
|
||||
const basename = path.basename(filePath);
|
||||
// Match case-insensitively. Every PROTECTED_FILES entry is lowercase, and on
|
||||
// case-insensitive filesystems (macOS APFS/HFS+, Windows NTFS) a write to
|
||||
@@ -194,7 +217,7 @@ function run(inputOrRaw, options = {}) {
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
return { exitCode: 0 };
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -207,7 +230,7 @@ function run(inputOrRaw, options = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
return { exitCode: 0 };
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = { run };
|
||||
|
||||
Reference in new issue
Block a user