GLM-5.3 Flash · Heavy

anonymous-add-configurable-device-limit-grafana-codex

Grafana · Go · M · 100–299 lines · 6 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
2 of 5
Comments published
7
Comments matching a bug
2
Comments not matching
5
Cost of this PR
$0.210

Published comments (7)

highsecuritypkg/services/anonymous/anonimpl/client.go:44-47

Device-limit gate bypassed when X-Grafana-Device-Id header is omitted — Since `TagDevice` returns early when the client-controlled `X-Grafana-Device-Id` header is absent, simply omitting it bypasses the gate and the limit never applies to the unbounded traffic it is meant to cap. Enforce a server-side fallback identity (e.g. from IP/User-Agent) or reject requests missing the header.

highbugpkg/services/anonymous/anonimpl/impl.go:144-148

Device cached before DB write, so limit rejection is bypassed on retry — Because `SetDefault` caches the device before `CreateOrUpdateDevice` runs, a rejected request succeeds on retry via a cache hit without touching the database — rejection silently becomes access. Cache the device only after `CreateOrUpdateDevice` succeeds, or evict the key on error. **Also found in:** - `pkg/services/anonymous/anonimpl/client.go:44-47`

highbugpkg/services/anonymous/anonimpl/anonstore/database.go:109-118

Device limit check has a check-then-act race allowing limit bypass — `CountDevices` and the insert run in separate sessions without locking, so concurrent requests with distinct device IDs all see the count below the limit and all insert, letting one burst push far past the cap. Enforce it atomically, e.g. a locking read in one transaction or a conditional insert.

mediumbugpackages/grafana-data/src/types/config.ts:200

anonymousDeviceLimit typed as number | undefined but backend always sends a number (0 = no limit) — `undefined` never arrives: the Go DTO field `AnonymousDeviceLimit` always serializes a number, `0` when no limit is set, so consumers checking for `undefined` or treating any number as a real limit will misbehave. Type the field as `number` and document that `0` means unlimited.

mediumbugpkg/services/anonymous/anonimpl/client.go:44-50

Panic in TagDevice now escapes Authenticate after removing defer/recover — Panics raised inside `TagDevice`, for example while parsing request headers, now escape `Authenticate` and fail the request with a 500 instead of being swallowed as before. Wrap the synchronous call in a defer/recover that logs and treats the panic as a tagging failure.

mediumsecuritypkg/services/anonymous/anonimpl/client.go:44-50

Authenticate leaks internal ErrDeviceLimitReached sentinel in HTTP response — Returning the raw `ErrDeviceLimitReached` sentinel makes it the response message for unauthenticated requests, disclosing to anonymous users that a device limit exists and is exhausted. Log the real cause server-side and return a neutral authentication failure instead.

mediumsecuritypkg/api/dtos/frontend_settings.go:193-197

AnonymousDeviceLimit leaks internal capacity config via unauthenticated /api/frontend/settings — The endpoint is served without authentication, so this publishes the internal capacity setting to any visitor, and no frontend consumer of the value appears in this PR. Omit it from the payload or include it only when anonymous access is enabled.

Gold bugs found (2)

highThe device limit check counts devices and then inserts in separate non-atomic steps, so concurrent requests from new devices can all pass the check and exceed the configured limit.
hightagDeviceUI caches the device key before CreateOrUpdateDevice; when the store returns ErrDeviceLimitReached the entry stays, so the next request from the same device skips the limit check and authenticates for up to 29 minutes.

Gold bugs missed (3)

highThe new auth.anonymous device_limit setting has no entry in conf/defaults.ini, so the GF_AUTH_ANONYMOUS_DEVICE_LIMIT environment override is ignored and the limit stays 0.
mediumupdateDevice prepends the query to the captured args inside the retried DB callback, so a SQLite lock retry runs Exec with the query duplicated in the arguments and the update fails.
highClaims a client disconnect cancels the context, TagDevice fails with context.Canceled, and Authenticate still succeeds without counting the device, bypassing the limit.