Harden auth: same-origin check, live admin flag, 90-day refresh
Test and deploy / test (push) Failing after 28s
Test and deploy / deploy (push) Has been skipped

- Refuse non-GET requests whose Origin (or Sec-Fetch-Site) is not the
  apex or www. SameSite=Lax lets sibling subdomains such as radar. and
  git. send the auth cookies. The WebSocket check shares the helper and
  no longer accepts localhost in production.
- Take the admin flag from the user row the token check already loads,
  so a demotion applies on the next request, not on token expiry.
- Cut the refresh token lifetime from 365 to 90 days; refreshes renew it.
- Docs: fix the stale revocation notes in backend/README.md and the
  Cloudflare Access comment in routes.caddy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:12:01 +00:00
co-authored by Claude Opus 5.5
parent 3139e8e239
commit d383774e97
10 changed files with 140 additions and 34 deletions
+4 -9
View File
@@ -40,8 +40,8 @@ func (store *Store) AuthMiddleware(ctx *gin.Context) {
ctx.Next()
}
// AdminMiddleware must follow AuthMiddleware. Admin comes from the token, so
// a revoked flag applies once the access token expires.
// AdminMiddleware must follow AuthMiddleware, whose claims carry the row's
// admin flag.
func (store *Store) AdminMiddleware(ctx *gin.Context) {
claims, exists := ctx.Get("userClaims")
if !exists {
@@ -69,13 +69,8 @@ func (store *Store) AdminMiddleware(ctx *gin.Context) {
// gate and the jobs container. It falls back to the refresh token and may
// mint new cookies, so a returning admin needn't log in again.
func (store *Store) ValidateAdmin(ctx *gin.Context) {
store.validateSession(ctx, func(user *models.User, claims *jwt.MapClaims) bool {
// The refresh path has no admin claim, so it reads the row.
if claims == nil {
return user.Admin
}
admin, ok := (*claims)["admin"].(bool)
return ok && admin
store.validateSession(ctx, func(user *models.User, _ *jwt.MapClaims) bool {
return user.Admin
})
}