Skip to content

fix(security): harden execution, sessions, MCP HTTP, and first admin - #77

Open
tao-hpu wants to merge 4 commits into
masterfrom
cursor/security-audit-hardening-136b
Open

tao-hpu wants to merge 4 commits into
masterfrom
cursor/security-audit-hardening-136b

Conversation

@tao-hpu

@tao-hpu tao-hpu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Hardens four defaults in the application and deployment entrypoint, with regression tests.

  • Inside a container, code execution uses the sandbox backend. A leftover CODE_EXEC_BACKEND=local is ignored unless ALLOW_LOCAL_CODE_EXEC=true. Outside a container, unset still means local.
  • Changing, setting, or resetting a password, revoking all sessions, an administrator forcing sign-out, and disabling an account increment users.session_generation and clear the stored refresh token. Access and refresh tokens carry that value as gen. A token from an earlier generation is rejected, including one issued in the same second. Turning a disabled account back on does not restore tokens issued before the disable. /refresh replaces the stored refresh token only when both the presented hash and the generation it read are still current, so a password change in flight cannot leave a rotated session behind. Tokens issued before this version have no gen and keep working while the account is still at generation 0; the next sign-out, password change, or disable rejects them. Migration g4c0e2f7a813 adds the column (not null, server default 0) and fills existing rows with 0. Inserts that do not set the value leave it to that default, so a schema from before the column still accepts those rows.
  • MCP SSE and streamable HTTP clients resolve the host again on each request and connect to the address they checked. They do not use a proxy from the environment.
  • The first administrator is created only by POST /api/auth/setup, which requires FIM_SETUP_TOKEN. The setup page sends that value only in the request body, in a password field, and does not store it. Registration and provider sign-in cannot create that account. Concurrent setup calls take one database lock, so only one can succeed.

Why

These paths were weaker than the documented deployment: in-process code execution could still be selected inside a container, a session could still be used after a password change, a self-serve sign-out, or re-enabling a disabled account, MCP HTTP connections checked the address only before connecting, and the first account could be created more than once without a setup secret.

Type

  • Bug fix
  • Security patch
  • Documentation
  • New feature (discussed in issue first)
  • Refactoring
  • Test coverage
  • Translation / i18n

Checklist

  • uv run ruff check src/ tests/ passes (the tree already has findings; this change does not take that on)
  • uv run mypy on the edited auth modules — no issues
  • Focused pytest on this commit: session revocation (including re-enable), session invalidation, first-admin setup, code-exec policy, SSRF transport, MCP client, and admin audit metadata — 92 passed
  • CI on 26a41b6a (run 45635335205): Python 3.11, 3.12, and 3.13, Frontend, Docs links, and Workflow editor smoke passed
  • i18n strings added to both en/ and zh/ (English docs and messages only; translation runs on master via i18n sync, and this environment has no translate key)
  • Tests added for new functionality
  • Alembic g4c0e2f7a813 upgrade, downgrade, upgrade on a disposable local SQLite database and on a disposable local PostgreSQL 16 database, including an existing user row backfilled to 0

Operator notes

Set FIM_SETUP_TOKEN to a long random value before creating the first administrator, and enter it on the setup page. Instances that already have users are unchanged. Do not commit the token.

Inside a container, remove a leftover CODE_EXEC_BACKEND=local unless you also set ALLOW_LOCAL_CODE_EXEC=true. The entrypoint otherwise starts the sandbox backend and waits for the proxy token. Outside a container, ./start.sh with CODE_EXEC_BACKEND unset still runs code in the application process.

Apply migration g4c0e2f7a813 with the usual startup migration. Existing sessions keep working until the next password change, sign-out of all sessions, or disable. Disabling an account signs its sessions out. Turning it back on does not restore tokens issued before the disable; sign in again. Requests are refused while the account is disabled.

Dependency updates for Next.js, soupsieve, and opentelemetry-api are left to the existing pull requests and are not included here.

Open in Web Open in Cursor 

cursoragent and others added 4 commits November 23, 2026 05:15
Inside a container, code execution uses the sandbox unless
ALLOW_LOCAL_CODE_EXEC is set, so a leftover local setting does not run
code in the application process. Password changes and revoking sessions
drop the refresh token and reject access tokens issued before that
second. MCP HTTP and SSE clients pin the address on each request. The
first administrator is created only from setup with FIM_SETUP_TOKEN,
and only one concurrent setup can succeed.

Co-authored-by: Tao An <tao-hpu@users.noreply.github.com>
Access and refresh tokens now carry the account's session generation.
Password changes, session revoke, and admin force-logout increment it, so a
token issued in the same second is rejected. Tokens from before this column
stay valid until the next sign-out or password change. Refresh rotation only
commits when the generation is still the one it read.

Co-authored-by: Tao An <tao-hpu@users.noreply.github.com>
A Python-side default was written into every INSERT, including rows built
against a schema from before the column existed. The column stays NOT NULL
with a server default of 0, so existing and new rows still start at 0.

Co-authored-by: Tao An <tao-hpu@users.noreply.github.com>
Disabling an account now increments its session generation, the same cut
password changes and revoke-all already use. Turning the account back on
no longer accepts an access token issued before the disable.

Co-authored-by: Tao An <tao-hpu@users.noreply.github.com>

This branch has not been deployed

No deployments
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