[PR #6238] [management] reject negative usage_limit on setup key creation #25184

Open
opened 2026-08-05 06:09:39 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/6238

State: open
Merged: No


Describe your changes

The POST /api/setup-keys endpoint accepted negative values for usage_limit. Semantically only 0 (unlimited) or a positive integer (a cap) is meaningful — a negative cap would either produce a key flagged as immediately overused by IsOverUsed(), or silently behave like unlimited depending on the downstream code path.

This PR:

  • Adds a handler-side guard in management/server/http/handlers/setup_keys/setupkeys_handler.go that returns 422 Unprocessable Entity with usage_limit can not be negative, mirroring the existing expires_in check.
  • Documents the constraint in the OpenAPI schema (minimum: 0 on CreateSetupKeyRequest.usage_limit).
  • Adds a handler test case (Create Setup Key With Negative Usage Limit) covering the rejection path.

N/A — found while exploring the API.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

This is a server-side input validation fix that brings the API in line with its documented semantics (the OpenAPI description already says 0 means unlimited, implying non-negative). The OpenAPI schema is updated in-repo (minimum: 0), so the public API contract is self-documenting. No user-facing docs in netbirdio/docs describe the prior behavior, so there is nothing to update there.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

N/A

**Original Pull Request:** https://github.com/netbirdio/netbird/pull/6238 **State:** open **Merged:** No --- ## Describe your changes The `POST /api/setup-keys` endpoint accepted negative values for `usage_limit`. Semantically only `0` (unlimited) or a positive integer (a cap) is meaningful — a negative cap would either produce a key flagged as immediately overused by `IsOverUsed()`, or silently behave like unlimited depending on the downstream code path. This PR: - Adds a handler-side guard in `management/server/http/handlers/setup_keys/setupkeys_handler.go` that returns `422 Unprocessable Entity` with `usage_limit can not be negative`, mirroring the existing `expires_in` check. - Documents the constraint in the OpenAPI schema (`minimum: 0` on `CreateSetupKeyRequest.usage_limit`). - Adds a handler test case (`Create Setup Key With Negative Usage Limit`) covering the rejection path. ## Issue ticket number and link N/A — found while exploring the API. ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [x] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) This is a server-side input validation fix that brings the API in line with its documented semantics (the OpenAPI description already says `0` means unlimited, implying non-negative). The OpenAPI schema is updated in-repo (`minimum: 0`), so the public API contract is self-documenting. No user-facing docs in `netbirdio/docs` describe the prior behavior, so there is nothing to update there. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: N/A
saavagebueno added the pull-request label 2026-08-05 06:09:39 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#25184