Skip to content

fix(api): a team viewer only reads, enforced in the auth middleware - #45

Merged
qdequele merged 2 commits into
mainfrom
claude/viewer-read-only
Nov 18, 2026
Merged

qdequele merged 2 commits into
mainfrom
claude/viewer-read-only

Conversation

@qdequele

Copy link
Copy Markdown
Owner

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} and POST /job/{id}/pause and /resume had none.

The role is now enforced once, in the auth middleware: a caller whose Lab role is viewer gets 403 forbidden on 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-handler check_write_permission and its 10 calls are removed.

This matters more since meilisearch/lab#147: the Lab now sends member or viewer for OAuth connections, where it sent null.

What does not change

  • API keys (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.
  • Every read stays allowed for a viewer: jobs, status, results, events, WebSockets, diagnostics, analytics.

Also in this PR

  • contracts/vendor/lab/lab-internal.openapi.json is re-vendored from Lab main (the description of the introspection role); it was already drifting on main.
  • The 403 is documented on the 13 write operations in contracts/openapi.json, contracts/openapi.engine.json and the generated TypeScript SDK types.
  • docs/api-reference/authentication.mdx gains a "Team roles" section.
  • CHANGELOG entry under [Unreleased]. No version was changed.

Tests

Three new router tests against a full hosted router with a fake Lab:

  • a viewer (session and OAuth) is refused all 14 write and billed requests;
  • a viewer gets the same status as a member on 12 read routes;
  • API key (both headers), service call, null role, member, admin, owner and an unknown role are never refused for their role.

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

  • Env, config, migrations: none.
  • Order: safe in any order relative to the Lab, which already sends the role.
  • Release: the contracts/openapi.json change (additive 403 responses) becomes official with the next release; the Lab's Contracts sync re-vendors it after that.

🤖 Generated with Claude Code

qdequele and others added 2 commits November 18, 2026 19:04
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>
@qdequele
qdequele merged commit 1fbc852 into main Nov 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant