The docs for the group-level NuGet API said the id could be a group ID or a full group path. The code disagreed. A request with the path failed with {"error":"id is invalid"} before GitLab ever looked the group up.
This is the story of gitlab-org/gitlab!272719. I'll cover the regexp that rejected a valid path, why I did not treat this as a docs-only correction, and the review that added a private-group example and a note about encoding /.
The issue: documented, then rejected
The issue was gitlab-org/gitlab#641185, opened by Viktor Bogdan. The NuGet API documentation describes id as:
The group ID or full group path.
A numeric group ID worked. A path such as /api/v4/groups/example-group/-/packages/nuget/index.json did not. The failure was a 400 from parameter validation, not a 404 from group lookup.
The restriction lived in lib/api/nuget_group_packages.rb:
params do
requires :id, types: [Integer, String], desc: 'ID of the group.',
regexp: ::API::Concerns::Packages::Nuget::PrivateEndpoints::POSITIVE_INTEGER_REGEX
end
POSITIVE_INTEGER_REGEX is a useful check for a take query parameter on the search endpoint. On :id, it made the String type in that requires line unreachable for any real group path. Other group package APIs — Maven, PyPI, npm, Debian — do not do this. They declare :id as an integer or a string, and they put the resource under API::NAMESPACE_OR_PROJECT_REQUIREMENTS.
Why this is not a docs-only correction
It is tempting, on a mismatch like this, to change the docs to say "group ID only" and move on. I looked at whether the integer restriction was intentional before doing the opposite.
NuGet v2 and v3 routes (/nuget/v2, /nuget/index, metadata, query, symbol files) all sit under groups/:id/-/packages/nuget/. They do not compete with :id for a path segment.
ServiceIndexPresenter always builds resource URLs with project_or_group.id. Once a client has fetched the index by path, follow-up requests already use numeric IDs, which already worked. Allowing a path on the first request does not require every later URL to accept a path too.
find_group / find_authorized_group! already accept an ID or a path. The integer regexp was not protecting a lookup that can only handle numbers. It was rejecting the value before that lookup ran.
So the docs were describing the API we should have, and the one the other package APIs already have. The code was the bug.
The fix: the same declaration as the other group package APIs
The production change drops the regexp and aligns the parameter with Maven and friends:
params do
requires :id, types: [Integer, String], desc: 'ID or URL-encoded path of the group.'
end
resource :groups, requirements: ::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
The resource already used API::NAMESPACE_OR_PROJECT_REQUIREMENTS, so :id remains a single path segment. A nested group still has to be URL-encoded as parent%2Fchild, the same way as the rest of the Groups API. A raw parent/child does not match the route.
The OpenAPI v3 description was updated to match. The markdown docs later gained one more clause, after review: "Encode / in a nested path as %2F."
The review: test a private path, and keep the pipe table
Moaz Khalifa's first suggestion was about coverage, and it was right. The first version used a path on the public service index, and not much else:
Add one positive spec for a path ID on an authenticated private endpoint. Only the public service index is tested with a path. Nothing checks that
find_authorized_group!resolves a path on a private route. One example that usesCGI.escape(group.full_path)on/queryor a metadata route closes the gap. A v2 index example with a path would also help.
A public index.json passing with a path does not prove that a private /query will authorize the same path. The final specs include both. The public index example also checks that the resource URLs in the body still use the numeric group ID, so a 200 with an empty or wrong body does not pass. The private query example uses CGI.escape(target.full_path) and asserts that Dummy.PathPackage comes back:
describe 'GET /api/v4/groups/:id/-/packages/nuget/query with a URL-encoded path' do
let_it_be(:path_package) { create(:nuget_package, project: project, name: 'Dummy.PathPackage') }
let(:url) { "/groups/#{CGI.escape(target.full_path)}/-/packages/nuget/query?q=PathPackage" }
before_all do
subgroup.add_developer(user)
[project, subgroup, group].each do |record|
record.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end
end
it 'resolves the path on a private group and returns packages' do
get api(url), headers: basic_auth_header(user.username, personal_access_token.token)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['data']).to include(
a_hash_including('id' => 'Dummy.PathPackage')
)
end
end
Moaz also asked to keep the existing pipe table in the shared examples, and to change only the cells that needed a new path_status, instead of rewriting the table as an array of arrays. RSpec::Parameterized::TableSyntax already lets a local variable sit in a pipe row, and the file was already doing that. The smaller change kept the convention and dropped a lot of noise from the diff.
A few tighter nits landed as well: a redundant project.add_developer(user) after subgroup.add_developer(user), and the encoding note in nuget.md that I mentioned above, which Zachary Painter was happy with as a technical writer. Invalid ids that look like path traversal stay a 400 when allow_full_path is on, rather than changing status as a side effect of accepting paths.
The MR merged on 30 November 2026.
What I took away
1. When the docs and the validator disagree, check whether the restriction is load-bearing. Here it was not. The lookup already accepted a path, the routes under :id did not clash, and every other group package API already allowed a path. Tightening the docs would have hidden a real inconsistency.
2. A regexp copied from a nearby parameter is not always the right regexp. POSITIVE_INTEGER_REGEX is correct for take. On :id, it made a documented String type impossible.
3. Nested groups still need %2F. Accepting a path is not the same as accepting an extra slash in the route. API::NAMESPACE_OR_PROJECT_REQUIREMENTS is one segment. The docs should say that.
4. A public index example does not cover find_authorized_group!. The interesting case is a private group, an encoded path, and a response body that still makes sense.
5. Prefer a small edit that keeps the file's table style. A rewrite can be easier to write and harder to review. If a local variable already works in a pipe row, use it.
Links
- Issue: gitlab-org/gitlab#641185
- Merge request: gitlab-org/gitlab!272719
- NuGet group-level API docs: docs.gitlab.com/api/packages/nuget/#group-level
Thanks to Viktor Bogdan for the issue, to Moaz Khalifa for the private-path coverage and the smaller table change, and to Zachary Painter for the docs review.
If you've been thinking about contributing to GitLab, the community issues are a great place to start: contributors.gitlab.com.
Top comments (1)
Interesting catch! It's easy to overlook these inconsistencies when different package registries have separate API implementations.
Good to see the fix merged. I wonder if similar validation issues exist in other GitLab endpoints too.