security: harden remote URL validation at config parse time#3210
Open
harry-miller-trimble wants to merge 1 commit intogastownhall:mainfrom
Open
security: harden remote URL validation at config parse time#3210harry-miller-trimble wants to merge 1 commit intogastownhall:mainfrom
harry-miller-trimble wants to merge 1 commit intogastownhall:mainfrom
Conversation
Add strict security validation for remote URLs and remote names to prevent injection attacks when multi-remote support lands. Changes: - Add ValidateRemoteURL() with control character rejection, CLI flag injection prevention, scheme allowlist, and per-scheme structural validation (host/path requirements) - Add ValidateRemoteName() aligned with existing peer-name policy (letter-start, alphanumeric + hyphen/underscore, max 64 chars) - Add MatchesRemotePattern() and ValidateRemoteURLWithPatterns() for enterprise lockdown via federation.allowed-remote-patterns config - Move config validation from simple IsRemoteURL() classifier to strict ValidateRemoteURL() security boundary - Add defense-in-depth validation in AddCLIRemote/RemoveCLIRemote - Add validation at clone entry points (cache.Ensure, bootstrap) - Tighten SCP-style URL regex to exclude control characters in path - Add comprehensive test coverage for null bytes, control chars, newline injection, CLI flag injection, scheme validation, structural validation, remote name edge cases, and pattern matching Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a5e2dba to
25af1e0
Compare
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
Hardens remote URL validation to prevent injection attacks when multi-remote support lands.
Changes
New validation functions in
internal/remotecache/url.goValidateRemoteURL()— strict security boundary that rejects control characters (null bytes, newlines, tabs, ANSI escapes), CLI flag injection (leading dash), disallowed schemes, and structurally invalid URLs per scheme (missing host/org/bucket)ValidateRemoteName()— allowlist validation aligned with existing peer-name policy ([a-zA-Z][a-zA-Z0-9_-]*, max 64 chars)ValidateRemoteURLWithPatterns()— enterprise lockdown via glob-stylefederation.allowed-remote-patternsconfigDefense-in-depth validation points
validateSyncConfig)AddCLIRemote,RemoveCLIRemote)cache.Ensure,BootstrapFromGitRemoteWithDB)Config
federation.allowed-remote-patternsconfig key (empty = no restriction)Tests
Security Context
When multi-remote support lands, remote names and URLs will be passed to
doltviaexec.Command. While Go'sexec.Commanduses argument arrays (no shell interpolation), URLs with control characters or leading dashes could still cause issues with git's URL parsing or credential helpers. This change validates all remote inputs at multiple boundaries before they reach subprocess calls.Files changed (8 files, +474/-8)
Rebased from fork PR harry-miller-trimble#32