Amazon Ergo 1.0 · 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
3
Comments matching a bug
2
Comments not matching
1
Cost of this PR
$1.563

Published comments (3)

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

Device limit is bypassed because the cache key is set before the store call — When `CreateOrUpdateDevice` fails with `ErrDeviceLimitReached`, `localCache.SetDefault` has already cached `key`, so retries and parallel requests pass `tagDeviceUI` and authenticate. Call `localCache.SetDefault` only after a successful store, or delete `key` on failure.

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

Concurrent device creations can exceed the configured device limit — Two concurrent requests can both pass the non-atomic `CountDevices` check and insert, exceeding `s.deviceLimit`. Enforce the limit atomically with a serializable transaction, locking, or a counter row if it must be a hard bound.

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

Anonymous auth blocks on device tagging when device limits are disabled — With `device_limit=0`, synchronously awaiting `TagDevice` adds a DB write to every uncached anonymous authentication without rejecting anything. Keep the previous asynchronous path when `AnonymousDeviceLimit` is zero, and block only when enforcement is needed.

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.