-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## CVE-2026-49948 Names `/configure`. The Patch Hardens Six Handlers.\n\nThe CVE-2026-49948 record describes one endpoint: `POST /configure`, which modifies global LLM and embedder provider configuration on the self-hosted Mem0 server and persists the change to PostgreSQL. Commit `ae7f4062`, titled `fix(server): harden self-hosted server, pgvector upgrade, admin auth, endpoint security` and merged as PR #5360 on June 5 2026, touches six endpoints across three files.\n\n```diff\n# server/main.py\n-def set_config(config: Dict[str, Any], _auth=Depends(verify_auth)):\n+def set_config(config: Dict[str, Any], _auth=Depends(require_admin)):\n \"\"\"Set memory configuration.\"\"\"\n\n-def delete_all_memories(..., _auth=Depends(verify_auth)):\n+def delete_all_memories(..., _auth=Depends(require_admin)):\n \"\"\"Delete all memories for a given identifier.\"\"\"\n\n-def reset_memory(_auth=Depends(verify_auth)):\n+def reset_memory(_auth=Depends(require_admin)):\n \"\"\"Completely reset stored memories.\"\"\"\n\n# get_all_memories: inline admin check added when no identifier is supplied\n+ auth_type = getattr(request.state, \"auth_type\", \"none\")\n+ if _auth is not None and _auth.role != \"admin\" and auth_type not in {\"admin_api_key\", \"disabled\"}:\n+ raise HTTPException(status_code=403, detail=\"Admin role required to list all memories.\")\n\n# server/routers/entities.py\n-def delete_entity(entity_type, entity_id, _auth=Depends(verify_auth)):\n+def delete_entity(entity_type, entity_id, _auth=Depends(require_admin)):\n\n# server/routers/requests.py\n-def list_requests(user: User = Depends(require_auth), ...):\n+def list_requests(_auth=Depends(require_admin), ...):\n```\n\n`POST /configure`, `POST /reset`, `DELETE /memories` without an identifier, `GET /memories` without an identifier, `DELETE /entities/{type}/{id}`, and `GET /requests`. Six handlers, one dependency swap each. The CVE-2026-49948 description's framing is `the /configure endpoint modifies global LLM provider and embedder configuration`. The patch admits that the same authorization gap exists for the endpoint that resets the entire instance, for the endpoints that list and delete every stored memory across every tenant on the instance, for the endpoint that deletes any entity by ID, and for the endpoint that reads the cross-instance request log. The CVE numbered the smallest one.\n\n## `verify_auth` Was The Entire Gate\n\nThe pre-patch handler is the standard FastAPI dependency-injection pattern. `Depends(verify_auth)` runs the helper, the returned value is bound to the parameter named `_auth`, and the function body proceeds.\n\n```python\n@app.post(\"/configure\", summary=\"Configure Mem0\")\ndef set_config(config: Dict[str, Any], _auth=Depends(verify_auth)):\n \"\"\"Set memory configuration.\"\"\"\n _validate_bundled_providers(config)\n update_config(config)\n return {\"message\": \"Configuration set successfully\"}\n```\n\n`verify_auth` returns the `User` row that authenticated, or `None` for the env-var `ADMIN_API_KEY` and `AUTH_DISABLED` paths. The `User` row carries a `role` field. The handler body never reads it. The bound parameter is prefixed with an underscore by convention, the standard Python signal that the value exists only because the dependency machinery runs as a side effect, and the body has no use for the binding itself.\n\nThis is the [Gate Was Decoration](/patterns/gate-was-decoration) pattern in its canonical form. The helper is called. The return value is bound. No branch on the result. CVE-2026-49948 names the handler where the dependency injection exists and the branch on its result does not.\n\n## Every User The Application Has A Code Path To Create Is Admin\n\nThe `User` model declares the `role` column with a default of `\"admin\"`:\n\n```python\nclass User(Base):\n __tablename__ = \"users\"\n id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=_new_uuid)\n name: Mapped[str] = mapped_column(String(255))\n email: Mapped[str] = mapped_column(String(255), unique=True, index=True)\n password_hash: Mapped[str] = mapped_column(Text)\n role: Mapped[str] = mapped_column(String(20), default=\"admin\")\n created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_utcnow)\n last_login_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)\n```\n\nThe only path into the `users` table is `/auth/register`:\n\n```python\n@router.post(\"/register\", response_model=TokenResponse)\ndef register(request: Request, body: RegisterRequest, db: Session = Depends(get_db)):\n \"\"\"Create the first admin account. Blocked once any user exists.\"\"\"\n _require_password_length(body.password)\n\n if db.scalar(select(func.count(User.id))) > 0:\n raise HTTPException(status_code=403, detail=\"Registration is closed. An admin account already exists.\")\n\n user = User(\n name=body.name,\n email=body.email,\n password_hash=hash_password(body.password),\n role=\"admin\",\n )\n```\n\nThe handler is a one-shot bootstrap. It checks the row count, refuses if any user exists, and otherwise creates a `User` with the role string literal `\"admin\"`. There is no second user-creation route. There is no member-invite route. There is no admin-creates-user route. The dashboard's `/setup` page calls `/auth/register`; it sets `role` to nothing because the model default already binds it. There is no UI flow anywhere in `server/dashboard/src/` for adding a teammate.\n\nThe only other assignment to `role` anywhere under `server/` is in `auth.py` at line 189, the synthetic `_BOOTSTRAP_ADMIN` constant that `require_admin` returns when the deployment is running with `ADMIN_API_KEY` env-var auth and no users exist yet:\n\n```python\n_BOOTSTRAP_ADMIN = User(\n id=uuid.UUID(int=0), name=\"admin_api_key\", email=\"\", password_hash=\"\",\n role=\"admin\", created_at=datetime.min.replace(tzinfo=timezone.utc),\n)\n```\n\nA repository search for any role value other than the string `\"admin\"` in any Python file under `server/` returns nothing.\n\nMigration 004, dated April 21 2026, added the partial unique index:\n\n```python\nop.create_index(\n \"ix_users_only_one_admin\",\n \"users\",\n [\"role\"],\n unique=True,\n postgresql_where=sa.text(\"role = 'admin'\"),\n)\n```\n\nThe constraint enforces at-most-one row with `role = 'admin'`. The column default is `'admin'`. The constraint forbids more than one row with that default. Together they encode the deployment shape Mem0 ships: exactly one admin per instance, no other roles. The schema accepts a twenty-character string in the `role` column. The application code writes one value.\n\n## The Distributed API Key Threat Is Unchanged\n\nThe CVE-2026-49948 description names a specific threat actor: `any authenticated user holding a distributed API key`. This is [Trust Inversion](/patterns/trust-inversion) in literal form: the credential Mem0 mints for distributing non-admin access to applications and teammates is the credential the description names as the attack surface against the admin-only `/configure` endpoint. Walk the path that holder takes through the patched code.\n\nThe holder sends `POST /configure` with an `X-API-Key` header. `verify_auth` runs as the dependency of `require_admin`. The header is matched against the env-var `ADMIN_API_KEY` first; if it matches, the function returns `None` and `require_admin` synthesizes the admin role via `_BOOTSTRAP_ADMIN` or the first registered user. If it does not match, the X-API-Key value is looked up in the `api_keys` table:\n\n```python\ndef _resolve_user_from_api_key(key: str, db: Session) -> User:\n prefix = key[:12] if len(key) >= 12 else key\n candidates = (\n db.execute(select(APIKey).where(APIKey.key_prefix == prefix, APIKey.revoked_at.is_(None)))\n .scalars().all()\n )\n for candidate in candidates:\n if verify_api_key_hash(key, candidate.key_hash):\n candidate.last_used_at = datetime.now(timezone.utc)\n db.commit()\n user = db.get(User, candidate.created_by)\n if user is None:\n raise HTTPException(status_code=401, detail=\"API key owner not found.\")\n return user\n raise HTTPException(status_code=401, detail=\"Invalid API key.\")\n```\n\nThe matched `APIKey` row's `created_by` UUID is the User who minted the key. The User row is loaded and returned. `require_admin` then runs `if user.role != \"admin\": raise 403`. The returned User's role is `\"admin\"`, because the only user the application code can create is the admin who bootstrapped via `/auth/register`, and that user is the only one who can mint API keys (`/api-keys` is gated by `require_auth`, which returns that same user).\n\nPre-patch trace, holder of distributed key calling `/configure`: `verify_auth` resolves the key to the admin, `set_config` runs.\n\nPost-patch trace, same holder calling `/configure`: `verify_auth` resolves the key to the admin, `require_admin` reads `admin.role`, sees `\"admin\"`, returns the same user, `set_config` runs.\n\nThe distributed-API-key threat the CVE-2026-49948 description names, where the holder of any minted key writes the global LLM and embedder configuration to redirect every prompt and every embedding on the instance to an attacker-controlled server, is the pre-patch threat and is the post-patch threat. The patch adds one database equality check per request to the path. The path executes the same handler with the same caller resolution to the same user with the same role.\n\nThe `api_keys` table has no role column. There is no per-key permission. There is no scope or audience on the key. The key inherits the role of the user who minted it, and the user who minted it is the only user who exists, and that user is admin.\n\n## The Pattern: Decoration Replaced By Tautology\n\n[Gate Was Decoration](/patterns/gate-was-decoration) is the shape where an authentication helper is called at the entry of a handler and its return value bound to a local variable that the body never reads. browserstack-runner's `_log` handler took `getWorkerUuid(request)`, bound it to `uuid`, and used it only as a `%s` label inside `logger.trace`. Mem0's `set_config` took `Depends(verify_auth)`, bound the result to `_auth`, and used it for nothing at all. The underscore prefix on `_auth` is the convention's surface acknowledgement that the body has no business with what the helper returned.\n\nThe patch swaps the helper. The check is now inside the helper, not the handler. `require_admin` reads `user.role` and compares it to the string `\"admin\"`. Every user the application code produces has that role; the inequality the helper checks for is structurally unreachable through any application code path. The pre-patch gate did not read the role. The post-patch gate reads the role and finds it always equal to the single value the application can write.\n\nThe check is forward-compatible. If Mem0 later ships a member-invite flow that creates a `User` with `role=\"member\"`, the patch's check will block that user's API key from calling `/configure`. The check is correct preparation. It is not a current mitigation. CVE-2026-49948 describes a current bug. The patch addresses a future schema.\n\nThe credential the CVE-2026-49948 description names as the attack surface, the distributed API key, has no role of its own. The Trust Inversion the description traces, from minted-for-distribution to admin-authoritative, operates on the minting user's role. The minting user is the admin. The check passes. The credential remains exactly as authoritative as it was before.\n\nPatch: [mem0ai/mem0@ae7f406](https://github.com/mem0ai/mem0/commit/ae7f4062652df1376990221101d1adbb0819c973)","closing_line":"The patch protects six handlers against a role the application has no code path to write.","hook_md":"The patch for CVE-2026-49948 replaces one FastAPI dependency on six handlers in Mem0's self-hosted server. `_auth=Depends(verify_auth)` becomes `_auth=Depends(require_admin)`. The new `require_admin` raises 403 unless `user.role == \"admin\"`. The `User` model declares `role: Mapped[str] = mapped_column(String(20), default=\"admin\")`. Migration 001, dated April 10 2026, created the column with `server_default=\"admin\"`. Migration 004, dated April 21 2026, added a partial unique index `WHERE role = 'admin'` that constrains the `users` table to at most one admin row. The only two assignments to `role` anywhere under `server/` are both the literal string `\"admin\"`. CVE-2026-49948 is what Mem0 disclosed in commit `ae7f4062` on June 5 2026 and what NVD published ten days later. The check the patch enforces is true for every user the application has a code path to create.","post_id":637,"slug":"mem0-cve-2026-49948-the-role-check-the-app-cant-fail","title":"CVE-2026-49948: Mem0 Patched `/configure` to Require Admin. The User Model's `role` Column Has One Value the Application Code Writes.","type":"initial","unreadable_sentence":"The patch protects six handlers against a role the application has no code path to write."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaxGwfwAKCRDeZjl4jgkQ JrOIAP4oLfR5V8xJrFtJeoCzsSqaLhBSVYIVoidIE5afQXITQQD/aFKlnkAUaIEW b1VnP0d8QB+47iWJiONpb/B2LpS9hw8= =f4bk -----END PGP SIGNATURE-----