Repository navigation
fix(api): a team viewer only reads, enforced in the auth middleware - #45
Merged
Merged
Conversation
The Lab's introspection now documents `role` for every credential: a
session's membership role, an OAuth connection's capped at member (a
viewer's stays viewer), null for an API key; a viewer only reads. Also
picks up the 403 the Lab returns to non-Scrapix callers of
GET /internal/accounts/{id}/meilisearch. `contracts/check-drift.sh --fix`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A hosted viewer (session or OAuth connection, the Lab's introspection
`role: "viewer"`) was refused the product calls by a check repeated in
each handler, but not DELETE /job/{id} (cancel, purge) nor
POST /job/{id}/pause and /resume: a viewer could cancel or pause the
team's jobs. The role is now checked once, in validate_api_key_or_session,
for every credential: a viewer gets 403 `forbidden` on any method that is
not GET/HEAD/OPTIONS, before the handler runs, so every guarded route,
present or future, is covered. The per-handler check_write_permission is
gone. No role (API keys, service calls, standalone), member, admin, owner
and unknown roles are unchanged.
The 403 is documented on the 13 write operations of both specs (and the
TypeScript SDK's generated types); a test keeps every non-GET operation
documenting it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On the hosted engine, a team viewer could cancel, purge, pause and resume the team's jobs. The product calls (
/scrape,/crawl*,/map,/search,/extract,/parse) already refused a viewer through a check in each handler;DELETE /job/{id}andPOST /job/{id}/pauseand/resumehad none.The role is now enforced once, in the auth middleware: a caller whose Lab role is
viewergets403 forbiddenon any method that is not a read (GET,HEAD,OPTIONS), before the handler runs. A route added to a guarded router is covered with no check of its own. The per-handlercheck_write_permissionand its 10 calls are removed.This matters more since meilisearch/lab#147: the Lab now sends
memberorviewerfor OAuth connections, where it sentnull.What does not change
X-API-Key), Lab service calls and the standalone engine carry no role and behave as before.member,admin,owner, and any role string the engine does not know, are never refused for their role.Also in this PR
contracts/vendor/lab/lab-internal.openapi.jsonis re-vendored from Labmain(the description of the introspectionrole); it was already drifting onmain.contracts/openapi.json,contracts/openapi.engine.jsonand the generated TypeScript SDK types.docs/api-reference/authentication.mdxgains a "Team roles" section.[Unreleased]. No version was changed.Tests
Three new router tests against a full hosted router with a fake Lab:
Before the fix the first one failed: the viewer got 200 on cancel and pause.
Run locally with CI's
RUSTFLAGS=-Dwarnings:cargo fmt --check,cargo clippy --all -- -D warnings,cargo test --workspace(1653 passed, 0 failed, 9 ignored),scripts/prepare-release.sh --check,sdks/generate.sh --check,contracts/check-drift.sh.Not run: the Postgres and ClickHouse tests (they skip without their database URLs) and the SDK test suites (only a generated type file changed).
Deploy notes
contracts/openapi.jsonchange (additive 403 responses) becomes official with the next release; the Lab's Contracts sync re-vendors it after that.🤖 Generated with Claude Code