Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions src/remote_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ static SSH_GIT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^git::(?P<url>ssh://((?P<user>[^@]+)@)?(?P<host>[^/]+)/(?P<repo>.+)\.git)//(?P<path>[^?]+)(\?ref=(?P<ref>[^?&]+)(&.*)?)?$").unwrap()
});

static AZURE_DEVOPS_SSH_GIT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^git::(?P<url>ssh://((?P<user>[^@]+)@)?(?P<host>[^/]+)/(?P<org>[^/]+)/(?P<project>[^/]+)/_git/(?P<repo>[^/]+))//(?P<path>[^?]+)(\?ref=(?P<ref>[^?&]+)(&.*)?)?$").unwrap()
});
Comment on lines +8 to +10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Azure SSH clone paths rejected

When a remote task uses an Azure DevOps SSH clone URL such as git::ssh://git@ssh.dev.azure.com/v3/org/project/repository//path/to/task, neither the generic .git-suffixed parser nor this new /_git/ parser recognizes it, causing task fetching to fail with “No provider found for file”.

Knowledge Base Used: Task Runner (mise run / mise tasks)

Comment on lines +8 to +10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n -C 6 'repo_structure\.path|full_path|destination\.join' \
  src/task/task_file_providers/remote_task_git.rs

Repository: jdx/mise

Length of output: 1612


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
fd -a 'remote_source\.rs|remote_task_git\.rs' . | sed 's#^\./##'

echo "== remote_source outline =="
if [ -f src/remote_source.rs ]; then
  ast-grep outline src/remote_source.rs --match AzureDevOpsSshGitRegex --view expanded || true
  wc -l src/remote_source.rs
  sed -n '1,90p' src/remote_source.rs
fi

echo "== remote_task_git outline and relevant sections =="
if [ -f src/task/task_file_providers/remote_task_git.rs ]; then
  wc -l src/task/task_file_providers/remote_task_git.rs
  ast-grep outline src/task/task_file_providers/remote_task_git.rs --view expanded || true
  sed -n '1,230p' src/task/task_file_providers/remote_task_git.rs
fi

echo "== search for path validation / confinement patterns =="
rg -n -C 4 'sanitize|normalize|RUSTSEC-2020-0071|relative|canonical|path\(|backslash|\\\\|validate|repo_file_path|full_path|storage_path' src/task src/remote_source.rs 2>/dev/null || true

Repository: jdx/mise

Length of output: 50365


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== exact target file sizes =="
wc -l src/remote_source.rs src/task/task_file_providers/remote_task_git.rs

echo "== src/remote_source.rs outline =="
ast-grep outline src/remote_source.rs --view expanded
echo

echo "== target regex and parse sections =="
rg -n -C 8 'AZURE_(DEVOPS_SSH_GIT_REGEX|DEVOPS_HTTP_GIT_REGEX)|fn parse|regex|matches' src/remote_source.rs
echo

echo "== exact target path construction/validation sections =="
rg -n -C 12 'get_repo_structure|repo_structure|destination\.join|path\.components|validate|split\(|full_path|get_local_path' src/task/task_file_providers/remote_task_git.rs
echo

echo "== focused path validation search =="
rg -n -C 4 'components\.any|PathBuf::from|\.to_path_buf\(|\\\.join\(|RUSTSEC-2020-0071|normalize|canonicalize|contains\(\[.*\\]' src/task/task_file_providers/remote_task_git.rs

Repository: jdx/mise

Length of output: 13530


Reject backslash path traversal before joining repo_structure.path.

RemoteSource::parse_git only checks / components, so git::ssh://.../_git/repo//..\\plugin?ref=master can pass and RemoteTaskGit::get_local_path joins the whole repo_structure.path into destination on Windows. Add a parser-level path validator that rejects .. with / or \, or normalize and confine the path before destination.join(&repo_file_path).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/remote_source.rs` around lines 8 - 10, Update RemoteSource::parse_git and
its path validation to reject traversal components represented with either
forward or backslash separators, including mixed-separator paths such as
..\plugin. Ensure the validated or normalized repo_structure.path is confined
before RemoteTaskGit::get_local_path joins it with destination, while preserving
valid repository paths and references.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repo files =="
git ls-files | sed -n '1,120p'

echo "== locate remote_source =="
fd -a 'remote_source\.rs$' . || true

echo "== search Azure regex and parse_git_with =="
rg -n "AZURE_DEVOPS_SSH_GIT_REGEX|AZURE_DEVOPS|parse_git_with|_git|_git/(?P<repo>|\\([^/\\]\\+\\))|v3|azure.com" . || true

echo "== file outline if present =="
if [ -f src/remote_source.rs ]; then
  ast-grep outline src/remote_source.rs || true
  echo "== src/remote_source.rs sample =="
  cat -n src/remote_source.rs | sed -n '1,220p'
fi

Repository: jdx/mise

Length of output: 14229


🌐 Web query:

Azure DevOps use SSH keys to authenticate Git SSH remote URL format ssh.dev.azure.com v3

💡 Result:

To authenticate with Azure DevOps using SSH, you must use the ssh.dev.azure.com hostname [1][2]. The standard format for a Git SSH remote URL in Azure DevOps is as follows: git@ssh.dev.azure.com:v3/{organization}/{project}/{repository} [3][4][5] Key details regarding this configuration include: 1. URL Structure: The URL includes a v3 segment, which is required for the pathing of Azure DevOps organizations, projects, and repositories [3][4][2]. 2. Setup Process: - You must generate an SSH key pair on your local machine and add the public key to your Azure DevOps user profile via the web portal (User Settings > SSH Public Keys) [1][3]. - If using a custom SSH key filename, it is highly recommended to configure your ~/.ssh/config file to map the host to the specific identity file to ensure the correct key is used [4][5][6]: Host ssh.dev.azure.com HostName ssh.dev.azure.com User git IdentityFile ~/.ssh/your_private_key IdentitiesOnly yes 3. Updating Remotes: If you have existing repositories using the older vs-ssh.visualstudio.com format, you can update them by running git remote set-url origin git@ssh.dev.azure.com:v3/{organization}/{project}/{repository} [1][2]. 4. Troubleshooting: You can verify your connection and key authentication by running the command ssh -T git@ssh.dev.azure.com [3][4][5]. If authentication fails, ensure your SSH agent has the key loaded or that your ~/.ssh/config file is correctly configured [4][6]. For self-hosted Azure DevOps Server instances, use the specific server hostname instead of ssh.dev.azure.com in both the URL and your SSH configuration [1][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n src/remote_source.rs | sed -n '220,320p'

python3 - <<'PY'
import re
pattern = re.compile(r"^git::(?P<url>ssh://((?P<user>[^@]+)@)?(?P<host>[^/]+)/(?P<org>[^/]+)/(?P<project>[^/]+)/_git/(?P<repo>[^/]+))//(?P<path>[^?]+)(\?ref=(?P<ref>[^?&]+)(&.*)?)?$")
for url in [
    "git::ssh://git@dev.azure/myorg/myproj/_git/example//terraform/myfile?ref=master",
    "git::ssh://git@ssh.dev.azure.com/v3/orG/prOj/ecH/example//terraform/myfile?ref=master",
    "git::ssh://git@ssh.dev.azure.com/g/v3/orG/prOj/ecH/example//terraform/myfile?ref=master",
]:
    m = pattern.match(url)
    print(f"url={url!r}")
    print("  match=", bool(m))
    if m:
        print("  url=", m.group("url"))
        print("  path=", m.group("path"))
        print("  ref=", m.group("ref"))
PY

Repository: jdx/mise

Length of output: 1390


Support the Azure DevOps v3 SSH layout.

Azure DevOps SSH remotes use ssh.dev.azure.com/v3/<org>/<project>/<repo> with paths like git::ssh://git@ssh.dev.azure.com/v3/orG/prOj/ecH/example//terraform/myfile?ref=master. The current regex only accepts /org/<project>/_git/<repo>, so add this layout and a regression test, or document the narrower URL contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/remote_source.rs` around lines 8 - 10, Extend AZURE_DEVOPS_SSH_GIT_REGEX
to accept the Azure DevOps v3 SSH layout with the /v3/<org>/<project>/<repo>
path while preserving existing Azure DevOps URL support and captures for
repository path and ref. Add a regression test covering the documented
ssh.dev.azure.com example, or explicitly document that only the existing
narrower URL contract is supported.


static HTTPS_GIT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^git::(?P<url>https?://(?P<host>[^/]+)/(?P<repo>.+)\.git)//(?P<path>[^?]+)(\?ref=(?P<ref>[^?&]+)(&.*)?)?$").unwrap()
});

static AZURE_DEVOPS_HTTPS_GIT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^git::(?P<url>https?://(?P<host>[^/]+)/(?P<org>[^/]+)/(?P<project>[^/]+)/_git/(?P<repo>[^/]+))//(?P<path>[^?]+)(\?ref=(?P<ref>[^?&]+)(&.*)?)?$").unwrap()
});

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoteGitSource {
pub url: String,
Expand All @@ -30,10 +38,12 @@ impl RemoteSource {

pub(crate) fn parse_git_ssh(file: &str) -> Option<RemoteGitSource> {
parse_git_with(&SSH_GIT_REGEX, file)
.or_else(|| parse_git_with(&AZURE_DEVOPS_SSH_GIT_REGEX, file))
}

pub(crate) fn parse_git_https(file: &str) -> Option<RemoteGitSource> {
parse_git_with(&HTTPS_GIT_REGEX, file)
.or_else(|| parse_git_with(&AZURE_DEVOPS_HTTPS_GIT_REGEX, file))
}

pub fn parse_http(file: &str) -> Option<RemoteHttpSource> {
Expand Down Expand Up @@ -135,6 +145,89 @@ mod tests {
);
}

#[test]
fn parses_azure_devops_git_ssh_sources() {
let source = RemoteSource::parse_git(
"git::ssh://git@dev.azure/myorg/myproj/_git/example//terraform/myfile?ref=master",
)
.unwrap();
assert_eq!(source.url, "ssh://git@dev.azure/myorg/myproj/_git/example");
assert_eq!(source.path, "terraform/myfile");
assert_eq!(source.git_ref, Some("master".to_string()));
}

#[test]
fn parses_azure_devops_git_ssh_sources_without_user() {
let source = RemoteSource::parse_git(
"git::ssh://dev.azure/myorg/myproj/_git/example//terraform/myfile",
)
.unwrap();
assert_eq!(source.url, "ssh://dev.azure/myorg/myproj/_git/example");
assert_eq!(source.path, "terraform/myfile");
assert_eq!(source.git_ref, None);
}

#[test]
fn parses_azure_devops_git_https_sources() {
let source = RemoteSource::parse_git(
"git::https://dev.azure:8080/myorg/myproj/_git/example//terraform/myfile?ref=master",
)
.unwrap();
assert_eq!(
source.url,
"https://dev.azure:8080/myorg/myproj/_git/example"
);
assert_eq!(source.path, "terraform/myfile");
assert_eq!(source.git_ref, Some("master".to_string()));
}

#[test]
fn parses_azure_devops_git_ref_before_additional_query_params() {
let source = RemoteSource::parse_git(
"git::https://dev.azure/myorg/myproj/_git/example//terraform/myfile?ref=master&depth=1",
)
.unwrap();
assert_eq!(source.git_ref, Some("master".to_string()));
}

#[test]
fn rejects_azure_devops_git_sources_without_paths() {
assert!(
RemoteSource::parse_git("git::https://dev.azure/myorg/myproj/_git/example?ref=master")
.is_none()
);
assert!(
RemoteSource::parse_git("git::ssh://user@dev.azure/myorg/myproj/_git/example")
.is_none()
);
}

#[test]
fn rejects_azure_devops_git_sources_with_unsafe_paths() {
assert!(
RemoteSource::parse_git("git::https://dev.azure/myorg/myproj/_git/example//../plugin")
.is_none()
);
assert!(
RemoteSource::parse_git(
"git::https://dev.azure/myorg/myproj/_git/example//plugin/../other"
)
.is_none()
);
assert!(
RemoteSource::parse_git(
"git::https://dev.azure/myorg/myproj/_git/example//plugin//other"
)
.is_none()
);
assert!(
RemoteSource::parse_git(
"git::https://dev.azure/myorg/myproj/_git/example//plugin/./other"
)
.is_none()
);
}

#[test]
fn parses_http_sources() {
assert!(RemoteSource::parse_http("http://myhost.com/test.txt").is_some());
Expand Down
56 changes: 56 additions & 0 deletions src/task/task_file_providers/remote_task_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ mod tests {
"git::ssh://git@myserver.com/example.git//terraform/myfile",
"git::ssh://user@myserver.com/example.git//myfile?ref=master",
"git::ssh://myserver.com/example.git//myfile?ref=master",
"git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::ssh://git@dev.azure/org/project/_git/example//terraform/myfile?ref=master",
"git::ssh://git@dev.azure:1222/org/project/_git/example//terraform/myfile?ref=master",
"git::ssh://git@dev.azure/org/project/_git/example//terraform/myfile",
"git::ssh://user@dev.azure/org/project/_git/example//myfile?ref=master",
"git::ssh://dev.azure/org/project/_git/example//myfile?ref=master",
];

for url in test_cases {
Expand All @@ -267,6 +273,9 @@ mod tests {
"git::ssh://user@myserver.com/example.git?ref=master",
"git::ssh://user@myserver.com/example.git",
"git::https://github.com/myorg/example.git//myfile?ref=v1.0.0",
"git::ssh://user@dev.azure/org/project/_git/example?ref=master",
"git::ssh://user@dev.azure/org/project/_git/example",
"git::https://dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
];

for url in test_cases {
Expand All @@ -287,6 +296,12 @@ mod tests {
"git::https://myserver.com/example.git//terraform/myfile",
"git::https://myserver.com/example.git//myfile?ref=master",
"git::http://localhost:8080/repo.git//xtasks/lint/remote-task", // HTTP support for local testing
"git::https://dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::https://dev.azure/org/project/_git/example//terraform/myfile?ref=master",
"git::https://dev.azure:8080/org/project/_git/example//terraform/myfile?ref=master",
"git::https://dev.azure/org/project/_git/example//terraform/myfile",
"git::https://dev.azure/org/project/_git/example//myfile?ref=master",
"git::http://localhost:8080/org/project/_git/example//xtasks/lint/remote-task", // HTTP support for local testing
];

for url in test_cases {
Expand All @@ -304,6 +319,9 @@ mod tests {
"git::https://myserver.com/example.git?ref=master",
"git::https://user@myserver.com/example.git",
"git::ssh://git@github.com/myorg/example.git//myfile?ref=v1.0.0",
"git::https://dev.azure/org/project/_git/example?ref=master",
"git::https://user@dev.azure/org/project/_git/example",
"git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
Comment on lines +322 to +324

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant Rust source and tests around the referenced lines.
if [ -f src/task/task_file_providers/remote_task_git.rs ]; then
  echo "== file exists =="
  wc -l src/task/task_file_providers/remote_task_git.rs
  echo "== outline =="
  ast-grep outline src/task/task_file_providers/remote_task_git.rs --view compact || true
  echo "== lines 280-345 =="
  sed -n '280,345p' src/task/task_file_providers/remote_task_git.rs | nl -ba -v280
else
  echo "== file missing =="
  fd -a 'remote_task_git.rs' .
fi

echo "== search parse_https and credential-related tests/code =="
rg -n "parse_https|credential|user@|test|assert|invalid" src/task/task_file_providers/remote_task_git.rs src || true

Repository: jdx/mise

Length of output: 442


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file stats =="
wc -l src/task/task_file_providers/remote_task_git.rs

echo "== ast outline expanded/main sections =="
ast-grep outline src/task/task_file_providers/remote_task_git.rs --view signatures || true

echo "== lines 280-345 with line numbers =="
awk 'NR>=280 && NR<=345 {printf "%5d\t%s\n", NR, $0}' src/task/task_file_providers/remote_task_git.rs

echo "== search parse_https and credential-related code/tests =="
rg -n "parse_https|credential|user@|test|assert" src/task/task_file_providers/remote_task_git.rs || true

echo "== deterministic URL path split check from source text =="
python3 - <<'PY'
from pathlib import Path
s = Path('src/task/task_file_providers/remote_task_git.rs').read_text()
for needle in [
    'fn parse_https',
    'git::https://user@dev.azure/org/project/_git/example',
    'git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v1.0.0'
]:
    print(needle, 'present=', needle in s)
    if needle in s:
        idx = s.index(needle)
        start=max(0, idx-800); end=min(len(s), idx+800)
        print("context:")
        for i, line in enumerate(s[start:].splitlines(), max(1, s[:start].count('\n')+1)):
            if idx <= start + sum(len(l)+1 for l in s[start:].splitlines()[:i-1]) < idx+800:
                pass
            print(f"{i}\t{line}")
PY

Repository: jdx/mise

Length of output: 47400


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate RemoteSource implementation =="
rg -n "struct RemoteSource|impl RemoteSource|parse_git_https|parse_git_ssh|credential|https://user|ssh://user" --glob '*.rs' . || true

echo "== read likely files around RemoteSource =="
while IFS= read -r line; do
  file="${line##*:}"
  echo "--- $file"
  wc -l "$file"
  ast-grep outline "$file" --view signatures || true
  sed -n '1,520p' "$file" | awk 'NR>=1 && NR<=520 {printf "%5d\t%s\n", NR, $0}'
done < <(rg -l "parse_git_https|parse_git_ssh" --glob '*.rs' .)

Repository: jdx/mise

Length of output: 21165


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== src/remote_source.rs =="
wc -l src/remote_source.rs
sed -n '1,150p' src/remote_source.rs | awk 'NR>=1 && NR<=150 {printf "%5d\t%s\n", NR, $0}'

echo "== src/remote_source.rs tests around credential cases =="
sed -n '110,220p' src/remote_source.rs | awk 'NR>=1 && NR<=110 {printf "%5d\t%s\n", NR+109, $0}'

Repository: jdx/mise

Length of output: 10870


Add an Azure HTTPS credential case with a //<task-path>.

git::https://user@dev.azure/org/project/_git/example fails parsing before the credential condition because there is no task path. Add //myfile so assert!(parse_https(...).is_none()) exercises credential rejection when HTTPS supports a task path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/task/task_file_providers/remote_task_git.rs` around lines 322 - 324,
Update the Azure HTTPS credential test case in the URL fixture list to append a
task path such as //myfile, ensuring parse_https reaches credential rejection
rather than failing earlier due to a missing task path. Keep the existing user
credential and assertion behavior unchanged.

];

for url in test_cases {
Expand Down Expand Up @@ -367,6 +385,24 @@ mod tests {
"terraform/myfile",
None,
),
(
"git::https://dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"https://dev.azure/org/project/_git/example",
"myfile",
Some("v1.0.0".to_string()),
),
(
"git::https://dev.azure/org/project/_git/example//terraform/myfile?ref=master",
"https://dev.azure/org/project/_git/example",
"terraform/myfile",
Some("master".to_string()),
),
(
"git::https://dev.azure/org/project/_git/example//terraform/myfile",
"https://dev.azure/org/project/_git/example",
"terraform/myfile",
None,
),
];

for (url, expected_repo, expected_path, expected_branch) in test_cases {
Expand All @@ -392,6 +428,11 @@ mod tests {
"git::ssh://user@myserver.com/example.git//myfile?ref=master",
false,
),
(
"git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v2.0.0",
false,
),
(
"git::ssh://git@github.com/example.git//myfile?ref=v1.0.0",
"git::ssh://git@github.com/example.git//subfolder/mysecondfile?ref=v1.0.0",
Expand All @@ -402,6 +443,11 @@ mod tests {
"git::ssh://git@github.com/myorg/example.git//subfolder/mysecondfile?ref=v1.0.0",
true,
),
(
"git::ssh://git@dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::ssh://git@dev.azure/org/project/_git/example//subfolder/mysecondfile?ref=v1.0.0",
true,
),
];

for (first_url, second_url, expected) in test_cases {
Expand All @@ -428,6 +474,11 @@ mod tests {
"git::https://bitbucket.com/myorg/example.git//myfile?ref=v1.0.0",
false,
),
(
"git::https://dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::https://dev.azure/org/project/_git/example//myfile?ref=v2.0.0",
false,
),
(
"git::https://github.com/myorg/example.git//myfile?ref=v1.0.0",
"git::https://github.com/myorg/example.git//subfolder/myfile?ref=v1.0.0",
Expand All @@ -438,6 +489,11 @@ mod tests {
"git::https://github.com/example.git//subfolder/myfile?ref=v1.0.0",
true,
),
(
"git::https://dev.azure/org/project/_git/example//myfile?ref=v1.0.0",
"git::https://dev.azure/org/project/_git/example//subfolder/myfile?ref=v1.0.0",
true,
),
];

for (first_url, second_url, expected) in test_cases {
Expand Down