Skip to content

refactor: code review fixes — security, architecture, performance#21

Merged
The-R4V3N merged 3 commits intomainfrom
refactor/code-review-fixes
Mar 15, 2026
Merged

refactor: code review fixes — security, architecture, performance#21
The-R4V3N merged 3 commits intomainfrom
refactor/code-review-fixes

Conversation

@The-R4V3N
Copy link
Owner

Summary

Comprehensive fixes from architecture, security, and performance review.

Critical (2/2)

  • FORGE content safety scan (isCodeSafe()) blocks dangerous code patterns before writing to disk
  • ORACLE max_tokens centralized via getMaxOracleOutputTokens() in security.ts

High (10/10)

  • Macro data sanitized for prompt injection (sanitizeMacroText())
  • FORGE protected file prefixes + backslash path traversal check
  • FORGE line-count uses actual diff, not net line change
  • API keys stripped from error logs (sanitizeErrorMessage())
  • Shared utilities extracted to src/utils.ts (salvageJSON, stripSurrogates, extractJSON, paths, groupBy)
  • loadAllJournalEntries() cached per session
  • AbortSignal.timeout() on all 14 fetch calls
  • Phase 1 data fetches parallelized via Promise.allSettled
  • Tests for forge.ts and utils.ts

Medium (6/6)

  • ReDoS mitigation in injection patterns
  • GitHub Pages XSS bias allowlist
  • resolvedSelfTasks comment sanitization
  • Crash handler logs actual phase
  • sessions.json capped to 500 entries
  • Debug logging in 9 empty catch blocks

Low (3/4)

  • npm ci in GitHub Actions
  • dist/ in .gitignore
  • TruffleHog --only-verified removed

Deferred

  • Break up runSession() (separate PR)
  • Break up runAxiomReflection() (separate PR)

Test plan

  • npx tsc --noEmit — clean build
  • npx vitest run — 221 tests passing (80 new)
  • Trigger a session run to verify pipeline works end-to-end

Security:
- FORGE content safety scan (isCodeSafe) blocks dangerous code patterns
- ORACLE max_tokens centralized via getMaxOracleOutputTokens()
- Macro data sanitized for prompt injection (sanitizeMacroText)
- FORGE protected file prefixes and backslash path traversal check
- FORGE line-count uses actual diff, not net line change
- API keys stripped from error logs (sanitizeErrorMessage)

Architecture:
- Extracted shared utils (salvageJSON, stripSurrogates, extractJSON, paths, groupBy)
- Cached loadAllJournalEntries() per session with invalidation

Performance:
- AbortSignal.timeout() on all 14 fetch calls (10-20s)
- Phase 1 data fetches parallelized via Promise.allSettled

Testing: 73 new tests (214 total across 9 files)
Security:
- ReDoS mitigation: bounded \s+ to \s{1,10} in injection patterns
- GitHub Pages XSS: bias values allowlisted before HTML injection
- resolvedSelfTasks: issueNumber validated, comment HTML stripped + capped

Code Quality:
- Crash handler now logs actual phase, not hardcoded "oracle"
- sessions.json capped to 500 entries (~8 months)
- Debug logging added to 9 empty catch blocks in agent.ts/axiom.ts

Low:
- npm install -> npm ci in GitHub Actions
- dist/ added to .gitignore
- TruffleHog --only-verified flag removed

Testing: 7 new tests (221 total)
Prevents TypeError when Claude API returns partial objects with
missing fields (e.g., bias without notes, undefined changePercent).
@The-R4V3N The-R4V3N merged commit d62442b into main Mar 15, 2026
4 of 5 checks passed
@The-R4V3N The-R4V3N deleted the refactor/code-review-fixes branch March 15, 2026 19:19
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