Skip to content

fix(security): handle GitLab nested groups in URL parsing - #768

Merged
max-sixty merged 3 commits into
mainfrom
glab-slash
Jan 20, 2026
Merged

max-sixty merged 3 commits into
mainfrom
glab-slash

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • Fix security vulnerability where GitLab nested group URLs produced non-unique project identifiers
  • URLs like gitlab.com/group/subgroup/repo1 and gitlab.com/group/subgroup/repo2 previously both resolved to identifier gitlab.com/group/subgroup, allowing approval bypass
  • Now correctly treats all path segments except the last as the namespace, producing unique identifiers

Problem

The GitRemoteUrl::parse() function assumed exactly /<owner>/<repo> structure. For nested GitLab groups:

  • Before: gitlab.com/group/subgroup/repo → owner=group, repo=subgroup (repo dropped!)
  • project_identifier: gitlab.com/group/subgroup (same for all repos in that group)

This meant approvals for one repo would apply to sibling repos, bypassing command approval security.

Solution

Introduced split_namespace_repo() helper that treats everything before the last path segment as the namespace:

  • After: owner=group/subgroup, repo=repo
  • project_identifier: gitlab.com/group/subgroup/repo (unique per repo)

Test plan

  • Unit tests for all URL formats (https, http, git://, ssh://, git@)
  • Security uniqueness tests verifying different repos produce different identifiers
  • Edge case tests (deep nesting, special characters, malformed paths)
  • Adversarial security tests (15 tests covering collision attacks, host spoofing, unicode lookalikes, path traversal)
  • All 2119 existing tests pass
  • All lints pass

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

max-sixty and others added 2 commits January 20, 2026 11:44
The GitRemoteUrl parser previously assumed exactly /<owner>/<repo>
structure, which silently dropped segments for GitLab nested groups.
For gitlab.com/group/subgroup/repo, the parser would return owner="group"
and repo="subgroup", dropping the actual repo name.

This caused project_identifier() to be non-unique across repos in the
same parent group, allowing approval bypass - approvals for one repo
would apply to sibling repos.

Fix: Treat all path segments except the last as the namespace. Now
gitlab.com/group/subgroup/repo correctly returns owner="group/subgroup"
and repo="repo", with project_identifier="gitlab.com/group/subgroup/repo".

Added comprehensive tests for:
- All URL formats (https, http, git://, ssh://, git@)
- Deep nesting (7+ levels)
- Security uniqueness verification
- Edge cases (double slashes, .git suffixes, malformed paths)

Co-Authored-By: Claude <[email protected]>
Restructure adversarial tests to ensure all assertions execute:
- Use .unwrap() for URLs that should parse successfully
- Use is_none() assertions for URLs that should fail parsing
- Add https:// variants where SSH parsing fails but https:// succeeds

This fixes the codecov/patch coverage requirement.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 5b6ede3 into main Jan 20, 2026
@max-sixty
max-sixty deleted the glab-slash branch January 20, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant