CWE-306: Missing Authentication for Critical Function
A sensitive function or endpoint performs its action without requiring authentication, so anyone who can reach it can use it.
Also known as: Missing authentication, Unprotected endpoint, No auth check
Risk
Typically high to critical. An admin action, data export, or internal API reachable without authentication gives an attacker the function's full power with no credential at all.
Definition
What it is
CWE-306 is the absence of an authentication check in front of a critical function. The endpoint exists, routes correctly, and does its job, but it never asks who is calling. This often happens with admin routes, internal APIs, cron or webhook handlers, and newly added endpoints that were never placed behind the auth middleware. Because reachability is the only requirement, anyone who finds the URL can run the action, read the data, or trigger the job.
Use-cases
How it shows up in real code
Unprotected admin endpoint
An admin action to delete users or change roles is routed but never checks authentication. Anyone who guesses the path can call it directly.
Internal API left open
A service-to-service endpoint assumes it is only reached internally and skips auth. When the host is exposed, external callers hit it with no credential.
Data export with no login
A reporting or export route returns a full data dump and was never placed behind authentication. The URL alone retrieves everyone's records.
New route misses middleware
A new endpoint is added outside the block that applies the auth middleware. It works in testing while sitting completely unauthenticated in production.
AI risk
Why AI-generated code has increased the exposure
- Assistants optimize for an endpoint that performs its action, and the action works without an auth check, so the check is simply never added.
- Training examples show the handler logic in isolation, rarely the middleware wiring, so the model emits the function without the guard in front of it.
- The model cannot see the app's auth middleware or route grouping, so it adds a new endpoint outside the protected block.
- When scaffolding admin, export, or internal endpoints, the assistant focuses on the behavior and treats access control as someone else's layer.
- Each generated endpoint is a new surface, and at volume some land without the authentication that the rest of the app assumes is present.
Vibe coding
How vibe coding amplifies the risk
- Vibe coding ships an endpoint that does its job in testing, hiding that it never asked who the caller is.
- The skipped review is where someone would ask is this route actually behind auth.
- A prototype admin or internal endpoint built without auth is promoted to production still wide open.
- The gap is invisible in local and demo testing because the developer is already logged in, or testing from inside, and never hits the endpoint as an anonymous outsider.
- As a vibe-coded app adds endpoints quickly, one eventually lands outside the auth wiring, and rapid growth means no review catches the open route.
Detection
How to find it
- Call sensitive endpoints with no credentials and confirm they reject the request instead of performing the action.
- Enumerate admin, export, internal, and webhook routes and check each is behind authentication.
- Review route definitions for endpoints added outside the block that applies the auth middleware.
- Diff newly added routes against the protected set to find any that were never placed behind a guard.
Remediation
How to fix it
- Require authentication on every sensitive endpoint, and prefer a default-deny setup where routes are protected unless explicitly made public.
- Apply auth through shared middleware or a route group so new endpoints inherit protection rather than opting in.
- Authenticate internal and service-to-service endpoints too, instead of trusting network position.
- Add an integration test that calls each critical route unauthenticated and asserts it is refused.
- Review new routes in code review specifically for whether they sit behind the authentication layer.
Frequently asked questions
- What is CWE-306 (missing authentication for critical function)?
- CWE-306 is when a sensitive function or endpoint performs its action without requiring authentication, so anyone who can reach the URL can run it. It often affects admin routes, internal APIs, and new endpoints that were never placed behind the auth middleware.
- How have AI assistants and vibe coding increased the risk?
- Assistants optimize for an endpoint that works, and the action runs without an auth check, so they emit the handler without the guard, often outside the middleware they cannot see. Vibe coding ships it because the developer tests while already logged in and never calls the route as an anonymous outsider, so the open endpoint reaches production.
- How do I fix missing authentication for critical function?
- Require authentication on every sensitive route with a default-deny posture, apply it through shared middleware so new endpoints inherit it, authenticate internal endpoints too, and test that each critical route refuses unauthenticated calls.
Related weaknesses
Catch CWE-306 before you ship
Tethlyn Audit scans your codebase and its git history for CWE-306 and the rest of the sensitive data exposure & privacy class, then ranks each finding by real exploitability and data sensitivity.