The Two Faces of API Access
A headless content API serves two primary types of users: humans interacting with an administrative interface and machines fetching published content. It is a common and dangerous mistake to secure these two distinct access patterns with identical credentials and threat models. Treating them as one leads to either an overly cumbersome experience for automated systems or a dangerously weakened security posture for administrative functions.
Consider the implications: an administrator needs broad, potentially destructive access to manage content. A public-facing website, on the other hand, should only ever read published content. Their credentials must reflect these fundamentally different permissions and risk profiles. A unified approach creates a compromise that satisfies neither requirement effectively. This is akin to using the same key for your front door and your safety deposit box – one is too weak, the other too inconvenient.
The key is to recognize that these are not just different users, but different roles with opposing security needs. The human operator is a trusted entity with a need for broad access but subject to phishing and credential compromise. The machine client is an untrusted entity that requires highly restricted, read-only access, but its credentials must be robustly protected against exposure.

Session-Based Authentication for Humans
When a human logs into an administrative UI, they establish a session. This session acts as proof that a specific, authenticated human is currently active and authorized to manage the content. These sessions are typically short-lived, often managed via HTTPOnly cookies that are inaccessible to JavaScript, thereby mitigating certain cross-site scripting (XSS) attacks. The session cookie is sent with every request to management routes, confirming the user's identity for that specific interaction.
The threat model for a session is primarily concerned with the human user's actions and the security of their browser. This includes risks like:
- Credential stuffing and brute-force attacks: If passwords are weak or reused, attackers might gain access.
- Phishing: Users can be tricked into revealing their credentials.
- Session hijacking: If the session cookie is intercepted (though HTTPOnly cookies mitigate this significantly), an attacker could impersonate the user.
- Malicious browser extensions: These could potentially interfere with cookie handling or user input.
Therefore, session management focuses on robust password policies, multi-factor authentication (MFA), and secure cookie handling. The user is generally considered a trusted agent within the system, but their endpoint (the browser) is not.
Token-Based Authentication for Machines
Machines, such as websites, build processes, or third-party integrations, need to access published content. They do not log in through a UI and do not require session cookies. Instead, they authenticate using delivery tokens. These tokens are long-lived, often API keys or bearer tokens, and are passed in the `Authorization` header of API requests.
The threat model for delivery tokens is fundamentally different. The machine itself is the potential point of compromise. Unlike a human session, the delivery token represents a persistent grant of access. If exposed, an attacker can impersonate the machine indefinitely, or at least until the token is revoked.
Key risks for delivery tokens include:
- Exposure in code repositories: Hardcoding tokens in public or private Git repositories is a common and severe mistake.
- Logging and debugging: Tokens inadvertently logged to insecure systems.
- Man-in-the-middle attacks: If the API is not served over HTTPS, tokens can be intercepted.
- Compromised build environments: A compromised CI/CD pipeline could steal active tokens.
Security for delivery tokens must focus on restricting their scope to the absolute minimum necessary permissions (e.g., read-only access to specific content types) and implementing secure storage and rotation mechanisms. The machine is an untrusted entity, and its credentials must be treated with extreme caution.
Designing for Separation
The critical insight is that these two credential types necessitate separate authentication mechanisms and distinct security controls. A system that allows a delivery token to manage content, or a session cookie to be used for public content delivery, is fundamentally flawed.
When designing or evaluating a headless content API, ask these questions:
- Does the API distinguish between human administrative access and machine content delivery access?
- Are separate credential types used for each? (e.g., session cookies for admins, API keys/tokens for machines)
- Are the security controls appropriate for each threat model? (e.g., MFA and short-lived sessions for humans; scoped, securely stored, and easily rotatable tokens for machines)
- Can a delivery token perform administrative actions? It should not.
- Can a human session cookie be used to fetch public content without explicit authorization? It could, but it's generally cleaner to use a separate, more restricted mechanism for public access.
By enforcing this separation, developers can build more secure and robust content APIs. This approach ensures that the administrative interface is protected against human-related vulnerabilities while public content delivery remains efficient and secure, even if the delivery token is inadvertently exposed, its impact is limited.
