Amazon Ergo 1.0 · 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
6
Comments matching a bug
2
Comments not matching
4
Cost of this PR
$3.018

Published comments (6)

highbugpkg/services/anonymous/anonimpl/anonstore/database.go:80-81

updateDevice anchors its activity window to caller-controlled UpdatedAt — A stale caller-supplied `device.UpdatedAt` can make an active device miss the update window, producing `ErrDeviceLimitReached` and an auth failure in `client.go`. Anchor both the update and limit-count windows to one `time.Now().UTC()` value, passing `from`/`to` into `updateDevice`.

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

Device-limit rejection is bypassed while the device stays cached — `tagDeviceUI` caches the device ID before `CreateOrUpdateDevice`, so a rejected device can use the cache fast path and gain anonymous access for the remaining TTL. Mark the device as tagged only after a successful store, or call `a.localCache.Delete(deviceID)` when the store returns an error.

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

Device-limit check races with concurrent inserts — Concurrent inserts can all observe the same below-limit `CountDevices` result and then insert, allowing active devices to exceed `s.deviceLimit`. Enforce the check and write atomically with a suitably locked transaction or a database-side mechanism.

mediumbugpkg/services/anonymous/anonimpl/anonstore/database.go:95-97

No-op device updates incorrectly return ErrDeviceLimitReached — On MySQL, `RowsAffected() == 0` also occurs when a row matches but no values change, so a legitimate no-op update is misreported as `ErrDeviceLimitReached`. Detect whether the device row matched independently of changed values, such as with found-rows semantics, and reserve `ErrDeviceLimitReached` for the actual limit.

mediumbugpkg/services/anonymous/anonimpl/anonstore/database_test.go:65-69

Device limit test does not verify updates to existing devices — Changing `DeviceID` to `keep` exercises only new-device rejection, so broken updates could lock out known devices while this test still passes. At the limit, update the original `DeviceID` and assert `NoError`, persisted fields, and one stored device; separately assert that a new `DeviceID` returns `ErrDeviceLimitReached`.

mediumbugpkg/services/anonymous/anonimpl/impl_test.go:116-117

Service tests do not cover device-limit config wiring — These tests use `setting.NewCfg()` with a zero limit, so failing to pass `cfg.AnonymousDeviceLimit` into `ProvideAnonDBStore` would silently disable the feature. Add a service-level case with `cfg.AnonymousDeviceLimit = 1`, tag two distinct devices via `TagDevice`, and assert the second returns `ErrDeviceLimitReached`.

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.