Skip to content

Security: Command injection risk via git clone with user-supplied URL #567

@gkorland

Description

@gkorland

Description

In api/project.py:35, a user-supplied URL is passed directly to git clone:

cmd = ["git", "clone", url, str(path)]
subprocess.run(cmd, check=True, capture_output=True, text=True)

While validators.url() is checked beforehand, it does not reject dangerous URL schemes like file://, ssh://, or git://. Combined with @public_access on analyze_repo, this endpoint is reachable without authentication when CODE_GRAPH_PUBLIC=1.

Impact

An attacker could:

  • Use file:// URLs to read local files on the server
  • Use ssh:// or git:// URLs to probe internal network services
  • Potentially trigger SSRF attacks

Suggested Fix

Restrict to HTTPS-only URLs:

parsed = urlparse(url)
if parsed.scheme not in ('https',):
    raise ValueError(f'Only HTTPS URLs are allowed, got: {parsed.scheme}')

Context

Found during code review of PR #522.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions