Skip to content

fix(auth): default-deny public self-signup on /api/access/request - #1274

Merged
vybe merged 1 commit into
devfrom
fix/ent10-access-request-secure-default
Jun 19, 2026
Merged

vybe merged 1 commit into
devfrom
fix/ent10-access-request-secure-default

Conversation

@dolho

@dolho dolho commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

POST /api/access/request (unauthenticated) auto-whitelisted any submitted email (role user), letting anyone who can reach the backend self-enroll and then log in via email OTP — so the email whitelist was not authoritative against self-enrollment, despite the "request access" naming implying admin approval.

Fix — secure default: gate the endpoint behind PUBLIC_ACCESS_REQUESTS_ENABLED (env) / the public_access_requests_enabled system setting, default CLOSED. When off → 403, no whitelist write. The gate runs before body parsing so a disabled instance never processes self-signup input.

Product decision (recorded per AC)

Keep frictionless auto-whitelist behind the flag rather than building a full admin-approval pending flow — minimal and non-breaking for opt-in (trinity:connect) users. A real pending flow can later build on the existing #311 access_requests precedent. Flipping the default off is a behavior change for anyone who relied on open self-signup — they set the flag to re-enable.

Acceptance criteria

  • Flag gates the endpoint, default closed → 403 when disabled.
  • Product decision recorded (flag-gated auto-approve; pending-flow deferred).
  • Disabled → non-whitelisted email is not whitelisted (verified in tests).
  • Response wording no longer says "Access granted".
  • Already-whitelisted emails can still request login codes regardless of the flag (separate endpoint, untouched).
  • Tests: default rejects (403, no whitelist); enabling is explicit and covered.
  • CLI onboarding docs updated (cli-tool flow, architecture, .env.example).

Testing

  • tests/unit/test_ent10_access_request_gate.py (offline, 4 tests): 403 + no-whitelist when off; auto-whitelist (normalized email, role user) when on; idempotent; 400 validation once open. All pass.
  • tests/test_cli_access_request.py rewritten: default-closed 403 (+ asserts the email isn't whitelisted via the admin list), and an operator-enabled class that toggles the setting via PUT /api/settings/{key} and restores it.
  • lint_sys_modules green.

Related to trinity-enterprise#10

POST /api/access/request was unauthenticated and AUTO-WHITELISTED any submitted
email (role `user`), so anyone who could reach the backend could self-enroll
and then log in via email OTP — the email whitelist was non-authoritative
against self-enrollment, despite the "request access" naming implying admin
approval.

Secure default: gate the endpoint behind PUBLIC_ACCESS_REQUESTS_ENABLED
(env) / the `public_access_requests_enabled` system setting, default CLOSED.
When off, the endpoint returns 403 and never whitelists. Operators who want
frictionless `trinity:connect` CLI onboarding opt in explicitly. The gate runs
before body parsing so a disabled instance never processes self-signup input.

Product decision (recorded): keep frictionless auto-whitelist behind the flag
rather than building a full admin-approval pending flow — minimal, non-breaking
for opt-in users; a real pending flow can build on the existing #311
access_requests precedent later. Response wording no longer says "Access
granted" (it isn't a per-request admin decision). Login-code requests for
already-whitelisted emails (/api/auth/email/request) are unaffected.

Default-deny blast radius is unchanged: a self-enrolled `user` owns no agents
and cannot create any (#314), so even an opted-in instance grants only an empty
session — but the whitelist is now the real gate by default.

Tests: offline unit test for the gate (403 + no-whitelist when off; auto-whitelist
when on; idempotent; 400 validation). Integration test_cli_access_request rewritten
to cover the default-closed 403 and the operator-enabled path (toggled via the
admin settings endpoint). Docs (architecture, cli-tool flow, .env.example) updated.

Related to trinity-enterprise#10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: P1 security fix (trinity-enterprise#10) — default-deny self-signup, fails secure (OFF→403), whitelist stays authoritative, no secrets. Docs + .env.example updated; 4 unit + CLI tests.

One non-blocking note: PUBLIC_ACCESS_REQUESTS_ENABLED isn't wired into docker-compose*.yml backend.environment, so that env lever is inert on prod-standalone — but the gate reads the DB system setting first (operators enable via PUT /api/settings), the secure default holds on deploy regardless, and this matches the existing SESSION_TAB_ENABLED settings-API-primary precedent. Approving.

@vybe
vybe merged commit aa0f350 into dev Jun 19, 2026
16 of 17 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.

2 participants