refactor(security): one answer for SSH git remotes
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m48s

#256 let `ssh://` through the URL guard (host rules still applied) and #255
then rejected every SSH remote at the clone, because the agent holds no git
SSH key any more. Two rules, two messages, for one decision.

The guard now refuses the `ssh` scheme outright, so the refusal happens at the
same place as `file://` and `git://`, and `pipeline::git::reject_ssh_url` stays
as the check for the scp-style form (`git@host:org/repo`), which carries no
scheme at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5 committed 2026-09-21 00:04:26 +02:00
1 parent c7fc7af249
commit a4c37b45cb
1 file changed
+8 -4
+8 -4
View File
@@ -59,8 +59,10 @@ pub enum NetGuardError {
const HTTP_SCHEMES: &[&str] = &["http", "https"];
/// Schemes accepted for a git remote. `file://` and `git://` are refused: the
/// first reads the agent's own disk (including other tenants' checkouts), the
/// second is unauthenticated and cleartext.
const GIT_SCHEMES: &[&str] = &["http", "https", "ssh"];
/// second is unauthenticated and cleartext. `ssh://` is refused too, because
/// the agent holds no git SSH key — see `pipeline::git::reject_ssh_url`, which
/// gives the same answer for the scp-style form that carries no scheme.
const GIT_SCHEMES: &[&str] = &["http", "https"];
/// Host suffixes that only mean something inside a private network.
const INTERNAL_SUFFIXES: &[&str] = &[
@@ -451,7 +453,7 @@ mod tests {
}
#[test]
fn git_urls_refuse_file_and_git_schemes_but_allow_ssh() {
fn git_urls_refuse_file_git_and_ssh_schemes() {
assert!(guard()
.check_git_url("file:///tmp/compliance-scanner/repos/other-tenant/app")
.is_err());
@@ -462,9 +464,11 @@ mod tests {
assert!(guard()
.check_git_url("https://example.com/org/repo.git")
.is_ok());
// The agent has no SSH key to offer, so an SSH remote could only
// authenticate as somebody else.
assert!(guard()
.check_git_url("ssh://git@example.com:22222/org/repo.git")
.is_ok());
.is_err());
// …but not to an internal host.
assert!(guard().check_git_url("https://gitea/org/repo.git").is_err());
}