Summary
A flaw in the Tandoor Recipes /api/food/{id}/shopping/ endpoint allows unvalidated amount and unit fields from the request body to be passed directly into database object creation.
This can cause unhandled server errors with malformed input and, more critically, allows a unit identifier from another tenant "Space" to be associated with a shopping list entry, leaking cross-tenant foreign key references.
Affected context
The issue occurs in Tandoor Recipes instances that expose the /api/food/{id}/shopping/ POST endpoint and rely on multi-tenant separation using "Spaces."
In affected versions, this specific endpoint bypasses the usual serializer-based validation and sanitization used elsewhere for ShoppingListEntry creation, instead reading amount and unit directly from request.data.
In environments where multiple tenants share the same deployment, this can allow references to units belonging to a different Space to be attached to a user's shopping list, and malformed amounts can crash the endpoint.
Exploit preconditions
- Attack surface: HTTP API endpoint
POST /api/food/{id}/shopping/. - Required access: Ability to call the API for a valid food ID; typically authenticated as any user allowed to add items to a shopping list in a given Space.
- Trigger point (invalid amount): Supplying a non-numeric string or otherwise invalid value in the
amountfield causes an unhandled exception when the ORM tries to persist it. - Trigger point (cross-space unit): Supplying a
unitidentifier that belongs to a different Space than the caller's current Space leads to a cross-tenant association of the foreign key. - Why exploitation is possible: The endpoint bypasses the
ShoppingListEntrySerializerused elsewhere, so there is no type validation, range checking, or tenant-scope enforcement on these fields before object creation.
Why this happens
The underlying issue is a combination of missing object-level access control and inconsistent input validation for a single API endpoint.
Instead of consistently using the ShoppingListEntrySerializer, the endpoint directly reads amount and unit from request.data and passes them to ShoppingListEntry.objects.create() without verifying:
- That
amountadheres to the expected numeric type or domain. - That the
unitforeign key belongs to the same Space as the requesting user or food item.
This matches CWE-639 (Authorization Bypass Through User-Controlled Key) because the client can select arbitrary foreign key IDs and have the system accept them, crossing tenant boundaries.
It also matches CWE-1284 (Improper Validation of Specified Quantity in Input) due to lack of robust validation for amount, resulting in unhandled exceptions and server errors.
Potential impact
- Cross-tenant exposure of unit relationships, as shopping list entries in one Space can be linked to units from another.
- Leakage of internal identifiers (IDs) across tenant boundaries, which can assist in further reconnaissance.
- Inconsistent or corrupted domain data where entries point to logically invalid or unauthorized units.
- Application instability and HTTP 500 errors when malformed
amountvalues are submitted repeatedly. - Potential denial of service at the endpoint level if automated or malicious clients send large volumes of invalid
amountvalues.
General mitigation guidance
Mitigation generally centers on enforcing consistent validation and strict tenant-aware access control for all object creation paths.
Useful patterns include:
- Centralize validation: Ensure all endpoints that create
ShoppingListEntryobjects go through a common serializer or validation layer that enforces type checks, range limits, and required fields foramountandunit. - Enforce tenant scoping: When resolving foreign keys such as
unit, always filter by the current Space or tenant context, rejecting IDs that cannot be found within that scope. - Fail safely on invalid quantities: Treat unparseable or out-of-range
amountvalues as validation errors and return structured client errors (e.g., 4xx) instead of allowing unhandled exceptions. - Apply least privilege to identifiers: Never trust client-supplied IDs alone; always re-derive accessible objects from the authenticated user context and tenant membership.
- Consistency across endpoints: Periodically audit API endpoints for bypasses of shared serializers or validation helpers, especially when new routes are added.
How teams detect issues like this
Organizations can detect this and similar issues through a mix of code-level and operational measures:
- Static analysis and linters: Flag direct uses of
request.dataor request payloads passed into ORMcreate()calls without intermediate validation or serializer logic, especially for multi-tenant models. - Code review practices: During review, verify that every endpoint creating or updating
ShoppingListEntry(or analogous entities) consistently uses serializers and enforces tenant scoping on foreign keys. - Access control checks: Establish patterns where any lookup by ID must also constrain by tenant/Space and have reviewers confirm this in pull requests.
- Runtime monitoring: Monitor logs and metrics for repeated HTTP 500 errors from
POST /api/food/{id}/shopping/or similar endpoints, correlating them with invalidamountpayloads or suspiciousunitIDs. - Automated tests: Add multi-tenant unit tests that attempt to use objects from another Space and verify that the system rejects these operations.

