fix: account link proof by auth_time, code in the URL fragment and POST show

- BackendLinkConfirm reads the session's auth_time (bouncer.VerifyAuthTime);
  a token without it, or a refreshed old session, answers 409 stale_session
- POST /_user/api/v1/backend-link/show takes the code in the body; GET
  /backend-link/{code} stays, deprecated; both answer Cache-Control no-store
- My account answers <frontend_url><page_path>#code=<code>; new key
  golem15.user.backend_links.page_path (default /link-admin)
- TestBackendLink now crafts auth_time tokens; TestBackendLinkAuthTimeSmoke
This commit is contained in:
Jakub Zych
2026-10-23 16:38:55 +02:00
parent 72de822a84
commit 32f92591d6
10 changed files with 225 additions and 44 deletions

View File

@@ -31,8 +31,9 @@ func (e *adminEnv) requestCreatedAt(t *testing.T, adminID uint) time.Time {
}
// TestBackendLink (D-03..D-08) extends the link smokes: the fresh sign-in
// rule at the second (an iat equal to the request's created_at confirms,
// one second earlier is stale_session); 1:1 on the frontend side too (a
// rule at the second (an auth_time equal to the request's created_at
// confirms, one second earlier is stale_session, and a token without
// auth_time is stale_session whatever its iat); 1:1 on the frontend side too (a
// linked user cannot confirm another administrator's request); the show
// route exposes the administrator's login and name and the expiry only;
// SetLink records linked_by and fires BackendLinkedEvent and both subject
@@ -54,13 +55,17 @@ func TestBackendLink(t *testing.T) {
sub := strconv.FormatUint(uint64(user.ID), 10)
code := env.startLink(t, token)
created := env.requestCreatedAt(t, admin).Truncate(time.Second)
early := craftToken(t, sub, "early-"+adminStamp(), created.Add(-time.Second), time.Now().Add(time.Hour))
early := craftSignInToken(t, sub, "early-"+adminStamp(), time.Now(), created.Add(-time.Second))
if status, body := env.confirmLink(t, early, code); status != http.StatusConflict || !strings.Contains(body, `"stale_session"`) {
t.Fatalf("iat one second early = %d %s", status, body)
t.Fatalf("auth_time one second early = %d %s", status, body)
}
exact := craftToken(t, sub, "exact-"+adminStamp(), created, time.Now().Add(time.Hour))
noAuthTime := craftToken(t, sub, "legacy-"+adminStamp(), time.Now(), time.Now().Add(time.Hour))
if status, body := env.confirmLink(t, noAuthTime, code); status != http.StatusConflict || !strings.Contains(body, `"stale_session"`) {
t.Fatalf("no auth_time = %d %s", status, body)
}
exact := craftSignInToken(t, sub, "exact-"+adminStamp(), created, created)
if status, body := env.confirmLink(t, exact, code); status != http.StatusOK {
t.Fatalf("iat equal to created_at = %d %s", status, body)
t.Fatalf("auth_time equal to created_at = %d %s", status, body)
}
})