IDOR
Description: Insecure Direct Object References (IDOR) occur when an application exposes a reference to an internal object, such as a file, database record, or URL, without proper access control. This allows attackers to manipulate the reference to gain unauthorized access to data or functions.
Example with Scenario:
Imagine an e-commerce website where users can view their order details by accessing a URL like http://example.com/order?id=1234. If the application does not verify whether the authenticated user is authorized to view order 1234, an attacker could change the id parameter to access other users' orders.
Payloads and Test Cases:
Basic IDOR to Access Unauthorized Data:
URL:
http://example.com/order?id=1234Payload: Change
idto another order number, e.g.,http://example.com/order?id=1235Test Case: Verify if the application allows access to the order details for
id=1235without proper authorization checks.
IDOR in API Endpoints:
API Request:
GET /api/user/1234/profilePayload: Change user ID to another user's ID, e.g.,
GET /api/user/1235/profileTest Case: Check if the API returns the profile details for user
1235without authorization.
IDOR in File Download:
URL:
http://example.com/download?file=report1234.pdfPayload: Change
fileparameter to another file name, e.g.,http://example.com/download?file=report1235.pdfTest Case: Ensure that the application prevents unauthorized file downloads by checking proper permissions.
IDOR in User Management:
URL:
http://example.com/admin/user/edit?id=1234Payload: Change
idto another user's ID, e.g.,http://example.com/admin/user/edit?id=1235Test Case: Verify if non-admin users can edit or view details of other users without proper authorization.
IDOR in Account Settings:
URL:
http://example.com/account/settings?id=1234Payload: Change
idto another account ID, e.g.,http://example.com/account/settings?id=1235Test Case: Check if users can access or modify other users' account settings.
IDOR in Deletion Functionality:
URL:
http://example.com/delete?file=1234Payload: Change
fileparameter to another file ID, e.g.,http://example.com/delete?file=1235Test Case: Ensure that the application checks for proper authorization before allowing deletion of any resource.
Mitigation:
Implement Proper Access Controls:
Ensure that every access to sensitive data or functionality checks if the user has the appropriate permissions.
// Example in Java User user = getCurrentUser(); Order order = orderService.getOrderById(orderId); if (!order.getUser().equals(user)) { throw new UnauthorizedAccessException(); }Use Indirect References:
Instead of using direct references like database IDs, use indirect references that are mapped to internal objects securely.
// Map indirect reference to internal ID String orderRef = "ORD-1234-ABC"; Order order = orderService.getOrderByRef(orderRef);Input Validation and Sanitization:
Validate and sanitize user inputs to ensure they do not contain unauthorized references.
if (!isValidId(orderId)) { throw new InvalidInputException(); }Log and Monitor Access:
Implement logging and monitoring to detect and respond to unauthorized access attempts.
// Log access attempts logger.info("User {} accessed order {}", user.getId(), orderId);Use Frameworks with Built-in Security:
Use security frameworks that provide built-in mechanisms for access control and authorization checks.
Perform Regular Security Audits:
Regularly review and audit your codebase for potential IDOR vulnerabilities and fix them promptly.
Last updated