Skip to content

fix(security): pre-release security hardening#79

Merged
pmclSF merged 1 commit intomainfrom
fix/pre-release-security
Feb 27, 2026
Merged

fix(security): pre-release security hardening#79
pmclSF merged 1 commit intomainfrom
fix/pre-release-security

Conversation

@pmclSF
Copy link
Copy Markdown
Owner

@pmclSF pmclSF commented Feb 27, 2026

Summary

  • Command injection (BLOCKER): Replace exec() with execFile() in repoConverter.js to eliminate shell interpolation on git clone URLs; add validateRepoUrl() with protocol, structure, and metacharacter validation
  • Path traversal (BLOCKER): Apply existing safePath() to root and outputDir in handleAnalyze and handleConvert server handlers, returning 403 on escape attempts
  • CSRF protection: Generate per-session crypto.randomUUID() token at server startup; require X-Hamlet-Token header on all POST requests (401 on mismatch); expose token via /api/health for local client bootstrapping
  • Security headers: Set X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: no-referrer, Cache-Control: no-store, Content-Security-Policy: default-src 'none' on all responses; return 204 on OPTIONS preflight

Test plan

  • npm run format:check passes
  • npm run lint passes
  • npm test passes (726 suites, 2231 tests)
  • New validateRepoUrl tests cover valid URLs, injection payloads, null bytes, non-string input, unrecognized protocols, and malformed URLs
  • New server tests verify CSRF rejection (missing/wrong token), path traversal rejection (absolute/relative escapes on analyze and convert), security header presence, and OPTIONS preflight response
  • Manual: hamlet convert "https://github.com/x/y; touch /tmp/pwned" --from jest --to vitest → "Invalid repository URL" before any exec
  • Manual: curl -X POST http://127.0.0.1:<port>/api/analyze -d '{"root":"/etc"}' → 401 (missing token) or 403 (path outside root)

🤖 Generated with Claude Code

…sing headers

Replace exec() with execFile() in repoConverter to prevent shell injection
via malicious git URLs. Add validateRepoUrl() with protocol, structure, and
metacharacter checks. Apply safePath() to root/outputDir in server handlers
to block path traversal. Add per-session CSRF token required on all POST
requests. Set X-Content-Type-Options, X-Frame-Options, Referrer-Policy,
Cache-Control, and CSP headers on all responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pmclSF pmclSF merged commit debc311 into main Feb 27, 2026
6 checks passed
@pmclSF pmclSF deleted the fix/pre-release-security branch February 28, 2026 00:37
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