Tokens can write but never read: no token auth on the read API #156
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
qwc-open/asiakirjat#156
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Noticed while mapping token scoping for #155. Not urgent — filing it so it is written down.
What is the case today
Bearer tokens are wired into exactly three routes, all of them writes:
POST /api/projectsPOST /api/project/{slug}/uploadPOST /api/uploadEverything else, including the read API, goes through
withSession, which reads the session cookie and nothing else (SessionManager.GetUserFromRequest). So these return the signed-out view to a token holder:GET /api/projectsGET /api/project/{slug}/versionsGET /api/searchA CI job can push a version and then cannot ask which versions exist. Scripts that want to know "is v1.2.0 already uploaded" have to guess from the upload's response, or carry a session cookie, which is not a thing tokens were meant to need.
Why it is worth doing deliberately rather than quickly
Reading is where a token's scope actually gets interesting, and the answers are not obvious:
GET /api/projects— one project, or an error? One project seems right: the token says which project it is for.GET /api/searchacross projects the robot cannot view would be an information leak, so it has to run throughFilterAccessiblelike the web search does.publicprojects: today the read API is cookie-only, so a public project's version list is already readable by a signed-out visitor. Adding token auth must not change that either way by accident.The shape that fits what #155 settled is a middleware that tries the session first and the token second, putting the resolved user in the context the same way, so the handlers stay unaware — with the token's project scope applied to the listing, not just to writes.
Also worth deciding at the same time
Whether reading needs its own scope value.
api_tokens.scopesnow carriesuploadandcreate(#155); a read-only token would be a genuinely useful thing to hand a dashboard, and it only makes sense to add the value when something reads it.Assisted-by: Claude Opus 5