From a4c37b45cb2f555ec5a70b90131fa1325df96757 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 21 Sep 2026 00:04:26 +0200 Subject: [PATCH] refactor(security): one answer for SSH git remotes #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) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-core/src/net_guard.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compliance-core/src/net_guard.rs b/compliance-core/src/net_guard.rs index 1c8749e..0ab8674 100644 --- a/compliance-core/src/net_guard.rs +++ b/compliance-core/src/net_guard.rs @@ -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()); }