The owner filter.
The access-control checklist I run on every endpoint: unconditional owner and zone filters, roles that fail closed, and testing access with two accounts.
Most access-control bugs I have read about are not clever. Nobody broke a cipher. An endpoint took an id from the request, loaded the row, and returned it, without asking whose row it was. That class of bug has a name, insecure direct object reference (IDOR), and it is the first thing I check on every endpoint I write or port.
I keep a short checklist for it. This post is that checklist and the reasoning behind each item.
The filter is never conditional
Every query that loads something a user owns carries the owner in the WHERE clause, always. Not "when the request includes a user id", not "unless the caller is a guest". Always.
The bug I look for is the conditional version. It reads naturally and it passes a quick review:
// Wrong: the owner check only exists on one branch.
q := "SELECT id, status, total FROM orders WHERE id = ?"
args := []any{orderID}
if guestID != "" {
q += " AND guest_id = ?"
args = append(args, guestID)
}// Wrong: the owner check only exists on one branch.
q := "SELECT id, status, total FROM orders WHERE id = ?"
args := []any{orderID}
if guestID != "" {
q += " AND guest_id = ?"
args = append(args, guestID)
}A signed-in user goes down the first branch with no owner filter at all. The guest branch looks careful, and that is exactly why the other branch gets missed. The version I want has no branch where the owner is optional:
// Right: the owner comes from the session, never from the request,
// and every path through the code includes it.
owner := mustOwner(r) // user id or guest id from the verified token
row := db.QueryRow(
"SELECT id, status, total FROM orders WHERE id = ? AND owner_key = ?",
orderID, owner.Key(),
)// Right: the owner comes from the session, never from the request,
// and every path through the code includes it.
owner := mustOwner(r) // user id or guest id from the verified token
row := db.QueryRow(
"SELECT id, status, total FROM orders WHERE id = ? AND owner_key = ?",
orderID, owner.Key(),
)Two rules hide in that second snippet. The owner comes from the verified session, never from a field the client sends. And if there is no owner, the request fails before any query runs. A missing row and a row that belongs to someone else return the same "not found", so the response doesn't confirm that the id exists.
The same rule applies to staff. Operations staff at Laayo are scoped to zones, and every staff query carries the zone filter the same way. A staff member's zones come from their account, not from a query parameter.
Roles fail closed
The second check is what happens when information is missing. A staff account with no zone should see nothing, not everything. A role with no entry for a module should be denied that module, not allowed by default. A permission lookup that errors should deny.
It sounds obvious written down, but the failure mode is easy to write. Code like "if the account has zones, filter by them" quietly means "if the account has no zones, show all of them". Every scope check I write starts from deny and adds access, so an empty or broken input lands on deny.
A related rule for staff: a person may only grant permissions they hold. A role editor that lets someone create a role with more access than their own, or assign a role from another store, is an escalation path even if every individual query is scoped.
The rest of the list
The owner filter is the first item. The rest follow from the same question, "what could the caller change that they shouldn't?":
- Mass assignment. Updates copy an explicit list of fields, never "everything in the request body". A profile update must not accept a role, a wallet balance or a verified flag.
- Prices and amounts. The server computes every price, fee and total from its own data. An amount sent by the client is, at most, something to compare against.
- One-time codes and logins. Rate limits per phone number and per account as well as per IP, and the same response whether or not an account exists.
- Personal data in responses. An endpoint returns the fields its screen uses. A rider list for a customer doesn't need riders' phone numbers. Masked by default, shown in full only to roles that need it.
- Realtime channels. A private channel name is not a secret. Subscribing to a channel goes through the same ownership check as reading the data over HTTP.
- Share links. A link that shows something without a login, like order tracking, shows only what the page needs, and stops showing live data when the thing it shares is finished.
- Database grants. The API's read user cannot select secret columns, and the write user can update only the columns the code is known to write. If a bug slips through review, the database still refuses.
Testing it, not just reading it
Reading code finds some of these. Running the attack finds the rest. For every new endpoint that takes an id, I use two test accounts. Account A creates something. Account B asks for it by id, tries to change it, and tries to delete it. Then a guest tries the same. Then a staff account from a different zone. Each attempt should fail, and fail with the same answer as an id that doesn't exist.
I do this in the test environment as part of finishing the feature, the same way I write tests. The security pass is a step of "done", not a separate project for later. When I port an old endpoint to Go, the port goes through the same checks before it serves anything.
Get new posts by email
One email when something new goes up. No tracking pixels, unsubscribe in one click.