security(backend): Add comprehensive Git URL sanitization#89
Merged
DevanshuNEU merged 1 commit intoDec 11, 2025
Merged
Conversation
…tel#57) SECURITY FIXES: - Add command injection prevention (blocks ; && || | ` $() ${} etc.) - Add host allowlist (github.com, gitlab.com, bitbucket.org by default) - Add SSRF prevention for private IP ranges (10.x, 172.16-31.x, 192.168.x) - Block AWS metadata endpoint (169.254.169.254) - Add configurable ALLOWED_GIT_HOSTS env var for self-hosted instances IMPLEMENTATION: - Enhanced validate_git_url() with 6 security layers - Uses ipaddress module for proper CIDR checking - Validates URL format with strict regex patterns - SSH URL validation improved TESTS: - 36 comprehensive test cases covering: - Command injection (9 attack vectors) - SSRF prevention (7 private IP ranges) - Host allowlist enforcement - URL format validation - Custom env var configuration Closes OpenCodeIntel#57
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
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
Adds comprehensive security validation to Git URL handling to prevent command injection and SSRF attacks.
Problem
The existing URL validation was insufficient:
; && || | \$()`)Solution
Enhanced
validate_git_url()with 6 security layers:1. Command Injection Prevention
Blocks shell metacharacters before any URL parsing:
2. Host Allowlist
Only allows trusted Git hosting providers by default:
Configurable via
ALLOWED_GIT_HOSTSenv var for self-hosted instances.3. SSRF Prevention
Uses
ipaddressmodule for proper CIDR checking:4. URL Format Validation
Strict regex patterns for both HTTPS and SSH URLs.
5. DNS Resolution Check
Validates resolved IP isn't private (catches DNS rebinding attacks).
6. Improved SSH URL Handling
Proper parsing and validation of
git@host:user/repo.gitformat.Test Coverage
36 comprehensive test cases organized by attack vector:
TestCommandInjectionPrevention(9 tests)TestSSRFPrevention(7 tests)TestHostAllowlist(3 tests)TestUrlFormatValidation(4 tests)Files Changed
backend/services/input_validator.py- Enhanced validation logicbackend/tests/test_validation.py- Comprehensive security testsBreaking Changes
If using self-hosted Git servers, set:
Testing
Closes #57