Skip to content

Commit 870b6f4

Browse files
authored
Merge pull request #20322 from mozilla/fxa-13356
fix(auth): offset TOTP delta histogram to avoid negative StatsD values
2 parents 769e5a8 + 4de79e4 commit 870b6f4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages/fxa-auth-server/lib/routes/utils

packages/fxa-auth-server/lib/routes/utils/otp.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ export class OtpUtils {
5656
const valid = otpAuthenticator.check(code, secret);
5757
const delta = otpAuthenticator.checkDelta(code, secret);
5858

59-
if (type && delta) {
60-
this.statsd.histogram(`${type}.totp.delta_histogram`, delta);
59+
if (type && delta !== undefined && delta !== null) {
60+
// Offset delta by window so the value is always non-negative.
61+
// With window=1: delta -1 → 0, delta 0 → 1, delta 1 → 2.
62+
// Telegraf's statsd plugin only accepts non-negative histogram values.
63+
const window = otpOptions?.window ?? 1;
64+
this.statsd.histogram(`${type}.totp.delta_histogram`, delta + window);
6165
}
6266
// Return delta for logging
6367
return { valid, delta };

0 commit comments

Comments
 (0)