Articles / Security

  • idor
  • access-control
  • appsec
  • vulnerability-disclosure
  • go
  • computer-misuse-act

How to Prove an IDOR With Two Test Accounts and Nobody Else's Data

You change /invoices/1001 to /invoices/1002 and an invoice comes back. The tempting next move is to try 1003, to make sure. Don't: if 1002 belongs to a stranger, you have just read their data, and 1003 only makes it worse.

An insecure direct object reference (IDOR) is a missing ownership check: the server knows who you are, but never asks whether this object is yours. You can prove that completely with two accounts that both belong to you.

Get permission before you create anything

Start with a bug bounty scope, a vulnerability disclosure policy or written permission that covers this system and this sort of testing. Check what it says about test accounts, automation and data you might stumble on.

In England and Wales, section 1 of the Computer Misuse Act 1990 covers knowingly seeking unauthorised access to programs or data. Section 17(5) defines "unauthorised" by whether you are entitled to control that access, or have consent from someone who is.

My reading is that owning both accounts does not by itself give you permission. The records still sit on someone else's computer. Two accounts limit the harm and make the evidence cleaner; the scope is what gives consent. This is general information, and the details of your case matter.

Plant a canary in the second account

Register account A and account B, using whatever naming or email convention the programme asks for. In each, create one object of the type you are testing.

Put a unique, harmless string in B's object, such as canary-B-7f3a9c in an invoice note. Then record:

  • each account's session token or cookie
  • the ID of each object, taken from that account's own pages or API responses
  • the canary, and when you created it

The canary is your proof. A 200 status alone shows very little, because plenty of applications return 200 with an error page, an empty object or your own record. If B's random string turns up in a response to A, that argument is over.

Send four requests and compare them

This script assumes bearer tokens and a path of /invoices/{id}. Swap in your target's equivalents. It prints the status and whether the canary appeared, without dumping response bodies into your terminal.

#!/usr/bin/env bash
set -euo pipefail

: "${BASE:?}" "${TOKEN_A:?}" "${TOKEN_B:?}" "${ID_A:?}" "${ID_B:?}" "${CANARY_B:?}"

body=$(mktemp)
trap 'rm -f "$body"' EXIT

probe() { # label, token (may be empty), object id
  local auth=() status seen=no
  if [[ -n $2 ]]; then auth=(-H "Authorization: Bearer $2"); fi
  : >"$body"
  status=$(curl -sS -o "$body" -w '%{http_code}' "${auth[@]}" "$BASE/invoices/$3")
  if grep -qF -- "$CANARY_B" "$body"; then seen=yes; fi
  printf '%-14s status=%s canary_b=%s\n' "$1" "$status" "$seen"
}

probe "A reads A" "$TOKEN_A" "$ID_A"
probe "B reads B" "$TOKEN_B" "$ID_B"
probe "A reads B" "$TOKEN_A" "$ID_B"
probe "nobody reads B" "" "$ID_B"

Against a deliberately broken local server, it prints:

A reads A      status=200 canary_b=no
B reads B      status=200 canary_b=yes
A reads B      status=200 canary_b=yes
nobody reads B status=401 canary_b=no

The third line is the finding; the other three stop people explaining it away.

  • The first shows A's session works.
  • The second shows the canary really is in B's object.
  • The fourth shows the endpoint demands a login, so the object isn't simply public.

If the anonymous request also returns the canary, you have a different and probably worse problem: no authentication at all. Check that the object isn't meant to be shareable by link before reporting it.

Also check that A and B aren't supposed to share access. Two users in the same organisation, or one with an admin role, can produce a very convincing false positive.

A 403 and a 404 can both be correct

A fixed server will refuse the third request. It may say 403, or it may pretend the invoice doesn't exist.

Quick detour, because this looks like fibbing: RFC 9110 explicitly allows a server to answer 404 when it wants to hide that a forbidden resource exists. HTTP has a sanctioned polite lie. For your test, what matters is that the canary stays put.

Test writes only on objects you can afford to lose

Read access doesn't tell you whether update or delete are broken. They are often separate handlers with separate mistakes. If the scope permits it:

  1. As B, create a fresh throwaway object.
  2. As A, change one harmless field to a new marker.
  3. As B, fetch the object and see whether the marker arrived.
  4. For delete, use another throwaway, delete it as A, then check as B.

Always verify from B's side. A success response to A might mean nothing changed, and an error might arrive after the write has already happened.

Leave alone anything that sends email, moves money or notifies third parties unless the owner has agreed to it. The same ID may also appear in a query string, JSON body, export job or attachment URL. Each is its own test, with the same two accounts.

Argue scale without demonstrating it

You don't need to enumerate records to say they could be enumerated. If you create two objects in quick succession and get 1002 and 1003, report that. It is evidence that IDs are predictable, gathered entirely from your own data. It doesn't count the affected records, so don't present it as if it does.

UUIDs don't make the bug go away. OWASP recommends access checks even with complex identifiers, which are only defence in depth. IDs leak through links, logs, exports and former colleagues. Hard to guess is not the same as allowed to read.

If someone else's data does appear, by a typo or an unexpected list response, stop. Don't save more of it, note what happened and when, and tell the owner.

Report the pair of requests, not a data dump

A useful report is short enough to reproduce over one cup of tea:

  • the endpoint and method
  • the two test account names, and which object belongs to which
  • the four results, with timestamps and any request IDs
  • the request where A receives B's canary, with the token redacted
  • what you did not test, including that you accessed no third-party records
  • the expected behaviour: A is refused

The usual labels are CWE-639 and, for APIs, Broken Object Level Authorization. Describe the impact you showed, then label any inference as inference.

Fix it in the lookup, then keep the two accounts

If it's your code, make ownership part of the query. The owner comes from the authenticated session, never from a request parameter.

func findInvoice(ctx context.Context, db *sql.DB, id, owner string) (Invoice, error) {
	var inv Invoice
	err := db.QueryRowContext(ctx,
		`SELECT id, note FROM invoices WHERE id = $1 AND owner_id = $2`,
		id, owner,
	).Scan(&inv.ID, &inv.Note)
	return inv, err
}

Map sql.ErrNoRows to 404, and other errors to 500. For shared or team-owned objects the condition will be a membership check, but it still belongs on every read and write.

Your two accounts now become a regression test. Here routes() is your application's handler, wired to test data where invoice 1001 is Alice's and 1002 is Bob's. For brevity, its test authentication treats the bearer token as the user name; never ship that.

func TestInvoiceOwnership(t *testing.T) {
	tests := []struct {
		name, token, id string
		want            int
	}{
		{"owner A", "alice", "1001", http.StatusOK},
		{"owner B", "bob", "1002", http.StatusOK},
		{"A reads B", "alice", "1002", http.StatusNotFound},
		{"B reads A", "bob", "1001", http.StatusNotFound},
		{"anonymous", "", "1002", http.StatusUnauthorized},
	}
	h := routes()
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			req := httptest.NewRequest(http.MethodGet, "/invoices/"+tt.id, nil)
			if tt.token != "" {
				req.Header.Set("Authorization", "Bearer "+tt.token)
			}
			rec := httptest.NewRecorder()
			h.ServeHTTP(rec, req)
			if rec.Code != tt.want {
				t.Errorf("status = %d, want %d", rec.Code, tt.want)
			}
		})
	}
}

Keep the successful owner cases. Without them, a handler that returns 404 to absolutely everyone passes your security test with flying colours. Add the same cross-account rows for update and delete, and check that the stored object hasn't changed.