//nefariousplan

CVE-2026-49948: Mem0 Patched `/configure` to Require Admin. The User Model's `role` Column Has One Value the Application Code Writes.

vendor

patterns

cve

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.

CVE-2026-49948 Names /configure. The Patch Hardens Six Handlers.

The 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.

# server/main.py
-def set_config(config: Dict[str, Any], _auth=Depends(verify_auth)):
+def set_config(config: Dict[str, Any], _auth=Depends(require_admin)):
     """Set memory configuration."""

-def delete_all_memories(..., _auth=Depends(verify_auth)):
+def delete_all_memories(..., _auth=Depends(require_admin)):
     """Delete all memories for a given identifier."""

-def reset_memory(_auth=Depends(verify_auth)):
+def reset_memory(_auth=Depends(require_admin)):
     """Completely reset stored memories."""

# get_all_memories: inline admin check added when no identifier is supplied
+        auth_type = getattr(request.state, "auth_type", "none")
+        if _auth is not None and _auth.role != "admin" and auth_type not in {"admin_api_key", "disabled"}:
+            raise HTTPException(status_code=403, detail="Admin role required to list all memories.")

# server/routers/entities.py
-def delete_entity(entity_type, entity_id, _auth=Depends(verify_auth)):
+def delete_entity(entity_type, entity_id, _auth=Depends(require_admin)):

# server/routers/requests.py
-def list_requests(user: User = Depends(require_auth), ...):
+def list_requests(_auth=Depends(require_admin), ...):

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.

verify_auth Was The Entire Gate

The 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.

@app.post("/configure", summary="Configure Mem0")
def set_config(config: Dict[str, Any], _auth=Depends(verify_auth)):
    """Set memory configuration."""
    _validate_bundled_providers(config)
    update_config(config)
    return {"message": "Configuration set successfully"}

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.

This is the 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.

Every User The Application Has A Code Path To Create Is Admin

The User model declares the role column with a default of "admin":

class User(Base):
    __tablename__ = "users"
    id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=_new_uuid)
    name: Mapped[str] = mapped_column(String(255))
    email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
    password_hash: Mapped[str] = mapped_column(Text)
    role: Mapped[str] = mapped_column(String(20), default="admin")
    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_utcnow)
    last_login_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)

The only path into the users table is /auth/register:

@router.post("/register", response_model=TokenResponse)
def register(request: Request, body: RegisterRequest, db: Session = Depends(get_db)):
    """Create the first admin account. Blocked once any user exists."""
    _require_password_length(body.password)

    if db.scalar(select(func.count(User.id))) > 0:
        raise HTTPException(status_code=403, detail="Registration is closed. An admin account already exists.")

    user = User(
        name=body.name,
        email=body.email,
        password_hash=hash_password(body.password),
        role="admin",
    )

The 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.

The 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:

_BOOTSTRAP_ADMIN = User(
    id=uuid.UUID(int=0), name="admin_api_key", email="", password_hash="",
    role="admin", created_at=datetime.min.replace(tzinfo=timezone.utc),
)

A repository search for any role value other than the string "admin" in any Python file under server/ returns nothing.

Migration 004, dated April 21 2026, added the partial unique index:

op.create_index(
    "ix_users_only_one_admin",
    "users",
    ["role"],
    unique=True,
    postgresql_where=sa.text("role = 'admin'"),
)

The 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.

The Distributed API Key Threat Is Unchanged

The CVE-2026-49948 description names a specific threat actor: any authenticated user holding a distributed API key. This is 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.

The 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:

def _resolve_user_from_api_key(key: str, db: Session) -> User:
    prefix = key[:12] if len(key) >= 12 else key
    candidates = (
        db.execute(select(APIKey).where(APIKey.key_prefix == prefix, APIKey.revoked_at.is_(None)))
        .scalars().all()
    )
    for candidate in candidates:
        if verify_api_key_hash(key, candidate.key_hash):
            candidate.last_used_at = datetime.now(timezone.utc)
            db.commit()
            user = db.get(User, candidate.created_by)
            if user is None:
                raise HTTPException(status_code=401, detail="API key owner not found.")
            return user
    raise HTTPException(status_code=401, detail="Invalid API key.")

The 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).

Pre-patch trace, holder of distributed key calling /configure: verify_auth resolves the key to the admin, set_config runs.

Post-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.

The 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.

The 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.

The Pattern: Decoration Replaced By Tautology

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.

The 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.

The 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.

The 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.

Patch: mem0ai/mem0@ae7f406

The patch protects six handlers against a role the application has no code path to write.