Skip to content

Tighten regex in artifact tool download#46714

Open
ayushhgarg-work wants to merge 1 commit intoAzure:mainfrom
ayushhgarg-work:ayushhgarg/regexfix
Open

Tighten regex in artifact tool download#46714
ayushhgarg-work wants to merge 1 commit intoAzure:mainfrom
ayushhgarg-work:ayushhgarg/regexfix

Conversation

@ayushhgarg-work
Copy link
Copy Markdown
Member

Changes

  1. Adds path traversal (ZipSlip) validation to extractall() in _redirect_artifacts_tool_path() (CWE-22)
  2. Tightens greedy regex (.*)([^/]+) to prevent unanchored capture from matching slashes

Motivation

  • ICM 115323: extractall() without member path validation allows crafted zip archives to write outside the extraction directory (Defense in Depth / Low / Fix in Next Version)
  • ICM 113651: Greedy regex could theoretically capture attacker-controlled path segments (Not a Vulnerability / best practice fix per MSRC)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to harden the ArtifactTool download flow in azure-ai-ml by tightening Azure DevOps organization URL parsing (and, per the PR description, adding ZipSlip/path traversal protection during zip extraction).

Changes:

  • Tightened organization URL regex capture groups from (.*) to ([^/]+) for both *.visualstudio.com and dev.azure.com/{org} formats.
  • (Not present in the current diff) The PR description states ZipSlip validation was added for ZipFile.extractall(), but the implementation still uses extractall() without member path validation.

Comment on lines +174 to 180
organization_pattern = r"https:\/\/([^/]+)\.visualstudio\.com"
result = re.findall(pattern=organization_pattern, string=organization)
if result:
organization_name = result[0]
else:
organization_pattern = r"https:\/\/dev\.azure\.com\/(.*)"
organization_pattern = r"https:\/\/dev\.azure\.com\/([^/]+)"
result = re.findall(pattern=organization_pattern, string=organization)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants