Skip to content

server: expire authorization codes after 5 minutes - #206

Open
yonaadug wants to merge 1 commit into
tailscale:mainfrom
yonaadug:fix/auth-code-expiry
Open

yonaadug wants to merge 1 commit into
tailscale:mainfrom
yonaadug:fix/auth-code-expiry

Conversation

@yonaadug

@yonaadug yonaadug commented Nov 2, 2026 •

Copy link
Copy Markdown

Fixes #214

serveAuthorize never set ValidTill on the code's AuthRequest, and the token endpoint never checked it. Codes only disappeared when the 10-minute cleanup ran, which treated the zero ValidTill as expired and deleted every pending code, including ones issued seconds earlier.

Set ValidTill to now + AuthCodeDuration (5 minutes) when the code is created, and reject expired codes at /token with invalid_grant.

Testing

  • Added TestAuthorizationCodeExpiration, which checks that a fresh code is exchanged successfully, an expired code is rejected with code expired, and the code is deleted after use either way.
  • Extended TestServeAuthorize to check that new codes get a ValidTill within AuthCodeDuration.

@yonaadug

yonaadug commented Nov 2, 2026

Copy link
Copy Markdown
Author

Hi. First PR for this project. I currently use this idp at home so I wanted to help develop it

@yonaadug
yonaadug force-pushed the fix/auth-code-expiry branch from adeddbe to 644a19f Compare November 2, 2026 21:32
@jentfoo

jentfoo commented Nov 10, 2026

Copy link
Copy Markdown
Member

@yonaadug Thank you for the contribution!

Can you open an Issue to document this gap (and in the PR description and commit message mention "Fixes #XXX") as well as remove claude from the co-author in the commit.

@yonaadug yonaadug changed the title Fix/auth code expiry Fixes #214 Nov 13, 2026
serveAuthorize never set ValidTill on the code's AuthRequest, and the
token endpoint never checked it. Codes only disappeared when the
10-minute cleanup ran, which treated the zero ValidTill as expired and
deleted every pending code, including ones issued seconds earlier.

Set ValidTill to now + AuthCodeDuration (5 minutes) when the code is
created, and reject expired codes at /token with invalid_grant. Add
tests for both: TestServeAuthorize checks that new codes expire within
5 minutes, and TestAuthorizationCodeExpiration checks that /token
accepts a fresh code and rejects an expired one.

Fixes tailscale#214

Signed-off-by: kebedey16 <kebedey16@gmail.com>
@yonaadug
yonaadug force-pushed the fix/auth-code-expiry branch from 644a19f to f676b28 Compare November 13, 2026 07:15
@yonaadug yonaadug changed the title Fixes #214 Fix/auth code expiry Nov 13, 2026
@yonaadug

Copy link
Copy Markdown
Author

Thanks for reviewing @jentfoo !
I've made the changes you requested

@yonaadug yonaadug changed the title Fix/auth code expiry server: expire authorization codes after 5 minutes Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization codes have no expiry and live 0–10 minutes depending on the cleanup timer

2 participants