CWE-306 in APIs
What is CWE-306?
CWE-306 refers to Missing Authentication for Critical Function. This weakness occurs when a critical function or operation within a system lacks proper authentication controls, allowing unauthorized users to access sensitive functionality without proving their identity or authorization.
The weakness manifests when developers fail to protect sensitive operations with authentication mechanisms. This might include administrative functions, data modification operations, or any endpoint that should only be accessible to authenticated users. Attackers can exploit this by directly accessing these endpoints without credentials, bypassing security entirely.
CWE-306 is particularly dangerous because it provides an easy entry point for attackers. Unlike vulnerabilities that require sophisticated exploitation techniques, missing authentication is often as simple as knowing the endpoint URL. This weakness frequently appears in development environments that get accidentally deployed to production, in hastily implemented features, or when authentication middleware fails to cover all critical paths.
CWE-306 in API Contexts
In API environments, CWE-306 takes on specific characteristics due to the stateless nature of HTTP and the diverse authentication patterns used in modern web services. APIs often expose multiple endpoints that handle different operations, and authentication gaps can occur at any level of the API surface.
Common API manifestations include:
- Missing auth on POST/PUT/DELETE endpoints: While GET endpoints might be intentionally public, write operations should almost always require authentication
- Admin function exposure: Endpoints that modify user roles, delete data, or configure system settings left unprotected
- Database operation endpoints: Direct database manipulation endpoints (like MongoDB's
/api/db/query) exposed without authentication - Health check endpoints with sensitive data: Health endpoints that return internal system information, database credentials, or configuration details
- API key generation endpoints: Endpoints that create new API keys or tokens without requiring existing credentials
RESTful APIs are particularly vulnerable because each endpoint represents a distinct function. A single missing authentication check on one endpoint can compromise the entire system. GraphQL APIs face similar risks, where resolvers might miss authentication checks for specific fields or mutations.
Real-world examples include the Capital One breach (2019) where misconfigured WAF rules and missing authentication on certain endpoints contributed to data exposure, and numerous cases where admin panels were accidentally left accessible on the public internet.
Detection
Detecting CWE-306 requires systematic testing of authentication controls across all API endpoints. Manual testing involves attempting to access each endpoint with and without authentication tokens, but this becomes impractical for large APIs.
Automated detection approaches include:
- Black-box scanning: Tools that systematically test each endpoint without authentication to identify those that should be protected but aren't
- Specification analysis: Examining OpenAPI/Swagger specifications to identify endpoints marked as requiring authentication but lacking enforcement
- Code analysis: Static analysis to find authentication middleware usage patterns and identify endpoints that bypass these controls
middleBrick provides comprehensive CWE-306 detection through its black-box scanning approach. The scanner automatically tests each endpoint in your API without credentials, identifying critical functions that respond without authentication. For OpenAPI specification analysis, middleBrick cross-references your API definition with runtime findings, flagging endpoints that should require authentication according to your spec but don't enforce it in practice.
The scanner tests for common critical function patterns including:
POST /admin/users # User management without auth
DELETE /api/data/* # Data deletion without auth
PUT /api/settings/* # Configuration changes without auth
POST /api/generate-token # Token creation without auth
middleBrick's LLM/AI security module also detects unauthenticated endpoints in AI services, identifying cases where model inference endpoints or prompt engineering interfaces lack proper authentication controls.
Remediation
Remediating CWE-306 requires implementing consistent authentication controls across your entire API surface. The approach varies by framework and authentication strategy, but the principles remain consistent.
Framework-level authentication
Most modern frameworks provide middleware or decorators for authentication. Apply these consistently: