A security audit found five ways one tenant could reach another tenant's
data or act on its behalf. All five are closed here.
1. Clone directories were shared. Every producer and consumer resolved a
checkout to `<git_clone_base>/<sanitized-name>`, so two tenants that
onboarded a target with the same name got one directory: the second one
to scan fetched the first one's `origin` instead of cloning its own, and
then scanned it. Checkouts are now `<base>/<tenant>/<name>` through a
single helper, `pipeline::git::clone_dir`, which every call site uses —
the orchestrator, PR review, ingest, the graph build, the chat embedding
build and the file-content reader. Both segments collapse to one safe
path component, and the tenant segment additionally carries a digest
whenever collapsing was lossy, so two distinct tenant ids can never map
to one directory.
2. One SSH deploy key authenticated every tenant's clone. A tenant that
added the agent's key to a repository made that repository readable by
any other tenant that named its URL. Per-tenant key management is R1, so
at MVP the key is gone entirely: `RepoCredentials` is HTTPS-token only,
an `ssh://`/`git@` URL is rejected with a message pointing at the HTTPS
URL and a token, and `SSH_KEY_PATH`, the generator, the
`/api/v1/settings/ssh-public-key` endpoint, the dashboard panel that
advertised the key and the onboarding docs are all removed.
3. `serve_artifact` had no tenant check. Runner blobs are addressed by
content hash and the hash is in the job record, so any valid runner key
could fetch any tenant's control-logic source. The blob store is now per
tenant (`<base>/tenants/<tenant>/blobs/…`) and the read is bound to the
tenant the key is bound to; another tenant's digest is simply not there.
4. The runner scope check accepted the `werkbank:runner` scope *or* any key
whose product was `pruefwerk`, which made every product API key a runner
key able to lease and complete other tenants' jobs. The scope is now
required.
5. Webhooks created databases before authenticating. A POST with any
`tenant_id` reached `for_tenant_id`, whose index-ensure materializes
`<prefix>_<tenant_id>` — an unauthenticated write primitive. The target
lookup now goes through `DatabasePool::for_existing_tenant_id`, which
creates nothing; an unknown tenant or target is a 404.
Also: the static `WERKBANK_RUNNER_TOKEN` names no tenant, so a holder acts
for all of them. It is still accepted in dev, where it is the only option
before the platform is wired up, and refused when `app_env.is_hardened()`.
URL-scheme and SSRF validation (file://, local paths, server-side
`source_ref`) is deliberately untouched — that is #256.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p