Construct TokenAuthenticator once on Handler (H-13) #114

Merged
qwc merged 1 commit from refactor/token-authenticator-deps into main 2026-05-18 23:09:25 +02:00
Owner

Summary

Workstream item #19. Audit finding H-13.

handleAPIUploadWithSlug and handleAPICreateProject each called auth.NewTokenAuthenticator(h.tokens, h.users) per request — cheap, but a sign that token auth wasn't a first-class handler member. Any new token-auth call site would have re-constructed it the same way; adding the second auth path the audit flagged (e.g. webhook signing) would have required yet another bespoke construction.

Changes

  • New Handler.tokenAuth *auth.TokenAuthenticator field, constructed once in handler.New from the existing Tokens + Users Deps.
  • Two call sites in api.go switched from auth.NewTokenAuthenticator(h.tokens, h.users).X to h.tokenAuth.X.
  • No new Deps field — matches the existing pattern for projectService and checker which are also built in-constructor from existing Deps.

Net diff: 5 / -5 lines.

Test plan

  • go test ./... passes; all existing API token tests continue to work since behavior is unchanged

🤖 Generated with Claude Code

## Summary Workstream item #19. Audit finding **H-13**. `handleAPIUploadWithSlug` and `handleAPICreateProject` each called `auth.NewTokenAuthenticator(h.tokens, h.users)` per request — cheap, but a sign that token auth wasn't a first-class handler member. Any new token-auth call site would have re-constructed it the same way; adding the second auth path the audit flagged (e.g. webhook signing) would have required yet another bespoke construction. ## Changes - New `Handler.tokenAuth *auth.TokenAuthenticator` field, constructed once in `handler.New` from the existing `Tokens` + `Users` Deps. - Two call sites in `api.go` switched from `auth.NewTokenAuthenticator(h.tokens, h.users).X` to `h.tokenAuth.X`. - No new Deps field — matches the existing pattern for `projectService` and `checker` which are also built in-constructor from existing Deps. Net diff: 5 / -5 lines. ## Test plan - [x] `go test ./...` passes; all existing API token tests continue to work since behavior is unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Construct TokenAuthenticator once on Handler (H-13)
All checks were successful
CI / test (pull_request) Successful in 1m25s
CI / build (pull_request) Successful in 55s
CI / docker (pull_request) Has been skipped
269b5e4338
Audit finding H-13. handleAPIUploadWithSlug and handleAPICreateProject
each called auth.NewTokenAuthenticator(h.tokens, h.users) per request
— cheap but a sign that token auth wasn't a first-class member of the
handler. Any new token-auth call site would have re-constructed it the
same way, and the second auth path the audit flagged would need yet
another bespoke construction.

Construct once in handler.New, store on h.tokenAuth, use h.tokenAuth.X
at the two call sites. Matches the established pattern for projectService
and checker (also wired in handler.New from existing Deps fields).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
qwc merged commit 7a4c4b2952 into main 2026-05-18 23:09:25 +02:00
qwc deleted branch refactor/token-authenticator-deps 2026-05-18 23:09:25 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
qwc-open/asiakirjat!114
No description provided.