Skip to content

[Bug]: core throttle's response phase overwrites RateLimit fields on an extension's 429 #701

Closed

Description

@jimhoyd

Runtime revision and environment

origin/main at bedd85f plus the per-credential quota branch for #572 (feat/auth-credential-quota). Found by reading packages/core/src/policies/throttle.ts and packages/core/src/runtime.ts; not reproduced end to end.

Minimal reproduction

A route that declares both core throttle and the auth bearer quota:

/api/items:
  function: functions/items.mjs
  auth: {bearer: {scopes: [items.read], quota: {requests: 2, window: 60}}}
  policies:
    throttle: {quota: 60, window: 60}

On the third request with one key, auth's authorize() returns a 429 with RateLimit-Policy: "credential";q=2;w=60 and RateLimit: "credential";r=0;t=N. The runtime passes that result through finishPolicies, and throttle's onResponse calls withHeaders, which removes every existing ratelimit/ratelimit-policy field and adds its own "default" policy. The client sees throttle's budget (with remaining capacity) on a refusal caused by the credential budget. Retry-After survives.

Relevant output

withHeaders in packages/core/src/policies/throttle.ts filters by header name before appending. The IETF RateLimit fields are structured-field lists that can carry several named policies, so throttle could append its member to an existing field instead of replacing it.

The auth docs (packages/auth/README.md "Per-credential quota", docs/policies/throttle.md) record this as a current limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions