Skip to content

fix: NotebookEdit hook bypass, gitleaks tests, scan_text early-exit#5

Merged
bokiko merged 5 commits into
mainfrom
kyzn/20260408-analyze-fix-a42ff097
Apr 10, 2026
Merged

fix: NotebookEdit hook bypass, gitleaks tests, scan_text early-exit#5
bokiko merged 5 commits into
mainfrom
kyzn/20260408-analyze-fix-a42ff097

Conversation

@bokiko
Copy link
Copy Markdown
Owner

@bokiko bokiko commented Apr 8, 2026

Summary

  • SEC-001 (HIGH): Add NotebookEdit to HOOK_MATCHER in claude.py — the hook handler already processed NotebookEdit events, but the matcher string never registered for them, so Claude Code silently skipped scanning secrets written to Jupyter notebook cells
  • ARCH-001 (HIGH): Add max_findings: Optional[int] = None to scan_text and scan_file — provides an early-exit for obviously-compromised files; default None is fully backward compatible
  • TEST-001 (HIGH): Add TestGitleaksIntegration to tests/test_scanner_unit.py covering _scan_with_gitleaks field mapping, timeout handling (returns []), empty-report handling, and scan_path deduplication-by-fingerprint merge logic

Test plan

  • pytest tests/test_scanner_unit.py — 17 tests including 4 new gitleaks tests
  • pytest tests/test_claude_install.py — hook matcher constant verified
  • pytest tests/ — all 171 tests pass

🤖 Generated with Claude Code

bokiko and others added 2 commits April 8, 2026 13:14
…early-exit

- SEC-001: add NotebookEdit to HOOK_MATCHER so secrets in Jupyter notebook
  cells are scanned (hook.py already handled the tool, but claude.py never
  registered the matcher)
- ARCH-001: add max_findings parameter to scan_text/scan_file for early-exit
  on obviously-compromised files; default None preserves backward compat
- TEST-001: add TestGitleaksIntegration covering _scan_with_gitleaks field
  mapping, timeout handling, and scan_path deduplication by fingerprint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cdfa5244e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gitshield/claude.py
SETTINGS_PATH = Path.home() / ".claude" / "settings.json"
HOOK_COMMAND = "gitshield-claude-hook"
HOOK_MATCHER = "Write|Edit|Bash"
HOOK_MATCHER = "Write|Edit|Bash|NotebookEdit"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Migrate existing Claude hook matcher to include NotebookEdit

Updating HOOK_MATCHER only affects fresh installs; existing users who already have a gitshield-claude-hook entry with the old matcher (Write|Edit|Bash) are still bypassable for NotebookEdit. install_hook() exits early when _is_installed() finds any gitshield command, so it never rewrites the matcher for already-installed hooks, leaving the security fix unapplied for upgraded installations.

Useful? React with 👍 / 👎.

Comment thread gitshield/engine.py
Comment on lines +161 to +162
if max_findings is not None and len(findings) >= max_findings:
break
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce max_findings limit during pattern matching

The new max_findings guard is checked only once per input line, so a single line that matches multiple patterns can still append several findings after the limit is reached (e.g., max_findings=1 can return more than one finding). That violates the documented “stop scanning once this many findings are accumulated” behavior and weakens the intended short-circuit for heavily compromised content.

Useful? React with 👍 / 👎.

bokiko and others added 3 commits April 8, 2026 13:25
Remove find_git_root, Optional, and tempfile unused imports flagged by ruff.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bokiko added a commit that referenced this pull request Apr 10, 2026
- Add migration path for NotebookEdit matcher in install_hook() so
  existing users get the updated matcher without reinstalling
- Remove unguarded regex search in _gitignore_regex_is_safe to prevent
  ReDoS on main thread; always use thread-based timeout
- Harden batch parser in _scan_staged: bounds check before header parse,
  skip non-blob entries while advancing pos correctly
- Fix max_findings overshoot in scan_text by trimming results post-loop
- Log warning on OSError when reading .gitshieldignore so users know
  their suppressions are not being applied

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bokiko bokiko merged commit cf85b10 into main Apr 10, 2026
7 checks passed
@bokiko bokiko deleted the kyzn/20260408-analyze-fix-a42ff097 branch April 10, 2026 04:00
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