Subscribe to the Non-Human & AI Identity Journal

Auth Dependency

An auth dependency is a reusable access check that FastAPI runs before an endpoint handler executes. It can block unauthenticated requests, inject verified user context, and centralise session validation, but it only works when every protected route actually uses it consistently.

Expanded Definition

An auth dependency is a reusable gate in FastAPI that executes before request handling, typically to verify identity, session state, or claims and then inject trusted context into the route. In NHI and agentic systems, that same pattern is often used to validate service-to-service callers, bearer tokens, or signed assertions before an NIST Cybersecurity Framework 2.0-aligned control path continues.

Definitions vary across vendors when the dependency does more than authentication, because some teams use it for RBAC, tenant checks, or request enrichment as well. NHI Management Group treats the concept narrowly: the dependency is the enforcement point, while the downstream handler should assume the caller is already verified. That separation matters when an Agent or AI Agent needs bounded tool access, because the credential check must happen before execution authority is granted.

The most common misapplication is relying on a dependency in one router or decorator pattern while leaving other protected routes, background callbacks, or mounted sub-apps unguarded.

Examples and Use Cases

Implementing auth dependencies rigorously often introduces duplication pressure, requiring organisations to weigh cleaner centralised validation against the risk of accidental bypasses in custom routes and middleware stacks.

  • A FastAPI service validates an incoming JWT once, then passes the decoded identity to every endpoint that depends on the shared auth function.
  • A control plane for an internal Agent uses an auth dependency to confirm that the caller’s NHI has only the tool scopes needed for that action.
  • A multi-tenant API adds a dependency that checks tenant membership before any object lookup, reducing the chance of cross-tenant access.
  • A session-backed admin portal uses the dependency to reject expired or revoked sessions before the route handler loads sensitive data.
  • During incident review, teams often trace a missed auth dependency to the same pattern seen in the LiteLLM PyPI package breach, where credential trust and execution boundaries were not enforced tightly enough.

These cases are also consistent with identity assurance guidance in NIST Cybersecurity Framework 2.0, which expects access enforcement to be explicit rather than implicit. In practice, teams often pair the dependency with RBAC, but RBAC should decide what an authenticated caller may do, not whether unauthenticated traffic is allowed to enter.

Why It Matters in NHI Security

Auth dependencies are a practical control boundary for NHI workloads because service accounts, API keys, and automation tokens are frequently reused across routes, jobs, and tool calls. When that boundary is inconsistent, a single overlooked endpoint can expose privileged operations even if the rest of the application appears protected. NHI Management Group research shows that 97% of NHIs carry excessive privileges, increasing unauthorised access and broadening the attack surface, which makes route-level enforcement a governance issue rather than just a code-style preference.

This becomes especially important in zero-trust designs, where every request should be explicitly evaluated rather than assumed safe because it arrived from an internal network. The same lesson appears in the LiteLLM PyPI package breach, where trust in credential handling and execution context proved dangerous once the package was compromised. In a broader program, auth dependencies support the intent of NIST Cybersecurity Framework 2.0 by making access checks observable, repeatable, and reviewable.

Organisations typically encounter the operational impact only after an unauthorised request reaches a sensitive route, at which point auth dependency coverage becomes unavoidable to audit and fix.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP Non-Human Identity Top 10 NHI-01 Auth dependencies enforce request-time identity checks for non-human callers.
NIST CSF 2.0 PR.AC-4 Access permissions must be managed explicitly before resources are reached.
NIST Zero Trust (SP 800-207) Zero Trust requires each request to be authenticated and authorised continuously.

Map protected FastAPI routes to access-control reviews and confirm unauthenticated requests are blocked.