Skip to content

AUTH during an open BEGIN session switches namespace → keys from two namespaces committed in one atomic transaction #508

Description

@liunyl

AUTH is not blocked while a BEGIN session transaction is open, and it unconditionally rewrites the connection's namespace prefix. Commands issued after the mid-transaction AUTH therefore land under a different namespace while sharing the same txm, so a single atomic commit mixes keys from two namespaces.

Evidence

AuthCommand::Execute rewrites the namespace with no open-transaction guard (src/redis_command.cpp:1503-1511):

if (ns_meta) {
    ctx->authenticated = true;
    ctx->ns = ns_meta->ns_name;
    ctx->ns_meta = ns_meta;
    ctx->ns_id = NamespacePrefix::MakePrefix(ns_meta->encoded_id, ns_meta->epoch...);
}

By contrast, WATCH is rejected during a session (src/redis_service.cpp:6016-6019: "ERR WATCH inside a BEGIN transaction"), and AUTH mid-MULTI is also rejected — but AUTH mid-BEGIN is not. In a BEGIN session, subsequent commands run immediately on ctx->txm, and key prefixing uses the now-changed ctx->ns_id.

Repro

BEGIN; SET a 1 (namespace N1) ; AUTH <token-for-N2>; SET b 2; COMMITa (N1) and b (N2) are committed atomically in one transaction, crossing the namespace isolation boundary.

Fix: reject AUTH (and any namespace switch) while ctx->txm != nullptr, as is already done for WATCH.


Found during a code audit (docs PR #492). Verified against source at the cited lines. Related: #493, #499.

🤖 Found with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions