IDOR in exports and batch endpoints

A list of ids is still a list of objects. An export or a batch route that loads each id without an owner check is broken object authorization with better throughput.

Lesson 58 of 69 · 15 min read · practice only with authorization

Diagram

From a batch of ids to rows the caller does not own

Follow the path. One example at a time.

Step 1 of 4

List

The client sends several ids, or asks for “everything in this filter.”

Illustration: a list is still one caller’s rows
# An export asks for many rows.
# The caller is still one person, or one tenant.
What changes the outcome
Body

A list of ids arrives.

Query

WHERE id IN (…).

File

Other tenants’ rows are in the download.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

4 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. A list is many objects

    What fails
    Authorization that works for one id and is skipped for an array is the same bug, repeated.
    Who is affected
    Every person whose id was in the batch and was not the caller.
    What you would notice
    A route whose schema is an array, with a query that has no owner predicate.
    What you change
    Add the owner predicate. Review every new bulk route the same way as a single-id route.
  2. Exports are easy to over-collect

    What fails
    A file that leaves the system is a worse place to put an extra row than a JSON error. People forward files.
    Who is affected
    The other tenants in the file, and the caller who now holds data they were not granted.
    What you would notice
    An export job that runs with a service role and a filter the client supplied.
    What you change
    Run the job as the user, or pass the user id into a query that cannot see other tenants.
  3. Do not confirm foreign ids

    What fails
    Telling the caller which ids existed but were not theirs is its own disclosure. Absence is enough.
    Who is affected
    The owner of an id the caller was probing.
    What you would notice
    An error body that lists “forbidden” ids separately from “missing” ones.
    What you change
    Return the caller’s rows only. Use one shape for everything else.
  4. Jobs and webhooks

    What fails
    A background export stored by id in a queue can drop the user if the worker only trusts the payload.
    Who is affected
    Whoever the worker can read while it builds the file.
    What you would notice
    A queue message that contains ids and no subject, consumed by a privileged worker.
    What you change
    Put the subject in the query, not only in the message. Reject messages that do not match a real session or a real grant.

Bulk is not a different rule

Broken object authorization is usually taught as one id in a URL. Products also accept a list: export these invoices, delete these files, share these records. The authorization rule does not become weaker because the schema is an array. Each id is still an object. The query still has to say which caller is allowed to see it.

A correct check on the single-item route is how this bug hides. Reviewers point at that route and call the feature done. The export was written later, by someone who copied a query that used an IN list and forgot the owner. Treat every new route as unreviewed, including the ones that “just wrap” an existing lookup.

Workers inherit whatever you put in the queue

Exports often run in a job so the HTTP request can finish. The job is a second entry point. If the message says “these ids” and the worker connects as a privileged account, the worker is an API with no session. Put the user or the tenant in the query the worker runs. Do not trust a list that was valid when it was enqueued if you cannot prove it is still that user’s list.

The file is the sensitive artifact. It gets emailed, downloaded, and left in a bucket. A single foreign row in it is a disclosure with a long life. Scope the query so the row is never selected. Do not filter it out in the renderer after it has already been read into a template.

Errors that confirm someone else’s id

If the batch returns “these three were forbidden” and “these two do not exist,” the caller learns which ids are real. That is a smaller bug than returning the rows, and it is still a bug. Return the rows that belonged to the caller. Say nothing specific about the rest. The same response shape should cover missing and not-owned.

You would notice a query with an IN list and no tenant column, a worker role that can read the whole table, and an error schema that separates forbidden from missing. The people affected are the owners of the extra rows. The finding can say that without attaching the file.

What you change

Add the owner or tenant predicate next to the IN list, and bind both. Cap the list length as a capacity control, not as an authorization control. Make the worker use the same query helper as the interactive route so there is one place to be correct.

Test with two users. Avery submits a list that mixes Avery’s ids with Blake’s. The result contains only Avery’s rows, and the response does not name Blake’s ids. That is the regression. Hiding the export button is not.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

GET /invoices/1042 checks the owner. POST /exports accepts a list of invoice ids and loads them with no owner predicate. What failed?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapIDOR and broken object-level authorization: ids without an owner checkHow changing an id in a URL or API body returns someone else’s record, why it tops the OWASP API list, how to test it with two accounts you own, and the ownership-scoped query that fixes it.
  1. 01Nested object authorizationA check on the parent record does not authorize every child id inside the request.

Practice

  1. LabTenant deskTwo companies, one API. See what changes when the server checks ownership.

Glossary

  1. CardInsecure direct object referenceChanging an identifier in a request returns or edits another user's object because the server never checks ownership.