Skip to content

API key: an empty value silently disables authentication, and the key is compared with == #213

Closed

Description

@alphastorm

Two small hardening points in the API key check (serve/server.py#L1243-L1251):

  1. An empty key turns authentication off, silently on 127.0.0.1. --api-key defaults to $STRATA_API_KEY (#L1669-L1670), and an empty value falls back to the config's api_key (#L1727); when both are empty, _authorized() lets every request through. The "no API key" warning is printed only for other hosts (#L1752-L1761); on 127.0.0.1 the ready line just leaves out ", API key required". A launcher that meant to set a key but exported an empty STRATA_API_KEY gets an open server and no sign of it.
  2. The key is compared with == (given == svc.api_key), which is not a constant-time comparison. hmac.compare_digest(given.encode(), svc.api_key.encode()) is the usual replacement.

Suggested: refuse to start, or at least warn on every host, when --api-key or STRATA_API_KEY is given but empty, and compare with hmac.compare_digest.

Activity

  1. Niko1221 commented on Sep 30, 2026

    @Niko1221
    Owner

    Good points. 0.1.28 (in testing) compares the key in constant time (hmac.compare_digest), and an explicitly empty key (--api-key "" or an empty STRATA_API_KEY) stops the server with a message instead of switching authentication off.

  2. Niko1221 commented on Sep 30, 2026

    @Niko1221
    Owner

    Fixed in 0.1.28: constant-time comparison (hmac.compare_digest), and an explicitly empty key (--api-key "" or an empty STRATA_API_KEY) stops the server with a message.

  3. added a commit that references this issue on Oct 1, 2026
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions