Skip to content

Feature/improve audit log naming#3

Merged
ajmallesh merged 3 commits intomainfrom
feature/improve-audit-log-naming
Oct 27, 2025
Merged

Feature/improve audit log naming#3
ajmallesh merged 3 commits intomainfrom
feature/improve-audit-log-naming

Conversation

@ajmallesh
Copy link
Copy Markdown
Collaborator

No description provided.

ajmallesh and others added 3 commits October 27, 2025 10:14
Enhances audit log directory naming from `{hostname}_{uuid}` to
`{timestamp}_{appName}_{hostname}_{shortId}` for better discoverability
and benchmarking analysis.

Changes:
- Add extractAppName() helper to extract app name from config files
- Add smart fallback: use port number for localhost without config
- Update generateSessionIdentifier() to include timestamp prefix
- Shorten session ID to first 8 characters for readability

Examples:
- With config: 20251025T193847Z_myapp_localhost_efc60ee0/
- Without config: 20251025T193913Z_8080_localhost_d47e3bfd/
- Remote: 20251024T004401Z_noconfig_example-com_d47e3bfd/

Benefits:
- Chronologically sortable audit logs
- Instant app identification in directory listings
- Efficient filtering for benchmarking queries
- Non-breaking: existing logs keep their names

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed bug where audit system would create duplicate folders for the same
session because it was using current time instead of the session's original
createdAt timestamp.

Bug behavior:
- Session created at T1 → folder: {T1}_app_host_id/
- Audit re-initialized at T2 → NEW folder: {T2}_app_host_id/
- Result: 2 folders per session with same ID but different timestamps

Root cause:
- metrics-tracker.js:65 was calling formatTimestamp() (current time)
- Should use sessionMetadata.createdAt (original creation time)

Impact: Each running benchmark was creating 2 audit log folders instead of 1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This reverts the timestamp-based naming scheme that was causing audit log
fragmentation. Each agent execution was creating a new folder because the
timestamp kept changing.

Reverting back to simple, stable naming: {hostname}_{sessionId}

This ensures ONE folder per session, preventing the bug where multiple
folders were created for the same session.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ajmallesh ajmallesh merged commit 4be7f96 into main Oct 27, 2025
@ajmallesh ajmallesh deleted the feature/improve-audit-log-naming branch October 27, 2025 21:57
ajmallesh added a commit that referenced this pull request Jan 13, 2026
ajmallesh added a commit that referenced this pull request Mar 4, 2026
mm5srh4ngk-droid pushed a commit to mm5srh4ngk-droid/shannon that referenced this pull request Apr 20, 2026
… escapes

CRITICAL KeygraphHQ#3 from AUDIT-2026-04-19-INTERNAL-CRITICAL.md.

The previous guard only checked that the lexical resolution of --file-path
started with cwd. readFileSync then followed symlinks silently. A prompt-
injected agent could plant a symlink in .shannon/scratchpad/ pointing at
/proc/self/environ, /app/credentials/google-sa-key.json, or any file readable
by UID 1001, pass the symlink's cwd-local path to --file-path, and see the
target file's contents land inside a persisted deliverable that eventually
ships to a CYSTEMS customer.

resolveSafeFilePath now enforces four stages:
  1. Reject NUL bytes in raw input.
  2. Lexical-only traversal fast-reject.
  3. realpathSync.native on both cwd and the resolved target; require the
     final canonical target to live inside cwd. Defeats symlink-escape.
  4. statSync + isFile + 8 MiB size cap. Rejects /proc/self/environ
     (char device), FIFOs, directories, and oversized reads.

Verified with a reproducer:
  - /etc/passwd symlink in .shannon/scratchpad/ -> rejected with
    "Symlink escapes cwd (realpath=/private/etc/passwd, cwd=...)"
  - Legitimate .shannon/scratchpad/real.md -> still read and saved.
  - pnpm --filter @shannon/worker check passes.
mm5srh4ngk-droid pushed a commit to mm5srh4ngk-droid/shannon that referenced this pull request Apr 20, 2026
… escapes

CRITICAL KeygraphHQ#3 from AUDIT-2026-04-19-INTERNAL-CRITICAL.md.

The previous guard only checked that the lexical resolution of --file-path
started with cwd. readFileSync then followed symlinks silently. A prompt-
injected agent could plant a symlink in .shannon/scratchpad/ pointing at
/proc/self/environ, /app/credentials/google-sa-key.json, or any file readable
by UID 1001, pass the symlink's cwd-local path to --file-path, and see the
target file's contents land inside a persisted deliverable that eventually
ships to a CYSTEMS customer.

resolveSafeFilePath now enforces four stages:
  1. Reject NUL bytes in raw input.
  2. Lexical-only traversal fast-reject.
  3. realpathSync.native on both cwd and the resolved target; require the
     final canonical target to live inside cwd. Defeats symlink-escape.
  4. statSync + isFile + 8 MiB size cap. Rejects /proc/self/environ
     (char device), FIFOs, directories, and oversized reads.

Verified with a reproducer:
  - /etc/passwd symlink in .shannon/scratchpad/ -> rejected with
    "Symlink escapes cwd (realpath=/private/etc/passwd, cwd=...)"
  - Legitimate .shannon/scratchpad/real.md -> still read and saved.
  - pnpm --filter @shannon/worker check passes.
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