Skip to content

security: harden remote URL validation at config parse time#3210

Open
harry-miller-trimble wants to merge 1 commit intogastownhall:mainfrom
harry-miller-trimble:upstream/harden-remote-url
Open

security: harden remote URL validation at config parse time#3210
harry-miller-trimble wants to merge 1 commit intogastownhall:mainfrom
harry-miller-trimble:upstream/harden-remote-url

Conversation

@harry-miller-trimble
Copy link
Copy Markdown
Contributor

Summary

Hardens remote URL validation to prevent injection attacks when multi-remote support lands.

Changes

New validation functions in internal/remotecache/url.go

  • ValidateRemoteURL() — 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-style federation.allowed-remote-patterns config

Defense-in-depth validation points

  • Config parse time (validateSyncConfig)
  • CLI remote operations (AddCLIRemote, RemoveCLIRemote)
  • Clone entry points (cache.Ensure, BootstrapFromGitRemoteWithDB)

Config

  • Added federation.allowed-remote-patterns config key (empty = no restriction)

Tests

  • 40+ test cases covering null bytes, control characters, newline injection, CLI flag injection, scheme validation, per-scheme structural validation, remote name edge cases, pattern matching, and allowed-remote-patterns enforcement

Security Context

When multi-remote support lands, remote names and URLs will be passed to dolt via exec.Command. While Go's exec.Command uses 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

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>
@harry-miller-trimble harry-miller-trimble force-pushed the upstream/harden-remote-url branch from a5e2dba to 25af1e0 Compare April 12, 2026 06:07
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.

1 participant