mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-06 23:24:01 +09:00
Merge reviewed PR #4013 into security and evaluation batch
This commit is contained in:
2 files changed
+56
No files matched your search
@@ -106,6 +106,27 @@ function normalizeHookResult(previousRaw, output) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* True when hook stdout is a PreToolUse `deny` decision. GateGuard and other
|
||||
* hooks deny by writing that JSON to stdout at exit code 0, so the dispatcher
|
||||
* must recognise it as a decision rather than as pass-through output.
|
||||
*/
|
||||
function isPermissionDeny(raw) {
|
||||
if (typeof raw !== 'string' || !raw.includes('permissionDecision')) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
return Boolean(
|
||||
parsed
|
||||
&& parsed.hookSpecificOutput
|
||||
&& parsed.hookSpecificOutput.permissionDecision === 'deny'
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function runHooks(rawInput, hooks) {
|
||||
let currentRaw = rawInput;
|
||||
// Track whether a sub-hook deliberately produced stdout (a string or
|
||||
@@ -134,6 +155,16 @@ function runHooks(rawInput, hooks) {
|
||||
if (result.additionalContext) {
|
||||
additionalContext = combineAdditionalContext(additionalContext, result.additionalContext);
|
||||
}
|
||||
// A deny is a decision, not a note: stop here so neither a later hook
|
||||
// nor an earlier hook's advisory additionalContext can replace it.
|
||||
if (result.exitCode === 0 && rawModified && isPermissionDeny(currentRaw)) {
|
||||
return {
|
||||
output: currentRaw,
|
||||
stderr,
|
||||
additionalContext,
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
if (result.exitCode !== 0) {
|
||||
return {
|
||||
output: rawModified ? currentRaw : '',
|
||||
|
||||
@@ -134,6 +134,31 @@ function runTests() {
|
||||
assert.ok(!disabled.stderr.includes('Review changes before push'), 'Disabled hook should not emit reminder');
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('pre dispatcher keeps a GateGuard deny when an advisory hook also adds context', () => {
|
||||
// In the strict profile the git-push reminder adds additionalContext for
|
||||
// every `git push`, and GateGuard denies a force-push with a
|
||||
// permissionDecision on stdout at exit 0. The advisory note must not
|
||||
// replace the denial.
|
||||
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-bash-dispatcher-gateguard-'));
|
||||
try {
|
||||
const input = {
|
||||
tool_name: 'Bash',
|
||||
session_id: 'dispatcher-deny-precedence',
|
||||
tool_input: { command: 'git push --force origin main' },
|
||||
};
|
||||
const result = runScript(preDispatcher, input, {
|
||||
ECC_HOOK_PROFILE: 'strict',
|
||||
GATEGUARD_STATE_DIR: stateDir,
|
||||
});
|
||||
assert.strictEqual(result.status, 0, result.stderr);
|
||||
const output = parseHookOutput(result.stdout).hookSpecificOutput;
|
||||
assert.strictEqual(output.permissionDecision, 'deny', `Expected GateGuard deny, got: ${result.stdout}`);
|
||||
assert.ok(output.permissionDecisionReason.includes('Destructive command'), 'Expected the GateGuard reason');
|
||||
} finally {
|
||||
fs.rmSync(stateDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('pre dispatcher respects hook profiles inside the consolidated path', () => {
|
||||
const input = { tool_input: { command: 'git push origin main' } };
|
||||
const result = runScript(preDispatcher, input, { ECC_HOOK_PROFILE: 'minimal' });
|
||||
|
||||
Reference in new issue
Block a user