feat(security): implement critical security hardening (CWE-22, CWE-88, CWE-400, CWE-346)#13
Merged
Razshy merged 2 commits intoSidenai:mainfrom Apr 9, 2026
Merged
Conversation
…, CWE-400, CWE-346) This commit addresses four critical security vulnerabilities identified during code review, implementing defense-in-depth measures across the Tauri backend: ## 1. PATH TRAVERSAL PROTECTION (CWE-22) **Problem**: File system commands only validated empty paths and NUL bytes, allowing attackers to use ../ sequences to access files outside intended directories. **Solution**: Created centralized validation.rs module with validate_path() that uses Path::components() to reject ParentDir components. **Impact**: All file operations now protected against path traversal. **Files**: NEW: validation.rs, UPDATED: fs.rs, mod.rs ## 2. COMMAND INJECTION PREVENTION (CWE-88) **Problem**: git.rs's run_git() executed git commands without validating path or arguments, allowing injection. **Solution**: Added validate_args() and integrated both validators into run_git(). **Impact**: All git operations now validate inputs before execution. **Files**: UPDATED: git.rs ## 3. RESOURCE EXHAUSTION PROTECTION (CWE-400) **Problem**: storage_set() accepted arbitrary-length values, enabling DoS via huge data. **Solution**: Added MAX_KEY_LENGTH (256B) and MAX_VALUE_LENGTH (1MB) limits. **Impact**: Storage now rejects oversized values. **Files**: UPDATED: storage.rs ## 4. PROXY ALLOWLIST BYPASS FIX (CWE-346) **Problem**: is_host_allowed() was case-sensitive, allowing bypass via mixed-case hostnames. **Solution**: Normalize hostnames to lowercase before comparison. **Impact**: Proxy allowlist now case-insensitive. **Files**: UPDATED: proxy.rs ## Testing - All validation unit tests pass (7/7) - cargo check: success, no warnings - Backward compatible, no breaking changes Co-authored-by: Akarsh Bandi <your-email@example.com>
- Downgrade @tauri-apps/plugin-dialog from 2.7.0 to 2.6.0 - Add pnpm-lock.yaml for pnpm lockfile - Fixes version mismatch with Cargo.toml tauri-plugin-dialog v2.6.0
Razshy
added a commit
that referenced
this pull request
Apr 9, 2026
- Path traversal protection via centralized validate_path() - Git argument NUL byte validation - Storage size limits (256B keys, 1MB values) - Case-insensitive proxy hostname matching Co-authored-by: Akarsh Bandi <bandiakarsh@gmail.com>
Collaborator
|
Merged with fixes:
Thanks for the contribution. |
Alex-Keagel
pushed a commit
to Alex-Keagel/caduceus-ide
that referenced
this pull request
Apr 14, 2026
…-346) - Path traversal protection via centralized validate_path() - Git argument NUL byte validation - Storage size limits (256B keys, 1MB values) - Case-insensitive proxy hostname matching Co-authored-by: Akarsh Bandi <bandiakarsh@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Summary
This PR addresses four critical security vulnerabilities identified during a comprehensive code review of the SideX Tauri backend. The changes implement defense-in-depth measures to harden the application against common attack vectors.
🔒 Security Fixes
1. Path Traversal Protection (CWE-22) ✅
Problem: File system commands only validated empty paths and NUL bytes, allowing attackers to use
../sequences to access files outside intended directories (e.g.,../../../etc/passwd).Solution: Created a centralized
validation.rsmodule withvalidate_path()that usesPath::components()to rejectParentDircomponents. This properly handles platform-specific separators and prevents directory traversal attacks.Files Changed:
src-tauri/src/commands/validation.rs(NEW - 136 lines with comprehensive unit tests)src-tauri/src/commands/fs.rs(updated to use shared validation)src-tauri/src/commands/mod.rs(added validation module)Impact: All file operations (
read_file,write_file,read_dir,stat,mkdir,remove,rename) are now protected against path traversal attacks.2. Command Injection Prevention (CWE-88) ✅
Problem: The
git.rsmodule'srun_git()function executed git commands without validating the repository path or arguments, allowing potential injection via malicious paths or arguments containing shell metacharacters.Solution:
validate_args()function to reject empty arguments and NUL bytesrun_git()to call bothvalidate_path()andvalidate_args()before executionFiles Changed:
src-tauri/src/commands/git.rs(added validation imports and input sanitization)src-tauri/src/commands/validation.rs(newvalidate_args()function)Impact: All git operations (
status,diff,log,commit,push,pull,fetch,stash,branch,reset) now validate inputs before spawning git processes.3. Resource Exhaustion Protection (CWE-400) ✅
Problem: The
storage_set()function accepted arbitrary-length keys and values, enabling denial-of-service attacks by storing huge amounts of data (e.g., 1GB string) to exhaust memory and disk space.Solution: Added size limits:
MAX_KEY_LENGTH: 256 bytes (sufficient for typical storage keys)MAX_VALUE_LENGTH: 1 MB (prevents memory exhaustion while allowing reasonable configuration data)Files Changed:
src-tauri/src/commands/storage.rs(added constants and validation checks)Impact: Storage operations now reject oversized values with clear, descriptive error messages.
4. Proxy Allowlist Bypass Fix (CWE-346) ✅
Problem: The
is_host_allowed()function performed case-sensitive hostname comparison, allowing attackers to bypass the allowlist using mixed-case hostnames (e.g.,"OpenVSX.org"vs"openvsx.org").Solution: Normalize both allowed hosts and target host to lowercase using
to_ascii_lowercase()before comparison. This ensures case-insensitive matching while preserving the subdomain logic.Files Changed:
src-tauri/src/commands/proxy.rs(case-insensitive hostname matching)Impact: Proxy requests correctly enforce the allowlist regardless of hostname case variation.
🧪 Testing
📐 Code Quality
validation.rsfor reuse🎨 Changes Summary
validation.rsfs.rsgit.rsstorage.rsproxy.rsmod.rsNone - All changes are internal security hardening that do not affect the public API.
🤝 Contributing
This fix was developed as part of a security audit of the SideX codebase. We followed the project's existing coding conventions and ensured all changes align with Rust best practices.
📋 Related Issues
Co-authored-by: Akarsh Bandi bandiakarsh@gmail.com
Security Review: Comprehensive code review conducted on Tauri backend