Vscode Edit Handler
Overview
The VS Code edit handler (/_edit/ endpoint) allows opening documentation files directly in VS Code from the preview server. Since it executes local commands, it implements multiple security layers.
Security Model
Threat Model
Potential Attackers:
- Malicious HTTP requests from unauthorized users
- Path traversal attacks to access files outside docs directory
- Command injection via file paths or IPC socket paths
- Symlink attacks to access sensitive system files
- Environment variable injection via socket paths
Assets Protected:
- Local file system (read access via VS Code)
- Command execution (VS Code CLI)
- Environment variables
Security Controls
1. Feature Flag Protection
Control: Feature disabled by default, requires explicit --vscode flag
Threat Mitigated: Unauthorized access
OWASP: A01:2021 Broken Access Control
2. Mode Restriction
Control: Only works in preview mode (single local repository)
Threat Mitigated: Multi-repository security boundary violations
OWASP: A01:2021 Broken Access Control
3. Path Traversal Protection
Control: Validates resolved paths stay within docs directory
Threat Mitigated: Path traversal (../../../etc/passwd)
OWASP: A01:2021 Broken Access Control
Additional Hardening:
- Directory separator enforcement to prevent prefix confusion
- Absolute path requirement
- Clean path normalization
4. Symlink Attack Prevention
Control: Rejects all symlinks
Threat Mitigated: Symlink attacks to escape docs directory
OWASP: A01:2021 Broken Access Control
CVE Examples: CVE-2022-24765 (Git symlink traversal)
5. File Type Restriction
Control: Only markdown files allowed
Threat Mitigated: Opening sensitive non-documentation files
OWASP: A01:2021 Broken Access Control
6. Command Injection Prevention
Control: No shell invocation (bash -c), direct exec only
Threat Mitigated: Shell injection attacks
OWASP: A03:2021 Injection
CWE: CWE-78 (OS Command Injection)
Previous vulnerable pattern:
7. IPC Socket Path Validation
Control: Multi-layered socket path validation
Threats Mitigated:
- Environment variable injection via newlines
- Malicious socket paths
- Relative path attacks
8. Execution Timeout
Control: 5 second timeout on command execution
Threat Mitigated: Resource exhaustion, hanging processes
OWASP: A05:2021 Security Misconfiguration
9. Validated Executable Paths
Control: Code CLI path from trusted locations only
Threat Mitigated: Malicious executable substitution
OWASP: A08:2021 Software and Data Integrity Failures
Security Testing
Test Coverage
- ✅ Feature flag enforcement
- ✅ Path traversal attempts
- ✅ Symlink detection and rejection
- ✅ IPC socket validation (injection attempts)
- ✅ File type restrictions
- ✅ Invalid paths and edge cases
Penetration Testing Scenarios
1. Path Traversal:
2. Symlink Attack:
3. Control Character Injection:
4. Feature Disabled:
Defense in Depth
Multiple security layers ensure that even if one control fails, others prevent exploitation:
- Feature Flag → Prevents access by default
- Mode Check → Limits to preview mode
- Path Validation → Blocks directory traversal
- Symlink Check → Prevents indirect traversal
- File Type → Limits to markdown only
- Direct Exec → No shell injection possible
- Socket Validation → Prevents environment injection
- Timeout → Limits resource usage
Security Recommendations
For Operators
- Only use
--vscodeflag in trusted development environments - Never expose preview server to untrusted networks
- Use preview mode only with trusted repositories
- Monitor logs for suspicious access attempts
For Developers
- Never remove security validations
- Add tests for new security controls
- Run security-focused linters (gosec)
- Review shell command execution patterns
- Validate all external inputs
Incident Response
If security issue is discovered:
- Disable feature immediately (remove
--vscodeflag) - Check logs for exploitation attempts
- Report via security policy
- Apply patch and test thoroughly
- Update security documentation
References
Changelog
- 2026-01-05: Initial security review and hardening
- Removed shell invocation (
bash -c) - Added symlink detection
- Added IPC socket path validation
- Improved path traversal protection
- Removed shell invocation (
[vscode-edit-handler](https://docs.home.luguber.info/_uid/2fc65921-3513-436e-aa99-8cb4202560cb/)