GLM-5.3 Flash · Balanced

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

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

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

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

Published comments (5)

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

Cached device key persists after tagging failure, bypassing device limit — An over-limit device gets cached anyway, so retries within the ~29-minute cache TTL return nil and `Anonymous.Authenticate` grants access without ever seeing `ErrDeviceLimitReached`. Move `localCache.SetDefault` to after `CreateOrUpdateDevice` succeeds, or invalidate the key on failure.

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

Device limit check is not atomic, allowing the limit to be exceeded — Concurrent first-tag requests, including across instances in HA where the dedupe cache is per-instance, can all see `CountDevices` below the limit and all upsert. Run the count and insert in one transaction with a lock, or bound the row count inside the upsert itself.

highbugpkg/services/anonymous/anonimpl/anonstore/database.go:72-97

Stale device rows (30-61 days old) can never be refreshed once limit is reached — A device last seen 30–61 days ago keeps a row that `CountDevices` no longer counts but `updateDevice` still refuses to refresh, locking it out until the count drops. Drop the `updated_at BETWEEN` condition on the `device_id` match, or delete and reinsert the expired row.

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

Device-limit enforcement bypassed when X-Grafana-Device-Id header is omitted — Any client that omits the header — scripts, bots, curl — skips `TagDevice` entirely and is never counted or blocked by `ErrDeviceLimitReached`, defeating the cap. Derive the device identity server-side, e.g. from client IP and user agent, instead of trusting the client-controlled header.

mediumperformancepkg/services/anonymous/anonimpl/anonstore/database.go:110-117

Per-device full COUNT in auth path scales O(N) per fresh device — Every uncached device tag runs `CountDevices` over the full 30-day active set in the auth path, so a burst of N fresh devices costs O(N²) aggregate work and adds latency under load. Track the count incrementally, or enforce the limit inside the upsert statement itself.

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.