PUT checked the project space, DELETE didn’t: cross-tenant deletes in the CommCare HQ API
Several CommCare HQ REST API delete handlers looked up objects by ID without checking that they belonged to the project space named in the URL. A user with the relevant API permission in one project space could, given an object ID from another project space, retire a mobile worker there or delete its lookup tables and rows.
Published on medium.com
CommCare HQ is the server side of CommCare, Dimagi’s platform for building offline-first mobile apps for frontline workers. One instance hosts many project spaces, and the project space is the tenant boundary.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
CommCare HQ is the server side of CommCare, Dimagi's platform for building offline-first mobile apps for frontline workers. A single instance hosts many project spaces, and the project space is the tenant boundary. The code calls a project space a domain. Mobile workers are the field users of a project's apps, and lookup tables hold reference data that a project's apps and forms read.
The REST API is built on django-tastypie. Each request names a project space in its URL, /a/<domain>/api/.... Authentication checks that the caller has the required permission in that project space. It says nothing about the object the request points at; that second check is left to each resource's own methods.
Several delete handlers looked objects up by ID without checking that they belonged to the project space in the URL. A user with the relevant API permission in one project space could, given an object's ID, delete mobile workers and lookup tables in another. The read and update handlers on the same resources did check ownership.
Setup
The work was source review plus a local harness, not a live instance. The researcher did not run a full CommCare HQ.
- The vulnerable code was read at commit
2ef6f1cfrom 2026-08-13. - The harness drives django-tastypie 0.15.1, the version CommCare HQ pins, through its real request handling.
- Into it the researcher copied CommCare HQ's
obj_deletemethod from commit2ef6f1c, andobj_updateup to its project-space check, with the class names swapped for in-memory stand-ins. - The harness seeded one synthetic mobile worker in
domain_Y, and caller A made the request as a user ofdomain_X. - Stand-ins replaced the request object, the database, authentication, CommCare HQ's base-resource dispatch check (which looks only at the caller's own project space), and
retire()(a reduced copy that marks the user deleted). - The data was synthetic.
The precondition for the real attack is a caller who holds the relevant API permission in a project space they control, plus the ID of an object in another project space.
Finding it
The researcher compared the handlers on each resource. On the mobile-worker resource, the update handler loads the user and asserts it belongs to the URL's project space, while the delete handler loads the user by ID alone and retires it:
# corehq/apps/api/resources/v0_5.py, commit 2ef6f1c, lines 351-353 and 375-380 (CommCareUserResource)
def obj_update(self, bundle, **kwargs):
bundle.obj = CommCareUser.get(kwargs['pk'])
assert bundle.obj.domain == kwargs['domain']
...
def obj_delete(self, bundle, **kwargs):
user = CommCareUser.get(kwargs['pk'])
if user:
user.retire(bundle.request.domain, deleted_by=bundle.request.couch_user,
deleted_via=USER_CHANGE_VIA_API)
return ImmediateHttpResponse(response=http.HttpAccepted())
The lookup-table resource has the same shape. Like its read handler, its update handler raises NotFound when the table's project space doesn't match the URL's. Its delete handler filters by ID only:
# corehq/apps/fixtures/resources/v0_1.py, commit 2ef6f1c, lines 176-183 and 208-214 (LookupTableResource)
def obj_delete(self, bundle, **kwargs):
query = LookupTable.objects.filter(id=kwargs['pk'])
if not query.exists():
raise NotFound('Lookup table not found')
query.delete()
clear_fixture_cache(kwargs['domain'], [kwargs['pk']])
return ImmediateHttpResponse(response=HttpAccepted())
...
try:
bundle.obj = LookupTable.objects.get(id=kwargs['pk'])
except LookupTable.DoesNotExist:
raise NotFound('Lookup table not found')
if bundle.obj.domain != kwargs['domain']:
raise NotFound('Lookup table not found')
And the lookup-table row resource:
# corehq/apps/fixtures/resources/v0_1.py, commit 2ef6f1c, lines 359-367 (LookupTableItemResource)
def obj_delete(self, bundle, **kwargs):
try:
row = LookupTableRow.objects.get(id=kwargs['pk'])
except LookupTableRow.DoesNotExist:
raise NotFound('Lookup table item not found')
table_id = row.table_id
row.delete()
clear_fixture_cache(row.domain, [table_id])
return ImmediateHttpResponse(response=HttpAccepted())
The pattern was clear: the URL's project space authenticated the caller, the read and update handlers checked that the object belonged to it, and the delete handlers did not. The advisory lists the affected routes for users, lookup tables and rows across the v0.5, v0.6, v1 and v2 API paths.
Exploitation
Step 1: identify the request shape
A caller with permission to edit mobile workers through the API in project space X sends a delete naming project space X in the URL and the ID of a mobile worker that lives in project space Y:
DELETE /a/X/api/v0.5/user/<id>/
The request passes authentication in X, because authentication only checks the caller's permission in the project space named in the URL. The delete handler then loads the user by <id> alone and retires it, so the user in Y is retired.
Step 2: reproduce with the harness
The harness seeded one synthetic mobile worker in domain_Y and had caller A, a user of domain_X, issue the delete. These are the delete lines of the harness's output, as recorded in the run notes (the harness's separator lines removed):
STEP 2 -- THE FINDING: A issues DELETE (obj_delete, the unguarded sink)
DELETE dispatch returned HTTP 204 (HttpNoContent)
target user domain at delete time was: domain_Y (caller's domain: domain_X)
target user base_doc AFTER delete: CouchUser-Deleted
retire() was invoked with retired_by_domain=[('domain_X', 'stub-deletion-id')]
The delete from domain_X went through and marked the domain_Y user deleted. It returned 204, not the 202 in the handler, because tastypie returns 204 after a delete. A second harness ran the same delete for a lookup table and a lookup-table row, and both were removed.
Step 3: the control that did not work
The harness also tried the update as a control. On review, that step never reached CommCare HQ's code: the stand-in request object lacks a method tastypie calls on every PUT, so the PUT failed with a 500 before obj_update ran. It does not show the update check working. The check is in the source shown above, and the advisory describes only the deletes as affected.
Limits of the reproduction
The harness ran tastypie's real request path, but with stand-ins for the request object, the database, authentication, CommCare HQ's base-resource dispatch check and retire(). No HTTP requests were sent to a running CommCare HQ. The impact on a live instance is as the advisory states it.
Root cause
Each resource had read, update and delete handlers, and only two of the three checked ownership. Read and update compared the object's project space with the URL's; delete did not, on three resources. The delete handlers looked the object up by primary key alone (CommCareUser.get(kwargs['pk']), LookupTable.objects.filter(id=kwargs['pk']), LookupTableRow.objects.get(id=kwargs['pk'])) and acted on whatever came back.
Authentication answered a different question from the one that mattered. It confirmed the caller's permission in the project space named in the URL, not that the object lived there. The harness used a stand-in for CommCare HQ's base-resource dispatch check, which looks only at the caller's own project space. The ownership check was left to each resource's own methods, and the delete methods omitted it.
Impact
Per the advisory, a user with the relevant API permission in a project space they control could, given an object ID from another project space, retire a mobile worker there or delete its lookup tables and rows. A delete from another tenant takes away a project's field user or the data its forms depend on.
The IDs are not sequential and, per the advisory, generally are not exposed across project spaces, which raises the bar for finding a target ID. The advisory rates the issue Moderate 6.8 (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H), CWE-639 and CWE-863.
Fix
The issue was fixed in commit 3570c0ff9c7, through PR #38029, merged on 2026-08-14. Each delete now looks the object up within the URL's project space:
# corehq/apps/api/resources/v0_5.py, commit 3570c0ff9c7
return bundle
def obj_delete(self, bundle, **kwargs):
- user = CommCareUser.get(kwargs['pk'])
+ user = CommCareUser.get_by_user_id(kwargs['pk'], kwargs['domain'])
if user:
user.retire(bundle.request.domain, deleted_by=bundle.request.couch_user,
deleted_via=USER_CHANGE_VIA_API)
+ else:
+ raise NotFound(f"Could not find user for id: {kwargs['pk']}")
return ImmediateHttpResponse(response=http.HttpAccepted())
def dehydrate_primary_location(self, bundle):
# corehq/apps/fixtures/resources/v0_1.py, commit 3570c0ff9c7 ("..." separates the two hunks)
return list(LookupTable.objects.by_domain(domain))
def obj_delete(self, bundle, **kwargs):
- query = LookupTable.objects.filter(id=kwargs['pk'])
- if not query.exists():
+ try:
+ query = LookupTable.objects.get(id=kwargs['pk'], domain=kwargs['domain'])
+ except LookupTable.DoesNotExist:
raise NotFound('Lookup table not found')
query.delete()
...
def obj_delete(self, bundle, **kwargs):
try:
- row = LookupTableRow.objects.get(id=kwargs['pk'])
+ row = LookupTableRow.objects.get(id=kwargs['pk'], domain=kwargs['domain'])
except LookupTableRow.DoesNotExist:
raise NotFound('Lookup table item not found')
table_id = row.table_id
The fix keeps the same handlers and adds the project space to the lookup. Per the advisory, a foreign object ID now returns 404 instead of being deleted. The advisory asks self-hosted instances to deploy 3570c0ff9c7 or later. For anyone who cannot upgrade right away, it suggests blocking the /a/<domain>/api/ paths at the proxy, since per-user permission changes do not help when the attacker controls their own project space.
Variants to test
- Compare every handler on a resource, not just the one you are testing. For each resource, list the read, update and delete methods and check whether each one constrains the lookup by the tenant in the URL. A positive result is a delete (or any write) that resolves an object by primary key alone while its sibling methods filter by tenant.
- Send a delete with a foreign ID and watch the status code. If the object is removed and the response is a success rather than a 404, the ownership check is missing. In this case the handler returned 202 and tastypie turned it into a 204.
- Check the base-resource dispatch check separately from the handler. Authentication and any framework-level check may only validate the caller's permission in the URL's project space. A positive result is a request that passes those checks and still reaches an object in another tenant.
- Try the same pattern on nested resources. Lookup-table rows are children of lookup tables; child resources often repeat the parent's lookup mistake. A positive result is a row deleted through a URL naming a different project space.
- Look for ID exposure across tenants. The severity here depends on whether IDs leak between project spaces. A positive result is any API response, export or shared link that reveals an object ID belonging to another tenant.
Disclosure timeline
- 2026-08-12: found during source review.
- 2026-08-13: reproduced with the harness above.
- 2026-08-14: reported by email to Dimagi's security team; the fix (PR #38029) was merged the same day.
- 2026-08-16: Dimagi acknowledged the report.
- 2026-08-20: advisory GHSA-hq38-78vf-f4cj published.
If you self-host CommCare HQ, make sure you have deployed 3570c0ff9c7 or later.
What happened, in plain words
CommCare HQ is a web service that runs in the background for a family of mobile apps. Organisations use it to build apps for frontline workers: health visitors, survey takers, delivery staff. The apps are built to keep working when the phone has no signal, and to sync back to the server later.
One CommCare HQ server hosts many organisations at once. Each organisation gets its own separate area on that server, called a project space. In the code, a project space is called a domain. Think of one large office building with many locked offices: the building is the server, each office is a project space, and the walls between offices are what stop one organisation from touching another's things. Security people call that wall a tenant boundary; a tenant is one customer sharing a system with others.
Inside a project space there are two kinds of things that matter here:
- Mobile workers: the field users of a project's apps. These are the people who log into the phone app and fill in forms.
- Lookup tables: reference data that a project's apps and forms read, for example a list of villages or clinic codes. A lookup table is made of rows, one per entry.
CommCare HQ offers a REST API. An API is a way for one computer program to talk to another over the web, using ordinary web addresses and requests. You can think of it as a service counter: you hand over a request in a fixed format, and you get back an answer. REST is just a common style for such counters, where each thing has its own address and you use standard verbs: GET to read something, PUT to update it, DELETE to remove it.
The API is built on a toolkit called django-tastypie, which is a library that helps a Python web framework (Django) expose database records through a REST API. Tastypie gives each kind of record a set of handlers: small functions that run when someone reads, updates or deletes that record.
The bug: several of the delete handlers looked up the record purely by its ID (a unique identifier, like a customer number) and never checked that the record actually belonged to the project space named in the web address. The read and update handlers on the same records did check. So a user who had permission to use the API in their own project space could, if they knew the ID of a record in someone else's project space, delete it there.
This kind of mistake has a name: broken object level authorization, or IDOR (Insecure Direct Object Reference). It means the program checks who you are but not whether the specific thing you are pointing at is yours. The advisory also labels it CWE-639 (authorization bypass through a user-controlled key) and CWE-863 (incorrect authorization).
The advisory rates it Moderate 6.8. That number comes from CVSS, a standard scoring system for the severity of security flaws, where 0 is harmless and 10 is catastrophic. The vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H is the recipe behind the score; each part is explained in the glossary.
Why you should care
If you run a project on CommCare HQ, a delete from another organisation's project space takes away something your project depends on: a field user, or the reference data your forms read. That is the whole point of a tenant boundary, and here it had a gap.
The setup
Every API request names a project space in its web address, in this shape:
/a/<domain>/api/...
Here <domain> is the project space name. The rest of the address says which kind of record and which ID you mean.
When a request arrives, the system performs authentication: it works out who is calling and whether that caller has the required permission in the project space named in the address. Authentication is the "who are you and are you allowed in this office" check.
But that check says nothing about the record the request points at. It confirms you may use the API in project space X; it does not confirm that the record with ID 123 actually lives in X. That second check, called authorization at the object level, was left to each resource's own handler methods. And on the delete handlers, it was missing.
The bug
Mobile workers
The mobile-worker resource, at commit 2ef6f1c from 2026-08-13 (a commit is a saved snapshot of the source code, identified by a short hash):
# corehq/apps/api/resources/v0_5.py, commit 2ef6f1c, lines 351-353 and 375-380 (CommCareUserResource)
def obj_update(self, bundle, **kwargs):
bundle.obj = CommCareUser.get(kwargs['pk'])
assert bundle.obj.domain == kwargs['domain']
...
def obj_delete(self, bundle, **kwargs):
user = CommCareUser.get(kwargs['pk'])
if user:
user.retire(bundle.request.domain, deleted_by=bundle.request.couch_user,
deleted_via=USER_CHANGE_VIA_API)
return ImmediateHttpResponse(response=http.HttpAccepted())
Line by line:
def obj_update(...)starts the handler that runs when someone updates a mobile worker.bundleis tastypie's wrapper around the request and the record;kwargsholds values taken from the web address, includingpk(the record's ID) anddomain(the project space).bundle.obj = CommCareUser.get(kwargs['pk'])loads the mobile worker by ID alone.assert bundle.obj.domain == kwargs['domain']is the ownership check: it stops with an error unless the worker's project space matches the one in the address. This is the check that should have been in delete too....marks skipped lines.def obj_delete(...)starts the delete handler.user = CommCareUser.get(kwargs['pk'])loads the mobile worker by ID alone. No comparison with the address's project space.if user:runs the next lines only if a worker was found.user.retire(...)marks the worker as retired (effectively deleted). It records which project space the request came from (bundle.request.domain), who did it, and that it happened through the API.return ImmediateHttpResponse(response=http.HttpAccepted())sends back an immediate "accepted" reply, HTTP status 202.
So the update handler checked ownership and the delete handler did not.
Lookup tables
The lookup-table resource has the same shape. Like its read handler, its update handler raises NotFound when the table's project space doesn't match the address's. Its delete handler filters by ID only:
# corehq/apps/fixtures/resources/v0_1.py, commit 2ef6f1c, lines 176-183 and 208-214 (LookupTableResource)
def obj_delete(self, bundle, **kwargs):
query = LookupTable.objects.filter(id=kwargs['pk'])
if not query.exists():
raise NotFound('Lookup table not found')
query.delete()
clear_fixture_cache(kwargs['domain'], [kwargs['pk']])
return ImmediateHttpResponse(response=HttpAccepted())
...
try:
bundle.obj = LookupTable.objects.get(id=kwargs['pk'])
except LookupTable.DoesNotExist:
raise NotFound('Lookup table not found')
if bundle.obj.domain != kwargs['domain']:
raise NotFound('Lookup table not found')
Line by line:
query = LookupTable.objects.filter(id=kwargs['pk'])builds a database query for the table with that ID.filteris a database lookup;objectsis the standard Django way to query a table of records.if not query.exists():checks whether nothing matched.raise NotFound('Lookup table not found')returns a "not found" error (HTTP 404) if so.query.delete()deletes whatever matched. Since the query only used the ID, that could be a table in any project space.clear_fixture_cache(kwargs['domain'], [kwargs['pk']])clears the cached copy of that table for the project space in the address. A cache is a fast temporary store of data kept to avoid slow lookups; clearing it makes sure the app sees the deletion.return ImmediateHttpResponse(response=HttpAccepted())sends back the "accepted" reply.- The second block is the update handler: it loads the table by ID, raises
NotFoundif it does not exist, and thenif bundle.obj.domain != kwargs['domain']:raisesNotFoundagain if the table's project space differs from the address's. That is the ownership check, present in update and absent in delete.
Lookup-table rows
And the lookup-table row resource:
# corehq/apps/fixtures/resources/v0_1.py, commit 2ef6f1c, lines 359-367 (LookupTableItemResource)
def obj_delete(self, bundle, **kwargs):
try:
row = LookupTableRow.objects.get(id=kwargs['pk'])
except LookupTableRow.DoesNotExist:
raise NotFound('Lookup table item not found')
table_id = row.table_id
row.delete()
clear_fixture_cache(row.domain, [table_id])
return ImmediateHttpResponse(response=HttpAccepted())
Line by line:
row = LookupTableRow.objects.get(id=kwargs['pk'])fetches the row by ID alone.except LookupTableRow.DoesNotExist:catches the case where no such row exists.raise NotFound('Lookup table item not found')returns a 404 in that case.table_id = row.table_idremembers which table the row belongs to, so the cache can be cleared for the right table.row.delete()deletes the row.clear_fixture_cache(row.domain, [table_id])clears the cached copy of that table for the row's own project space.
Again, no comparison between the row's project space and the address's.
The pattern was clear: the address's project space authenticated the caller, the read and update handlers checked that the record belonged to it, and the delete handlers did not. The advisory lists the affected routes for users, lookup tables and rows across the v0.5, v0.6, v1 and v2 API paths.
Exploitation
Step 1: identify the request shape
A caller with permission to edit mobile workers through the API in project space X sends a delete naming project space X in the address and the ID of a mobile worker that lives in project space Y:
DELETE /a/X/api/v0.5/user/<id>/
Line by line:
DELETEis the HTTP verb meaning "remove this thing"./a/X/api/v0.5/user/<id>/is the path: project spaceX, the API, version 0.5 of the API, the user resource, and the ID of the worker to remove.
The request passes authentication in X, because authentication only checks the caller's permission in the project space named in the address. The delete handler then loads the user by <id> alone and retires it, so the user in Y is retired. The attacker does not need access to Y, only the ID of something in Y, though the advisory says such IDs generally are not exposed across project spaces.
Step 2: reproduce with the harness
The researcher did not run a full CommCare HQ. Instead they built a harness: a small test program that drives the real library through its real request handling, with fake pieces standing in for the parts that would need a full server. A stand-in (or stub) is a simplified replacement that behaves enough like the real thing for the test.
The harness seeded one synthetic mobile worker in domain_Y and had caller A, a user of domain_X, issue the delete. These are the delete lines of the harness's output, as recorded in the run notes (the harness's separator lines removed):
STEP 2 -- THE FINDING: A issues DELETE (obj_delete, the unguarded sink)
DELETE dispatch returned HTTP 204 (HttpNoContent)
target user domain at delete time was: domain_Y (caller's domain: domain_X)
target user base_doc AFTER delete: CouchUser-Deleted
retire() was invoked with retired_by_domain=[('domain_X', 'stub-deletion-id')]
Line by line:
STEP 2 -- THE FINDING: A issues DELETE (obj_delete, the unguarded sink)says which step of the test this is: caller A sends the delete, and it reaches the delete handler, which is the unguarded sink (the place where the missing check lets the request through).DELETE dispatch returned HTTP 204 (HttpNoContent)says the request was accepted and the reply was status 204, meaning "no content", the standard success reply to a delete.target user domain at delete time was: domain_Y (caller's domain: domain_X)shows the worker being deleted belonged todomain_Ywhile the caller belonged todomain_X.target user base_doc AFTER delete: CouchUser-Deletedshows the worker's stored record is now marked deleted.base_docis the underlying stored document.retire() was invoked with retired_by_domain=[('domain_X', 'stub-deletion-id')]shows the retire function ran and recordeddomain_Xas the project space that asked for it.
The delete from domain_X went through and marked the domain_Y user deleted. It returned 204, not the 202 in the handler, because tastypie returns 204 after a delete. A second harness ran the same delete for a lookup table and a lookup-table row, and both were removed.
Step 3: the control that did not work
A control is a comparison test: you run the same kind of action on a case that should be blocked, to show the difference. The harness also tried the update as a control. On review, that step never reached CommCare HQ's code: the stand-in request object lacks a method tastypie calls on every PUT, so the PUT failed with a 500 before obj_update ran. It does not show the update check working. The check is in the source shown above, and the advisory describes only the deletes as affected.
Limits of the reproduction
The harness ran tastypie's real request path, but with stand-ins for the request object, the database, authentication, CommCare HQ's base-resource dispatch check and retire(). No HTTP requests were sent to a running CommCare HQ. The impact on a live instance is as the advisory states it.
Root cause
Each resource had read, update and delete handlers, and only two of the three checked ownership. Read and update compared the record's project space with the address's; delete did not, on three resources. The delete handlers looked the record up by primary key alone (the unique ID of a database record) and acted on whatever came back.
Authentication answered a different question from the one that mattered. It confirmed the caller's permission in the project space named in the address, not that the record lived there. The harness used a stand-in for CommCare HQ's base-resource dispatch check, which looks only at the caller's own project space. The ownership check was left to each resource's own methods, and the delete methods omitted it.
Impact
Per the advisory, a user with the relevant API permission in a project space they control could, given a record ID from another project space, retire a mobile worker there or delete its lookup tables and rows. A delete from another tenant takes away a project's field user or the data its forms depend on.
The IDs are not sequential and, per the advisory, generally are not exposed across project spaces, which raises the bar for finding a target ID. The advisory rates the issue Moderate 6.8 (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H), CWE-639 and CWE-863.
Fix
The issue was fixed in commit 3570c0ff9c7, through PR #38029, merged on 2026-08-14. A PR (pull request) is a proposed change to the source code that gets reviewed and then merged into the main code. Each delete now looks the record up within the address's project space:
# corehq/apps/api/resources/v0_5.py, commit 3570c0ff9c7
return bundle
def obj_delete(self, bundle, **kwargs):
- user = CommCareUser.get(kwargs['pk'])
+ user = CommCareUser.get_by_user_id(kwargs['pk'], kwargs['domain'])
if user:
user.retire(bundle.request.domain, deleted_by=bundle.request.couch_user,
deleted_via=USER_CHANGE_VIA_API)
+ else:
+ raise NotFound(f"Could not find user for id: {kwargs['pk']}")
return ImmediateHttpResponse(response=http.HttpAccepted())
def dehydrate_primary_location(self, bundle):
Line by line:
- Lines starting with
-are the old code being removed; lines starting with+are the new code being added. Unmarked lines are unchanged context. - user = CommCareUser.get(kwargs['pk'])is the old lookup by ID alone.+ user = CommCareUser.get_by_user_id(kwargs['pk'], kwargs['domain'])is the new lookup, which takes both the ID and the project space, so it only finds a worker inside the address's project space.+ else:and+ raise NotFound(f"Could not find user for id: {kwargs['pk']}")add a "not found" error when no worker matches, so a foreign ID gets a 404 instead of a deletion.
# corehq/apps/fixtures/resources/v0_1.py, commit 3570c0ff9c7 ("..." separates the two hunks)
return list(LookupTable.objects.by_domain(domain))
def obj_delete(self, bundle, **kwargs):
- query = LookupTable.objects.filter(id=kwargs['pk'])
- if not query.exists():
+ try:
+ query = LookupTable.objects.get(id=kwargs['pk'], domain=kwargs['domain'])
+ except LookupTable.DoesNotExist:
raise NotFound('Lookup table not found')
query.delete()
...
def obj_delete(self, bundle, **kwargs):
try:
- row = LookupTableRow.objects.get(id=kwargs['pk'])
+ row = LookupTableRow.objects.get(id=kwargs['pk'], domain=kwargs['domain'])
except LookupTableRow.DoesNotExist:
raise NotFound('Lookup table item not found')
table_id = row.table_id
Line by line:
- query = LookupTable.objects.filter(id=kwargs['pk'])and- if not query.exists():are the old lookup by ID alone and its existence check.+ try:and+ query = LookupTable.objects.get(id=kwargs['pk'], domain=kwargs['domain'])replace them with a lookup that requires both the ID and the project space.except LookupTable.DoesNotExist:andraise NotFound('Lookup table not found')keep the 404 for a table that does not exist in that project space.- The second hunk does the same for rows:
- row = LookupTableRow.objects.get(id=kwargs['pk'])becomes+ row = LookupTableRow.objects.get(id=kwargs['pk'], domain=kwargs['domain']).
The fix keeps the same handlers and adds the project space to the lookup. Per the advisory, a foreign record ID now returns 404 instead of being deleted. The advisory asks self-hosted instances to deploy 3570c0ff9c7 or later. For anyone who cannot upgrade right away, it suggests blocking the /a/<domain>/api/ paths at the proxy, since per-user permission changes do not help when the attacker controls their own project space. A proxy is the server that sits in front of the application and forwards requests; blocking a path there stops the request before it reaches the app.
Variants to test
- Compare every handler on a resource, not just the one you are testing. For each resource, list the read, update and delete methods and check whether each one constrains the lookup by the tenant in the address. A positive result is a delete (or any write) that resolves a record by primary key alone while its sibling methods filter by tenant.
- Send a delete with a foreign ID and watch the status code. If the record is removed and the response is a success rather than a 404, the ownership check is missing. In this case the handler returned 202 and tastypie turned it into a 204.
- Check the base-resource dispatch check separately from the handler. Authentication and any framework-level check may only validate the caller's permission in the address's project space. A positive result is a request that passes those checks and still reaches a record in another tenant.
- Try the same pattern on nested resources. Lookup-table rows are children of lookup tables; child resources often repeat the parent's lookup mistake. A positive result is a row deleted through an address naming a different project space.
- Look for ID exposure across tenants. The severity here depends on whether IDs leak between project spaces. A positive result is any API response, export or shared link that reveals a record ID belonging to another tenant.
Disclosure timeline
- 2026-08-12: found during source review.
- 2026-08-13: reproduced with the harness above.
- 2026-08-14: reported by email to Dimagi's security team; the fix (PR #38029) was merged the same day.
- 2026-08-16: Dimagi acknowledged the report.
- 2026-08-20: advisory GHSA-hq38-78vf-f4cj published.
If you self-host CommCare HQ, make sure you have deployed 3570c0ff9c7 or later.
Glossary
- API: a way for one program to talk to another over the web, using fixed addresses and request formats.
- Authentication: working out who the caller is and whether they may use the system at all.
- Authorization: deciding whether a specific caller may do a specific thing to a specific record.
- Base-resource dispatch check: the framework-level check that runs before a resource's own handler; here it only looked at the caller's own project space.
- Broken object level authorization / IDOR: a flaw where the program checks who you are but not whether the record you point at is yours.
- Cache: a fast temporary store of data kept to avoid slow lookups.
- Commit: a saved snapshot of source code, identified by a short hash.
- Control: a comparison test run on a case that should be blocked, to show the difference.
- CVSS: a standard scoring system for the severity of security flaws, from 0 to 10.
- CVSS vector string: the recipe behind a CVSS score;
AVis attack vector (N means network),ACattack complexity (H means high),PRprivileges required (L means low),UIuser interaction (N means none),Sscope (U means unchanged),Cconfidentiality impact (N means none),Iintegrity impact (H means high),Aavailability impact (H means high). - CWE-639: a standard catalogue entry for authorization bypass through a user-controlled key.
- CWE-863: a standard catalogue entry for incorrect authorization.
- DELETE: the HTTP verb meaning "remove this thing".
- django-tastypie: a Python library that exposes database records through a REST API and gives each record read, update and delete handlers.
- Domain: the code's name for a project space.
- Handler: a small function that runs when a request touches a record, such as
obj_updateorobj_delete. - Harness: a small test program that drives real code through its real request handling, with fake pieces standing in for the parts that need a full server.
- HTTP status code: the number in a web reply, such as 202 (accepted), 204 (no content), 404 (not found) or 500 (server error).
- Lookup table: reference data that a project's apps and forms read, made of rows.
- Mobile worker: a field user of a project's apps.
- Primary key: the unique ID of a database record.
- Project space: one organisation's separate area on a shared CommCare HQ server; the code calls it a
domain. - Proxy: the server in front of the application that forwards requests; blocking a path there stops the request before it reaches the app.
- PR (pull request): a proposed change to source code that gets reviewed and then merged.
- REST: a common style for APIs where each thing has its own address and standard verbs are used.
- Retire: mark a mobile worker as deleted.
- Stand-in (stub): a simplified replacement that behaves enough like the real thing for a test.
- Tenant: one customer sharing a system with others.
- Tenant boundary: the wall that stops one tenant from touching another's things.
- PUT: the HTTP verb meaning "update this thing".
- GET: the HTTP verb meaning "read this thing".
- 202 / 204 / 404 / 500: HTTP status codes meaning accepted, no content, not found and server error respectively.