Commit Graph
17 Commits
Author SHA1 Message Date
haelyra 348f6e62b6 fix: reserve log lock quarantines without overwriting foreign files 2026-11-19 17:38:01 -05:00
haelyra 6c3ebeab96 test: document and verify orphan log recovery fallback 2026-11-19 17:35:32 -05:00
haelyra 7b9f56fb94 fix: preserve runtime history and project discovery across hook races 2026-11-19 17:34:15 -05:00
Gaurav Dubey b427484d1e fix(hooks): tighten a legacy log before rotating it
An existing 0664 log that was already at the cap was renamed to .1
before its mode was tightened, so the rotated copy stayed group/world
readable. Tighten the existing log first, and drop the post-open
fchmod that only reached the new active log.

Refs #3846
2026-11-19 04:21:19 +00:00
Gaurav Dubey 9e6272d5df fix(hooks): keep recording the command when log rotation fails
If the rename to <log>.1 fails (another session rotated first, or
Windows refuses the rename), append to the current log instead of
dropping the line.

Refs #3846
2026-11-19 03:57:06 +00:00
Gaurav Dubey c940659dab fix(hooks): create command logs owner-only and rotate them
bash-commands.log and cost-tracker.log record every Bash command but
were created with the default umask (0664 in the report) and grew
without bound. appendLine now opens them with mode 0600, tightens an
existing group/world-readable log on the next write, and rotates the
log to <log>.1 once it would pass 10 MiB, keeping one rotated copy.
This mirrors the metrics.jsonl scheme in scripts/lib/gateguard-metrics.js,
inlined because hooks cannot require scripts/lib/.

Refs #3846
2026-11-19 03:35:48 +00:00
haelyra 2915882707 fix(hooks): fail closed when JWT header decode budget is spent
findJwtHeader capped full header decodes at 8 per segment, so a valid
whitespace-header JWT after 8 decoy candidates (eyAg-eyAg-...-<JWT>) was
logged unredacted. Once the budget is spent, treat the next candidate
that passes the constant-time prefilter as a header. The scan stays
linear and the extra redaction only applies to pathological segments.

Refs #3846
2026-11-16 20:59:51 -05:00
Gaurav DubeyandClaude Opus 5.5 5f72adbd83 fix(hooks): try later JWT header candidates after a failed prefix match
A word prefix such as `eyewear_session_` was taken as the only JWT
header candidate; when it failed validation the real header after `_`
was never tried and the token stayed in the command log. Keep scanning
eligible candidates, with a constant-time prefilter and a per-segment
decode cap so long candidate runs stay linear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 03:31:34 +00:00
Gaurav DubeyandClaude Opus 5.5 f0eee4b543 fix(hooks): redact JWTs joined to an underscore-prefixed label
The JWT chain scanner only accepted a header at the start of a segment or
after `-`, so `session_<JWT>` reached the audit and cost logs unredacted.
Treat `_` as a prefix boundary too and cover it in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:30:52 +00:00
Gaurav DubeyandClaude Opus 5.5 71084e0555 fix(hooks): redact JWTs joined to a hyphenated prefix
The lookbehind added to keep the JWT scan linear also skipped tokens right
after a `-`, so `--cookie "session=jwt-<JWT>"` reached the logs unredacted.
Scan each `[A-Za-z0-9_.-]` run once instead, checking every dot segment for
a header at its start or after a `-`, decoding at most once per segment so
long `ey-ey-...` runs stay linear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 03:31:50 +00:00
Gaurav DubeyandClaude Opus 5.5 4d3e66e0ab fix(hooks): redact joined-fragment secret values and make JWT scan linear
- Replace the secret=/api_key= value regex with a single-pass, quote-aware
  scanner so the whole Bash word is redacted when quoted and unquoted
  fragments are joined (e.g. --secret='prefix-'suffix), while a value inside
  an enclosing quoted string stops at that string's closing quote.
- Searching for the keyword itself (grep -n "secret =" file,
  rg 'api_key:' dir) no longer redacts the rest of the command.
- Use a lookbehind instead of \b before the JWT header so long dot-free
  ey-ey-... runs are scanned in linear time instead of quadratic.
- Add regression tests for joined fragments, keyword searches, and the
  ey- performance case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 03:41:05 +00:00
Gaurav Dubey 0b57406e57 fix(hooks): redact spaced-header JWTs and escaped or $'...' secret values
Match JWT headers that start with ey or ew (whitespace after the opening
brace) and keep non-eyJ matches only when the header does not decode to
an object with an alg field. Parse secret= / api_key= values with escaped
double quotes, $'...' quoting and backslash escapes, and redact an
unterminated quoted value to the end of the command.

Refs #3846
2026-11-03 04:19:37 +00:00
Gaurav Dubey 08fb3c8a1c fix(hooks): redact bare API keys, JWTs and PEM blocks in bash command logs
sanitizeCommand only redacted keyword- or flag-shaped secrets, so a bare
Anthropic/OpenAI sk- key, a JWT, a PEM private key block, or a secret= /
api_key= / x-api-key: value was written verbatim to bash-commands.log and
cost-tracker.log. Add value-shape patterns for these and keep the key name
and separator for assignments so the log stays readable.

Refs #3846
2026-11-03 04:12:32 +00:00
basil-k-aji-dev cd85014b9e fix(plan-canvas): route session state through CLAUDE_CONFIG_DIR
The Plan Canvas library wrote ~/.claude/plan-canvas while the SessionStart
and Stop hooks read CLAUDE_CONFIG_DIR/plan-canvas. Under a second profile
SessionStart missed open reviews and Stop let a turn end with feedback
still queued.

Expand a leading ~ in CLAUDE_CONFIG_DIR the way scripts/lib/agent-data-home.js
does, so a profile written as ~/.claude-work resolves to one directory rather
than two.

Add hook-level coverage that spawns each hook with a distinct
CLAUDE_CONFIG_DIR and no ECC_* override, plus a producer-to-consumer round
trip. Eight of the nine cases fail against the previous revision.
2026-10-03 20:20:40 +05:30
basil-k-aji-dev 00d73fbae2 fix(hooks): honor CLAUDE_CONFIG_DIR instead of writing to ~/.claude
Claude Code points every profile-local path at CLAUDE_CONFIG_DIR when it is
set, but ECC hooks kept reading and writing ~/.claude. A session launched
under a second profile left its bash log, cost tracker, metrics, session data
and skill runs in the default profile, where the other one reads them back.

Two groups, as reported:

- getDefaultClaudeAgentDataHome() in scripts/lib/agent-data-home.js now
  follows the variable, which covers every hook reaching ~/.claude through
  resolveAgentDataHome(). ECC_AGENT_DATA_HOME still wins, so the documented
  workaround keeps working.
- plan-canvas-pending, plan-canvas-sessions, mcp-health-check and
  post-bash-command-log hard-coded os.homedir()/.claude and now resolve the
  same way, matching scripts/hooks/ecc-statusline.js:68.

A blank value is ignored rather than resolved, since path.resolve('  ')
returns the process cwd and would scatter profile data through whatever
directory the session started in.

Fixes #3266
2026-10-03 12:34:14 +05:30
Affaan Mustafa 1fabf4d2cf fix: consolidate bash hooks without fork storms 2026-04-14 21:23:57 -07:00
Affaan Mustafa a273c62f35 fix: restore ci lockfile and hook validation 2026-03-31 18:00:07 -07:00