Skip to content

Docs: KeyAuth now reads the x-api-key header, but examples/docs still advertise 'Authorization: Key' #982

Open

Description

@lemassykoi

Reality (pfSense-pkg-RESTAPI 2.11_1, pfSense CE 2.9.2)

Auth/KeyAuth.inc detects and reads x-api-key (since 3313e2bc — fix: change KeyAuth to use x-api-key header instead of authorization), but several places still advertise the old Authorization: Key <key> form:

  • Core/Auth.inc @example ['type' => 'apiKey', 'in' => 'header', 'name' => 'Authorization']
  • the docs pages and any copy-paste curl examples using Authorization: Key

Symptom for users

Every request returns 401 AUTH_AUTHENTICATION_FAILED with a valid key — easy to misdiagnose as a web-server/header issue (I opened and have now closed PR #983 on that false trail: nginx passes all headers to PHP automatically, confirmed empirically once the header name was fixed: x-api-key: <key> -> 200).

Suggested fix

Grep docs + code comments for the old header form and replace with x-api-key; optionally make KeyAuth accept Authorization: Key as a deprecated fallback for one release to ease migration.

Activity

  1. changed the title [-]pfSense >= 2.9 (nginx webConfigurator): Authorization header never reaches PHP — all authenticated requests return 401 AUTH_AUTHENTICATION_FAILED[/-] [+]Docs: KeyAuth now reads the x-api-key header, but examples/docs still advertise 'Authorization: Key'[/+] on Nov 23, 2026
  2. jaredhendrickson13 commented on Nov 23, 2026

    @jaredhendrickson13
    Member

    Can you clarify where you're seeing this discrepancy in the documentation?

    The referenced example at Core/Auth.inc doesn't actually apply to the KeyAuth class as it's overwritten in that subclass:

    public array $security_scheme = ['type' => 'apiKey', 'in' => 'header', 'name' => 'x-api-key'];

    Usage is also correctly stated in documentation examples:

    ### API Key Authentication
    API key authentication is a more secure form of authentication that requires the client to send an `X-API-Key` header
    containing a valid API key. These keys are better suited to distribute to systems as they cannot allow webConfigurator
    or SSH authentication (like local database credentials can). API keys can be generated in the pfSense webConfigurator
    under 'System' -> 'REST API' -> 'Keys' or by `POST` request to [/api/v2/auth/key](https://pfrest.org/api-docs/#/AUTH/postAuthKeyEndpoint).
    Below is an example of API Key authentication using `curl`:
    ```bash
    curl -H "X-API-Key: xxxxxxxxxxxxxxxxxxxxxxx" https://pfsense.example.com/api/v2/firewall/rules
    ```

    Additionally, commit 3313e2b is from a pre-release development version of v2.0.0 before the v2.0.0 package was released. v2 never actually used the Authorization header for key auth in or after the initial release. Authorization is only used for basic and JWT authentication.

    Happy to correct any discrepancies if you can point me to the right place.

    Thanks!

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