CWE-863 in APIs
- CWE ID
- CWE-863
- Category
- Authentication
- Severity
- HIGH
- Short Name
- Auth Errors
What is CWE-863
CWE-863, officially titled Incorrect Authorization, describes a fundamental security weakness where an application fails to properly verify that a user has the necessary permissions to perform a requested action or access specific resources. This weakness allows users to perform actions or access data beyond their intended privileges.
The weakness manifests when authorization checks are missing, improperly implemented, or bypassed. Unlike authentication (verifying who you are), authorization determines what you're allowed to do. CWE-863 occurs when this second critical step fails, granting users capabilities they shouldn't possess.
Common scenarios include: a regular user accessing admin functionality, viewing other users' data, modifying records they don't own, or escalating their privileges within the system. The impact ranges from information disclosure to complete system compromise, depending on what actions the attacker can perform.
CWE-863 in API Contexts
APIs are particularly vulnerable to CWE-863 because they're designed for programmatic access, often lacking the visual cues that might alert users to unauthorized access in traditional web applications. Several API-specific patterns make this weakness prevalent:
- Missing Authorization Checks: API endpoints assume the user is authenticated but fail to verify permissions for the requested operation.
- Broken Object Level Authorization (BOLA): APIs expose object identifiers (user IDs, document IDs, etc.) that allow attackers to manipulate references and access other users' data.
- Insecure Direct Object References (IDOR): Similar to BOLA, but specifically involves direct references to internal implementation objects that shouldn't be exposed.
- Privilege Escalation: Users can perform administrative actions by modifying request parameters or headers.
Consider a REST API for a banking application. An endpoint like GET /api/accounts/{accountId}/balance requires both authentication (proving you're a valid user) and authorization (proving you own or can access that specific account). CWE-863 occurs when the API only authenticates the request but never checks whether the authenticated user actually has permission to view the requested account's balance.
Another common scenario involves role-based access control failures. An API might properly check that a user is authenticated but fail to verify their role before allowing access to admin endpoints, enabling regular users to perform administrative operations.
Detection
Detecting CWE-863 requires systematic testing of authorization controls across all API endpoints. Manual testing involves: authenticating as different user types (regular user, admin, other users), attempting to access resources belonging to other users, modifying user identifiers in requests, and testing admin functionality with regular user credentials.
Automated scanning provides comprehensive coverage. middleBrick's black-box scanning approach tests the unauthenticated attack surface by: examining API endpoints without credentials, testing for broken authorization patterns, checking for IDOR vulnerabilities, and validating that privilege escalation is not possible.
middleBrick specifically tests for CWE-863 manifestations through its BOLA/IDOR and BFLA/Privilege Escalation checks. The scanner modifies request parameters to attempt accessing other users' data, tests admin endpoints with regular user context, and verifies that object-level authorization is properly enforced.
For OpenAPI specification analysis, middleBrick cross-references your API definitions with runtime findings. If your spec defines role-based access controls but the implementation doesn't enforce them, the scanner identifies this authorization gap. The tool also checks for excessive data exposure that might indicate authorization failures.
Key indicators of CWE-863 during testing include: successful access to resources belonging to other users, ability to perform administrative actions with regular user credentials, manipulation of object identifiers to access unauthorized data, and successful privilege escalation attempts.
Remediation
Fixing CWE-863 requires implementing robust authorization controls throughout your API. The foundation is a consistent authorization strategy applied uniformly across all endpoints.
Role-Based Access Control (RBAC) is the most common approach. Each user has roles (admin, user, manager, etc.), and each API operation requires specific roles. Implementation example in Node.js with Express:
const checkRole = (roles) => (req, res, next) => {
if (!req.user || !roles.includes(req.user.role)) {
return res.status(403).json({ error: 'Insufficient permissions' });
}
next();
};
app.get('/api/admin/stats', authenticate, checkRole(['admin']), (req, res) => {
// Only admins can access this endpoint
res.json(getAdminStats());
Object-Level Authorization verifies access to specific resources. For the banking example:
async function getAccountBalance(req, res) {
const accountId = req.params.accountId;
const account = await Account.findById(accountId);
// Verify user owns this account or has explicit permission
if (!account || account.userId !== req.user.id) {
return res.status(403).json({ error: 'Access denied' });
}
res.json({ balance: account.balance });
}Attribute-Based Access Control (ABAC) provides more granular control based on user attributes, resource attributes, and environmental conditions:
function canAccessDocument(user, document) {
// Check if user is owner, has explicit share permission, or is in allowed group
return document.ownerId === user.id ||
document.sharedWith.includes(user.id) ||
document.sharedGroup.some(g => user.groups.includes(g));
}
app.get('/api/documents/:id', authenticate, async (req, res) => {
const doc = await Document.findById(req.params.id);
if (!canAccessDocument(req.user, doc)) {
return res.status(403).json({ error: 'Access denied' });
}
res.json(doc);
Best Practices for Authorization:
- Never rely solely on client-side controls or hidden fields
- Implement authorization checks at the API gateway or middleware level for consistency
- Use principle of least privilege - grant only necessary permissions
- Log authorization failures for security monitoring
- Test authorization controls with each code change
- Validate that authorization checks cover all code paths, including error conditions
middleBrick's scanning helps verify your remediation efforts by testing whether authorization controls are properly implemented and whether CWE-863 vulnerabilities remain exploitable.