Visitar URL original
fix(rate-limit): convert a string lastRequest before computing X-Retry-After by aryan1306 · Pull Request #11521 · better-auth/better-auth · GitHub
Skip to content

fix(rate-limit): convert a string lastRequest before computing X-Retry-After - #11521

Merged
bytaesu merged 2 commits into
better-auth:mainfrom
aryan1306:fix/rate-limit-retry-after-string
Oct 15, 2026
Merged

bytaesu merged 2 commits into
better-auth:mainfrom
aryan1306:fix/rate-limit-retry-after-string

Conversation

@aryan1306

@aryan1306 aryan1306 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #11519

node-postgres returns int8 columns as strings. readRow only converted lastRequest when it was a BigInt, so getRetryAfter concatenated the string with the window and a 429 on Postgres sent X-Retry-After: 179090146493486. readRow now converts lastRequest whenever it isn't a number.

Validation:

  • New regression test returns lastRequest as a string from the adapter. It failed before the fix (expected 179090225262699 to be less than or equal to 60).
  • vitest run src/api/rate-limiter/rate-limiter.test.ts (34 passed) and pnpm typecheck.
  • Repro against PostgreSQL 17: https://github.com/aryan1306/better-auth-11519-repro. It returns X-Retry-After: 60 with this change.

No breaking changes.


Summary by cubic

Fixes the X-Retry-After header on database rate limiting when the driver returns lastRequest as a string, as node-postgres does for int8 columns. It had concatenated the string with the window and returned a huge number instead of the seconds left; readRow now normalizes lastRequest to a number for any row it returns. Adds a regression test covering the string case from #11519.

Written for commit baf97dd. Summary will update on new commits.

View guided diff

@aryan1306
aryan1306 requested a review from a team as a code owner October 2, 2026 05:59
@aryan1306
aryan1306 requested review from Bekacru and removed request for a team October 2, 2026 05:59
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown

@aryan1306 is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

@better-release better-release Bot added core Core infra, API routes, session, cookies, client SDK security 2FA, rate limiting, captcha, HIBP labels Oct 2, 2026
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no outstanding finding or new blocking issue was identified.

Summary

The PR converts database-backed rate-limit timestamps to numbers so string values produce a correct X-Retry-After header. The revised regression test checks the exact remaining seconds after a controlled clock advance.

Reviews (3) · Last reviewed commit: "refactor(rate-limit): simplify timestamp..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

…y-After

node-postgres returns int8 columns as strings, so readRow left lastRequest as a string and getRetryAfter concatenated it with the window instead of adding.

Closes better-auth#11519
@aryan1306
aryan1306 force-pushed the fix/rate-limit-retry-after-string branch from 688cf53 to cb4ef08 Compare October 4, 2026 17:50
@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@better-auth/api-key

npm i https://pkg.pr.new/@better-auth/api-key@11521

better-auth

npm i https://pkg.pr.new/better-auth@11521

@better-auth/cimd

npm i https://pkg.pr.new/@better-auth/cimd@11521

auth

npm i https://pkg.pr.new/auth@11521

@better-auth/core

npm i https://pkg.pr.new/@better-auth/core@11521

@better-auth/drizzle-adapter

npm i https://pkg.pr.new/@better-auth/drizzle-adapter@11521

@better-auth/electron

npm i https://pkg.pr.new/@better-auth/electron@11521

@better-auth/expo

npm i https://pkg.pr.new/@better-auth/expo@11521

@better-auth/i18n

npm i https://pkg.pr.new/@better-auth/i18n@11521

@better-auth/kysely-adapter

npm i https://pkg.pr.new/@better-auth/kysely-adapter@11521

@better-auth/mcp

npm i https://pkg.pr.new/@better-auth/mcp@11521

@better-auth/memory-adapter

npm i https://pkg.pr.new/@better-auth/memory-adapter@11521

@better-auth/mongo-adapter

npm i https://pkg.pr.new/@better-auth/mongo-adapter@11521

@better-auth/oauth-provider

npm i https://pkg.pr.new/@better-auth/oauth-provider@11521

@better-auth/passkey

npm i https://pkg.pr.new/@better-auth/passkey@11521

@better-auth/prisma-adapter

npm i https://pkg.pr.new/@better-auth/prisma-adapter@11521

@better-auth/redis-storage

npm i https://pkg.pr.new/@better-auth/redis-storage@11521

@better-auth/scim

npm i https://pkg.pr.new/@better-auth/scim@11521

@better-auth/sso

npm i https://pkg.pr.new/@better-auth/sso@11521

@better-auth/stripe

npm i https://pkg.pr.new/@better-auth/stripe@11521

@better-auth/telemetry

npm i https://pkg.pr.new/@better-auth/telemetry@11521

@better-auth/test-utils

npm i https://pkg.pr.new/@better-auth/test-utils@11521

commit: baf97dd

@bytaesu

bytaesu commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

baf97dd

if (data && typeof data.lastRequest !== "number") -> if (data)

I slightly simplified the condition check.

@bytaesu bytaesu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks @aryan1306 😁

@bytaesu
bytaesu enabled auto-merge October 15, 2026 14:52
@bytaesu
bytaesu added this pull request to the merge queue Oct 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 15, 2026
@bytaesu
bytaesu added this pull request to the merge queue Oct 15, 2026
Merged via the queue into better-auth:main with commit 37a75c9 Oct 15, 2026
38 checks passed
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Oct 22, 2026
## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `@better-auth/cimd` | 1.7.10 | 1.7.11 | patch |
| `@better-auth/mcp` | 1.7.10 | 1.7.11 | patch |
| `@better-auth/oauth-provider` | 1.7.10 | 1.7.11 | patch |
| `@better-auth/passkey` | 1.7.10 | 1.7.11 | patch |
| `@better-auth/sso` | 1.7.10 | 1.7.11 | patch |
| `better-auth` | 1.7.10 | 1.7.11 | patch |
| `seroval` | 1.6.10 | 1.6.11 | patch |

## Release Notes

<details>
<summary><b>@<!---->better-auth/cimd</b> (1.7.10 → 1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

<details>
<summary><b>@<!---->better-auth/mcp</b> (1.7.10 → 1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

<details>
<summary><b>@<!---->better-auth/oauth-provider</b> (1.7.10 →
1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

<details>
<summary><b>@<!---->better-auth/passkey</b> (1.7.10 → 1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

<details>
<summary><b>@<!---->better-auth/sso</b> (1.7.10 → 1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

<details>
<summary><b>better-auth</b> (1.7.10 → 1.7.11)</summary>

## `better-auth`

### Bug Fixes

- Fixed repeated PostgreSQL migration diffs for `int8` columns.
([#10719](better-auth/better-auth#10719))
- Fixed database-backed rate limiting returning an excessively large
`X-Retry-After` value.
([#11521](better-auth/better-auth#11521))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/better-auth/CHANGELOG.md)

## `@better-auth/core`

### Bug Fixes

- Fixed plugin `init` returns with `options: undefined` failing type
checks under `exactOptionalPropertyTypes`.
([#11907](better-auth/better-auth#11907))
- Fixed ID token signature and claim validation for Twitch and Paybin
sign-in. Custom Paybin issuers must publish RS256 signing keys at
`<issuer>/.well-known/jwks.json`.
([#11884](better-auth/better-auth#11884))
- Reduced installation size while preserving OpenTelemetry
instrumentation attributes.
([#11623](better-auth/better-auth#11623))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/core/CHANGELOG.md)

## `@better-auth/oauth-provider`

### Bug Fixes

- Fixed OpenAPI schemas for `/oauth2/consent` and `/oauth2/continue` to
match their redirect responses.
([#10881](better-auth/better-auth#10881))
- Fixed CIMD metadata refreshes overwriting concurrent administrator
changes to discovered clients.
([#11830](better-auth/better-auth#11830))

For detailed changes, see
[`CHANGELOG`](https://github.com/better-auth/better-auth/blob/e2365403dfa98c004ac5dd31f12769525017a67d/packages/oauth-provider/CHANGELOG.md)

## `@better-auth/expo`

### Bug Fixes

- Fixed Expo social account linking with ID tokens when a session cookie
is present. ([#10207](https://github.com/better-au

…[full
notes](https://github.com/better-auth/better-auth/releases/tag/v1.7.11)

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@better-release better-release Bot added the locked Locked conversations after being closed for 7 days label Oct 23, 2026
@better-release better-release Bot locked as resolved and limited conversation to collaborators Oct 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

core Core infra, API routes, session, cookies, client SDK locked Locked conversations after being closed for 7 days security 2FA, rate limiting, captcha, HIBP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database rate limiting returns a huge X-Retry-After on Postgres because pg returns lastRequest as a string

2 participants