Skip to content

Security: losing the AUTH_LOGIN line in usr/.env silently disables all HTTP and WebSocket authentication #2019

Open

Description

@EddieMurphy89

Reporting note: This repository has no SECURITY.md and exposes no private vulnerability-reporting entry, so this security report is filed as a regular public issue instead of a private report.

Summary

Agent Zero decides whether authentication is required from the presence of AUTH_LOGIN in the process environment, which is loaded from usr/.env at startup. get_credentials_hash() returns None when the value is missing, and both the HTTP decorator (requires_auth) and the WebSocket security check then let the request through instead of rejecting it. The only store is usr/.env, and the product rewrites that file in place with a non-atomic read-modify-truncate cycle whenever settings are saved (save_dotenv_value writes AUTH_LOGIN from the settings form). A crash, power loss, full disk or interrupted write during that save, or an emptied/replaced file, leaves the next process without AUTH_LOGIN; the product cannot distinguish "authentication was never enabled" from "authentication configuration was lost", so it starts with authentication disabled and no warning.

Details

Affected component

helpers/login.py (get_credentials_hash, is_login_required), helpers/api.py (requires_auth), helpers/ws.py (_check_security), helpers/dotenv.py (get_dotenv_value, save_dotenv_value), helpers/settings.py (_write_sensitive_settings).

Vulnerable code

helpers/login.py:

def get_credentials_hash():
    user = dotenv.get_dotenv_value(dotenv.KEY_AUTH_LOGIN)
    password = dotenv.get_dotenv_value(dotenv.KEY_AUTH_PASSWORD)
    if not user:
        return None
    return hashlib.sha256(f"{user}:{password}".encode()).hexdigest()

helpers/api.py:

def requires_auth(f):
    @wraps(f)
    async def decorated(*args, **kwargs):
        from helpers import login
        user_pass_hash = login.get_credentials_hash()
        if not user_pass_hash:
            return await f(*args, **kwargs)      # no credentials -> execute the handler
        if session.get("authentication") != user_pass_hash:
            return redirect(url_for("login_handler", next=get_current_request_next_url()))
        return await f(*args, **kwargs)
    return decorated

helpers/ws.py has the same shape: if user_pass_hash and ctx.auth_hash != user_pass_hash: return {"code": "AUTH_REQUIRED", ...}.

helpers/dotenv.py (the only store, rewritten in place):

def save_dotenv_value(key: str, value: str, reload_env: bool = True):
    ...
    with open(dotenv_path, "r+") as f:
        lines = f.readlines()
        for i, line in enumerate(lines):
            if re.match(rf"^\s*{key}\s*=", line):
                lines[i] = f"{key}={value}\n"
                found = True
        if not found:
            lines.append(f"\n{key}={value}\n")
        f.seek(0)
        f.writelines(lines)
        f.truncate()
    if reload_env:
        load_dotenv()

Root cause

Authentication is keyed on credential presence rather than on an independent "authentication was enabled" fact. A missing or unreadable AUTH_LOGIN is interpreted as "authentication is off", which is the permissive direction, and no compensating check exists: the HTTP and WebSocket paths share the same None handling, and the settings writer can lose the line because it rewrites the file in place without an atomic replace.

Attack path

  1. An operator enables authentication through the settings UI, which writes AUTH_LOGIN/AUTH_PASSWORD into usr/.env; the gateway serves login-protected HTTP and WebSocket routes.
  2. A fault removes the AUTH_LOGIN line at process start: a crash or power loss during a settings save (the in-place r+/writelines/truncate sequence), a full disk, an editor that truncates the file, a failed mount, or an operator replacing/emptying usr/.env.
  3. On the next start, load_dotenv() does not provide AUTH_LOGIN; get_credentials_hash() returns None.
  4. requires_auth executes the protected handler unchanged, and the WebSocket check skips authentication for the same reason.
  5. An unauthenticated client on the network reaches the UI/API/WebSocket routes, obtains a CSRF token from the public endpoint, and can drive the agent and its tools (code execution, file access, browser, MCP).
  6. With the line present, the same request is redirected to the login page (302) or rejected; the only difference between the two arms is whether AUTH_LOGIN is present at boot.

Affected deployments

Deployments that configure login through the settings page or usr/.env (rather than injecting AUTH_LOGIN through container environment variables), where usr/ lives on a persistent volume, and where a crash, full disk or interrupted settings save can occur. Deployments that only pass -e AUTH_LOGIN=... at container start and never write usr/.env are unaffected, and a deployment that never enabled authentication is unauthenticated by design.

Remediation

  1. Decouple "authentication enabled" from "credential present": persist an atomic auth_configured marker; if it says enabled and AUTH_LOGIN is missing or corrupt, refuse to start or force the setup flow.
  2. Write usr/.env atomically (temporary file plus os.replace, fsync before rename).
  3. Fail closed in requires_auth and the WS check when an authentication-enabled deployment cannot resolve credentials (503/500 instead of executing the handler).
  4. Log a loud startup warning when usr/.env exists without AUTH_LOGIN, and never silently serve an unauthenticated gateway after authentication was configured.
  5. Add regression tests for both paths (present → 302/WS AUTH_REQUIRED, missing → deny, not allow).

Proof of concept

Baseline: start Agent Zero with authentication configured (AUTH_LOGIN=admin and AUTH_PASSWORD=<password>; the UI listens on http://127.0.0.1:5000 by default), then request a protected API route without a session:

curl -s -o /dev/null -w '%{http_code}\n' -X POST http://127.0.0.1:5000/api/settings_get

Expected: 302 (redirect to the login page); the protected handler does not run. The same request with a valid login session returns the settings JSON.

Fault: stop the process, remove the AUTH_LOGIN line (or empty usr/.env) to model the file an interrupted settings save leaves behind, and restart:

grep -v '^AUTH_LOGIN=' usr/.env > usr/.env.new && mv usr/.env.new usr/.env

With authentication off, the public CSRF endpoint accepts the request and issues a token (the origin must be one of the default local origins, which 127.0.0.1:5000 is). Then call the same protected handler without any login:

curl -s -c /tmp/a0.jar -H 'Origin: http://127.0.0.1:5000' http://127.0.0.1:5000/api/csrf_token
TOKEN=$(curl -s -b /tmp/a0.jar -H 'Origin: http://127.0.0.1:5000' http://127.0.0.1:5000/api/csrf_token | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')
curl -s -o /dev/null -w '%{http_code}\n' -b /tmp/a0.jar -H 'Origin: http://127.0.0.1:5000' \
  -H "X-CSRF-Token: $TOKEN" -X POST http://127.0.0.1:5000/api/settings_get

Expected difference: the last request returns 200 and the full settings payload (including the model and API-key configuration), with no session and no login redirect. The same token-acquisition request is redirected to the login page when AUTH_LOGIN is present, so the two arms differ only in whether the line exists at boot. The WebSocket endpoints behave the same way: _check_security only compares the auth hash when get_credentials_hash() returned one, so a WS connection is accepted after the same restart.

Impact

The worst demonstrated impact is unauthenticated remote control of the entire Agent Zero instance: any network client that can reach port 5000 can call the API and open the WebSocket channels without a session, then drive the agent and its tools, including shell/Python code execution, file access, browser control and MCP servers. In practice this is remote code execution as the application user for any deployment that had authentication enabled and lost the line. Agent Zero is a full agent runtime, so this is effectively remote code execution as the application user for any deployment that had authentication enabled and lost the line. Not implied: deployments that inject AUTH_LOGIN via container environment variables are unaffected, the few requires_loopback endpoints keep their loopback check, and a deployment that never enabled authentication was already open by design.

Affected products

Agent Zero source deployments and releases up to 2.15 (agent0ai/agent-zero), including the shipped Docker images; verified at commit ba9b67df0f54ac78106ae85c552ef5d2458f7c9a (tag v2.15, 2026-11-01).

Weaknesses

CWE-287 (Improper Authentication), CWE-636 (Not Failing Securely). The impact-level weakness is unauthenticated access to an agent runtime with command execution.

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