lab: gate /lab behind API_TOKEN (basic auth + x-api-token) - #1618
Merged
Conversation
/lab was mounted before mcp's auth middleware, so every lab route — including run launches that spend LLM budget — was reachable unauthenticated on a public host (the known follow-up in lab/AGENTS.md). Gate the whole mount with the mcp-wide API_TOKEN, accepting either HTTP Basic admin:<API_TOKEN> (the browser prompts once for the UI and then attaches credentials to every request, including EventSource streams, which cannot carry custom headers) or the x-api-token header (parity with the rest of mcp for server-to-server callers). API_TOKEN unset = dev mode = open, the same posture as the /events route. Verified against a live instance: 401 + WWW-Authenticate with no/wrong credentials (wrong user, wrong pass), 200 for basic and x-api-token on /lab/health and the UI, open when API_TOKEN is unset. Co-Authored-By: Claude Fable 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.
What
/labis mounted before mcp's auth middleware, so the entire lab surface — workflow launches (which spend LLM budget), run logs, workspace step editing, secrets listing — was reachable unauthenticated on any host where mcp is exposed. This was the documented known follow-up inmcp/src/lab/AGENTS.md.This gates the whole
/labmount behind the mcp-wideAPI_TOKEN:admin:<API_TOKEN>— the browser prompts once for the UI, then attaches credentials to every request including EventSource/SSE streams (which can't carry custom headers), so the whole SPA + live run tailing works with zero UI changesx-api-tokenheader — parity with the rest of mcp for server-to-server/script callersAPI_TOKENunset ⇒ open (dev mode) — same posture as the existing/eventsrouteTesting
Verified against a live instance (
tsc --noEmitclean):WWW-Authenticate: Basic realm="stakgraph-lab"-u admin:<token>on /lab/health and /lab/ UIx-api-token: <token>API_TOKENunsetProd note: sphinx-swarm already injects
API_TOKENinto the container env from boltwall's stakwork_secret, so this becomes enforced in prod automatically once the image updates.🤖 Generated with Claude Code