Skip to content

fix: harden security — patch 7 critical and 3 high vulnerabilities - #29

Open
dngnguyen wants to merge 1 commit into
Ngxba:masterfrom
dngnguyen:fix/security-hardening
Open

fix: harden security — patch 7 critical and 3 high vulnerabilities#29
dngnguyen wants to merge 1 commit into
Ngxba:masterfrom
dngnguyen:fix/security-hardening

Conversation

@dngnguyen

Copy link
Copy Markdown

Summary

Full security audit identified 7 critical and 10 high severity vulnerabilities. This PR fixes all 7 critical and 3 high-priority issues with a comprehensive test suite.

No backdoors, telemetry, or malicious code was found in the codebase.

Critical Fixes

# Issue File Fix
C2 Command injection via exec() server/api/reveal.post.ts exec()execFile() (no shell) + path restriction
C3 Arbitrary file read (no path restriction) server/api/files.get.ts Added isUnderAllowedPath() — restricts to ~/.claude
C4 Arbitrary directory listing server/api/directories.get.ts Restricted to homedir() + ~/.claude
C5 SDK hardcoded bypassPermissions claudeSdk.ts, claudeProvider.ts Default to 'default' permission mode
C6 XSS — 6 v-html sinks, no sanitizer app/utils/markdown.ts + components Added DOMPurify to all render functions
C7 MCP import writes arbitrary configs server/api/mcp/import.post.ts Schema validation, field whitelist, URL validation

High Fixes

# Issue File Fix
H1 Path traversal via agent slugs server/utils/agentUtils.ts Reject ..///\ in slugs + safeClaudePath()
H3 Debug endpoint leaks process.env.PATH server/api/debug/claude-cli.get.ts Removed pathEnvironment from response
H9 PTY processes orphaned on shutdown server/utils/cliSession.ts Added SIGTERM/SIGINT cleanup handlers

New Files

  • server/utils/path-security.ts — Core security utilities: safePath(), safeClaudePath(), isUnderAllowedPath(), getAllowedPaths()
  • tests/security/path-security.test.ts — 10 unit tests for path security
  • tests/security/xss-sanitization.test.ts — 6 unit tests for XSS fixes
  • tests/security/api-security-e2e.test.ts — 21 E2E tests hitting live endpoints
  • vitest.config.ts — Test framework setup

Dependencies Added

  • dompurify + @types/dompurify — HTML sanitization for XSS prevention
  • vitest, @nuxt/test-utils, happy-dom — Test framework (dev)

Test plan

  • 37/37 tests pass (npm run test)
  • Unit tests: safePath() blocks traversal, decodeHTMLEntities safe, lang attribute escaped
  • E2E tests: /api/files?path=/etc/passwd → 403, /api/reveal shell injection → blocked, /api/directories?path=/etc/ → 403, agent slug traversal → 400, MCP import validation → 400 for invalid configs
  • Build passes (npx nuxi build)
  • Dev server smoke-tested at localhost:3000
  • Existing functionality unaffected — agents, skills, workflows load normally

- C2: Replace exec() with execFile() in reveal.post.ts to prevent command injection
- C3: Add path restriction to files.get.ts — block arbitrary file reads outside ~/.claude
- C4: Restrict directories.get.ts to home directory and ~/.claude
- C5: Default SDK permission mode to 'default' instead of 'bypassPermissions'
- C6: Add DOMPurify to sanitize all markdown v-html output, fix XSS amplifier in decodeHTMLEntities
- C7: Validate MCP import config schema — require command/url, whitelist fields, validate URLs
- H1: Add path traversal protection to agent slugs via safePath utility
- H3: Remove PATH environment variable leak from debug endpoint
- H9: Add SIGTERM/SIGINT handlers for PTY session cleanup

Adds server/utils/path-security.ts with safePath(), safeClaudePath(), isUnderAllowedPath().
Adds vitest test suite: 37 tests (unit + E2E) verifying all security fixes.
@bsolca

bsolca commented Apr 19, 2026

Copy link
Copy Markdown

Hey @dngnguyen, I was just looking through the repo and stumbled on this PR. Really nice work on hardening the security. The changes look thoughtful and it should make running this locally feel a lot safer. Hope to see this landed.

cbeaulieu-gt added a commit to cbeaulieu-gt/claude-code-cli-ui that referenced this pull request Jun 22, 2026
…view fixes (#2)

Cherry-picks upstream Ngxba/claude-code-cli-ui PR Ngxba#29 (6 critical + 3 high vuln fixes) onto the fork, plus cross-platform path-security fixes and resolutions for all Codex review findings (projectDir bypass, SSR XSS, e2e HOME isolation, signal-cleanup, MCP disabled-flag preservation). Remaining file-read-scope hardening tracked in #3.

Closes #1
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.

2 participants