Skip to content

fix: security hardening, stability fixes, and audit logging#23

Open
Noopy420 wants to merge 1 commit intozebbern:mainfrom
Noopy420:fix/security-and-stability-improvements
Open

fix: security hardening, stability fixes, and audit logging#23
Noopy420 wants to merge 1 commit intozebbern:mainfrom
Noopy420:fix/security-and-stability-improvements

Conversation

@Noopy420
Copy link

Summary

  • Security: Fix command injection in git operations — Branch names are now validated against shell metacharacters, and all arguments are shell-escaped before passing to exec(). Uses git worktree list --porcelain for reliable parsing that handles paths with spaces.
  • Stability: Cap shell output buffer at 10 MB — Prevents OOM crashes when a shell command produces infinite output (e.g., yes, cat /dev/urandom). Appends a truncation notice when the limit is hit.
  • Stability: Per-channel query isolation — Replaces the single global activeQuery variable with a Map<channelId, Query> so concurrent /claude commands from different channels don't overwrite each other's sessions.
  • Stability: 10-minute timeout on Claude SDK queries — Wraps executeWithErrorHandling() with Promise.race() to abort if the SDK hangs indefinitely.
  • Stability: Discord embed size validation — Adds safeTruncate() to enforce Discord's 4096-char embed description limit, preventing API errors on large Claude responses.
  • Fix: .env parsing handles quoted values with = — Values like SECRET="a=b=c" now parse correctly. Also handles escape sequences in double-quoted values and inline comments in unquoted values.
  • Fix: Crash recovery is now functionalrecoverShellProcess(), recoverWorktreeProcess(), and recoverClaudeProcess() now properly clean up resources with structured logging instead of being stubs.
  • Feature: Auto-archive inactive session threads — The cleanup() method now archives Discord threads before removing them from internal state, keeping the server tidy. Addresses Feature Req: better session management #19.
  • Feature: Audit logger — New util/audit-logger.ts provides in-memory + JSONL file audit logging for all bot commands, including user, command, cost, and duration tracking.

Test plan

  • Verify bot starts correctly with existing .env configuration
  • Test /worktree with valid branch names (should work as before)
  • Test /worktree with malicious branch names like ; rm -rf / (should be rejected)
  • Test /shell with a command that produces large output (should truncate at 10 MB)
  • Test concurrent /claude commands in different channels (should not interfere)
  • Verify Claude responses with long output render correctly in Discord embeds
  • Test .env file with SECRET="key=value" format (should parse correctly)
  • Verify inactive session threads get archived during periodic cleanup

🤖 Generated with Claude Code

- fix(git): prevent command injection via branch name validation and shell escaping
- fix(git): use `git worktree list --porcelain` for reliable parsing (handles spaces in paths)
- fix(shell): cap output buffer at 10 MB to prevent OOM on infinite output
- fix(claude): per-channel query isolation to prevent concurrent session collisions
- fix(claude): add 10-minute timeout on SDK queries to prevent indefinite hangs
- fix(claude): enforce Discord embed size limits with safe truncation
- fix(env): handle quoted .env values containing '=' and inline comments
- fix(crash): implement functional crash recovery with proper logging
- feat(session): auto-archive inactive Discord threads during cleanup (addresses zebbern#19)
- feat(audit): add audit logger with in-memory + JSONL file persistence

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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