Repository navigation
cli: reject invalid ratelimit modes and non-positive limits - #165
Merged
Merged
Conversation
`ratelimit set` stored whatever string `--mode` was given and accepted zero or negative limits, so a typo'd mode reached the server and a non-positive limit could disable the layer or break the arithmetic that reads it. Both are usage errors now, raised before the round trip: --mode must be one of off, detect or block (`redact` belongs to the DLP layer), and every limit that is passed must be positive. Fixes solongate#135 Signed-off-by: Turgay Nalbant <182372382+tnalbant@users.noreply.github.com>
codeyevsky
approved these changes
Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
ratelimit setvalidated nothing:--modewas cast straight toclient.LayerMode, so--mode nonsensewas accepted and stored. The failure surfaced later, wherever the stored mode was interpreted.--minute,--hourand--dayaccepted zero and negative values, which downstream throttling does not expect.Both are usage errors now, and they are raised before the
GetSecurityLayersround trip, so a typo never reaches the server.--modeacceptsoff,detectandblock.redactis deliberately not accepted: it belongs to the DLP layer, and the existing usage line already says--mode off|detect|block.Fixes #135
How I checked it
New tests, run against the unpatched code:
With the change:
The tests drive the real command handler with
client.New(), and the rejection tests assert that the stored layers are unchanged afterwards, so a future refactor that moves validation after the write would fail them.go test ./...inpackages/clistill reportsTestProtectAddandTestProtectListinpackages/cli/policyon this macOS host: the immutable-flag tests fail inTempDircleanup withoperation not permitted. That package is untouched by this diff, and the failure reproduces onmain.