Skip to content

integration-proxy: a refresh token is destroyed after ten idle minutes #42

Closed

Description

@michielbdejong

Summary

A user's OAuth refresh token is deleted ten minutes after they stop syncing. Nothing about plugins or clients is involved — it follows from where the credential is stored.

Split out of #40 (item A) because it stands on its own: it is worth fixing whether or not the signature-auth work there happens.

The mechanism

Verified in integration-proxy/src/{proxy,security}.rs:

  1. StoredCredential (proxy.rs:229-246) holds the real access_token, refresh_token and expires_at.
  2. It is sealed into the connection code's envelope and nowhere else. security.rs:100 creates exactly four tables — used_challenges, oauth_states, connection_codes, connection_handoffs. There is no persistent per-connection record.
  3. Each proxied request take_connection_codes (DELETE … RETURNING, security.rs:255), uses the credential, re-seals it into a fresh successor and stores that (proxy.rs:488-502).
  4. Successor rows are inserted at NOW() + INTERVAL '10 minutes' (security.rs:250) and swept on every write (security.rs:245).

So the TTL resets on each rotation — an actively syncing client never expires. But once a client goes idle past ten minutes, the row is swept, and that row was the only copy of the sealed refresh token. Recovery is a full re-OAuth.

Why it's worth fixing on its own

  • A refresh token is a long-lived grant the user consented to. Ending it because nobody synced over lunch is a surprising place for it to go, and the user is given no signal that it happened until the next sync fails.
  • The same applies to any break in the chain, not just idleness. A dropped response spends the code client-side and rotates it server-side; the reply carrying the successor is the only copy. The source already acknowledges this shape for the handoff case — "Consume before dispatch: a lost response may have spent the handoff code" — but for connection codes the cost is the grant itself, not a retry.
  • It couples grant durability to a transport detail. Single-use rotation is a reasonable property for a bearer token. It is not a reasonable lifecycle for an OAuth grant, and right now they are the same object.

Proposed

A persistent connections table: stable connection_id, the sealed StoredCredential, the owning user_id (DID), platform, created_at, last_used_at. Not deleted on use.

Rotating codes keep working unchanged — a connections row simply becomes the source of truth they are minted from, instead of being the only place the credential lives. Additive, no client change required.

Open questions

  • Idle lifecycle for a connections row. Something long (weeks) with last_used_at, so dead grants are still cleaned up, rather than no expiry at all.
  • Whether existing in-flight connection codes need a migration or can simply age out.
  • Revocation surface: is_revoked(tenant_id, user_id) exists (proxy.rs:113-117); a persistent connection makes per-connection revocation expressible too.

Activity

  1. added a commit that references this issue on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions