Stack

How to security test a Go HTTP service

Updated

In Go, authorization is a wrapper function you apply per route, so the test is to walk the mux and find the handlers registered without it. Then check that tenant identity comes from the request context rather than from a URL or body field.

Where this class of bug actually lives in a Go service

  • Handler registration. mux.HandleFunc("/invoices/", listInvoices) with no auth middleware wrapper is unauthenticated, and nothing in the type system notices.
  • ID from the path. r.PathValue("id") or a router param feeding a query without a tenant clause.
  • Context misuse. A middleware that puts the user in the context, and a handler that reads the org from the request body anyway.
  • Panic recovery. Without a recover middleware, one panic per request is a denial of service; with a naive one, the stack trace goes to the client.

What to try first

  1. Enumerate registered patterns and request each with no authentication header.
  2. Send another tenant's id in every path that has one, compared against a fake id.
  3. Trigger a panic in a handler and check what the client receives.
  4. Check http.Server timeouts are set — an unset write timeout is a one-line DoS.

A reproduction you can keep

The pattern to test is the auth wrapper's absence. One route, no header:

Unauthenticated handler, then a tenant swap
curl -sS -i https://staging.example.com/api/invoices/1003
curl -sS -i https://staging.example.com/api/invoices/1003 -H 'Authorization: Bearer ***'

# vulnerable: both 200, both return the invoice
# fixed: 401 without the header; 404 for a foreign id with it

What "fixed" has to look like

Every handler must sit behind the same auth wrapper, and the tenant must be read from the context the wrapper populated. The fixed response is 401 without a token and 404 for any id outside the caller's tenant, identical to a nonexistent id.

Where people get this wrong

  • A helper that wraps some routes and not others is the whole vulnerability class. Prefer one subrouter with the wrapper applied at mount time.
  • Structs decoded with json.Decode accept every field in the payload; use a separate request struct, not your model.
  • http.ServeMux patterns with a trailing slash match subtrees. /invoices/ also matches /invoices/admin.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Does Go have built-in authorization?

No. There is no auth layer at all; every route either sits behind your middleware or is public.

Why is a Go IDOR easy to miss?

Because the query compiles and runs correctly. Nothing in the language asks where the tenant id came from.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.