Skip to content

Claude pretool hooks for dangerous commands and secret files#1317

Open
labkey-martyp wants to merge 2 commits intodevelopfrom
fb_claude_pretool_hooks
Open

Claude pretool hooks for dangerous commands and secret files#1317
labkey-martyp wants to merge 2 commits intodevelopfrom
fb_claude_pretool_hooks

Conversation

@labkey-martyp
Copy link
Contributor

Rationale

Add security related Claude pre-tool hooks to prevent dangerous commands and accessing secrets files. Should be compatible and applicable to Mac, Linux and Windows.

Changes

  • Hooks added to settings.json
  • Python scripts for pattern matching dangerous commands and secrets files
  • Test script validating ALLOW/BLOCK

@labkey-martyp labkey-martyp requested review from a team and labkey-jeckels March 24, 2026 06:23
except json.JSONDecodeError:
detail = f" -- {result.stdout.strip()}"

print(f" [{status}] {description:45s} expected={expected} actual={actual}{detail}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High test

This expression logs
sensitive data (secret)
as clear text.

Copilot Autofix

AI about 7 hours ago

General approach: ensure that potentially sensitive data (like file paths or future secret values) are not logged in clear text. In this case, we can treat description and detail as potentially sensitive and sanitize or minimize what we print. For a test harness, it’s sufficient to log only non‑sensitive status information (PASS/FAIL, expected vs actual) and omit or redact arbitrary text coming from test definitions or hook output.

Best targeted fix: modify the print at line 96 in run_hook_test so that it does not include the raw description or detail. Instead, we can print an index or a generic label, or print only status, expected, and actual. This change avoids logging any tainted strings while preserving the core functionality of the test harness (indicating which tests passed or failed), albeit with less descriptive output. To keep things simple and avoid changing other code, I’ll just remove description and detail from the formatted string.

Concretely:

  • In .claude/hooks/test-hooks.py, in run_hook_test, replace:
print(f"  [{status}] {description:45s}  expected={expected}  actual={actual}{detail}")

with a version that omits description and detail, such as:

print(f"  [{status}] expected={expected}  actual={actual}")

No new imports or helper methods are needed.

Suggested changeset 1
.claude/hooks/test-hooks.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.claude/hooks/test-hooks.py b/.claude/hooks/test-hooks.py
--- a/.claude/hooks/test-hooks.py
+++ b/.claude/hooks/test-hooks.py
@@ -93,7 +93,7 @@
         except json.JSONDecodeError:
             detail = f" -- {result.stdout.strip()}"
 
-    print(f"  [{status}] {description:45s}  expected={expected}  actual={actual}{detail}")
+    print(f"  [{status}] expected={expected}  actual={actual}")
     return passed
 
 
EOF
@@ -93,7 +93,7 @@
except json.JSONDecodeError:
detail = f" -- {result.stdout.strip()}"

print(f" [{status}] {description:45s} expected={expected} actual={actual}{detail}")
print(f" [{status}] expected={expected} actual={actual}")
return passed


Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant