> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reliantlabs.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Find API endpoints that never check who is calling

> List every signed-in RPC whose handler never reads the caller, then fix each with a role or owner check, or mark it global with a reason a reviewer reads.

A forge API turns away every request without a valid credential, but a valid credential only proves the caller is signed in. Any signed-in user can call a handler that never asks who they are, which is how one customer ends up reading another's orders (IDOR, or BOLA in the OWASP API list). This guide finds those handlers and closes each one.

Forge can find them because it knows which RPCs require sign-in, from the proto, and can read the Go handler that serves each one. [The security model](https://docs.reliantlabs.io/deep-dives/security-model.md#2-you-write-the-access-rules-and-the-audit-finds-the-gaps) explains the design.

## Before you begin

* The `shop` project from [Add a database table with a CRUD API and pages](https://docs.reliantlabs.io/guides/forge/add-table-crud-api-pages.md), with its `Product` and `Review` entities. Any forge API works the same way.
* Forge v1.6.1 or later, run as `reliant forge` inside the project.
* `jq`, to read the JSON report.

**1. List the RPCs that never read the caller**

The check is the `unscoped_auth` category of `project audit`. There is no `lint` flag for it.

```bash terminal theme={null}
reliant forge project audit
```

```text theme={null}
⚠ unscoped_auth — 10 of 10 authenticated RPC(s) never resolve the caller — every signed-in caller is treated identically (middleware.GetUser)
```

The list itself is under `categories`:

```bash terminal theme={null}
reliant forge project audit --json | jq -r '.categories.unscoped_auth.details.unscoped_rpcs[] | "\(.method)  \(.file)"'
```

```text theme={null}
CreateProduct  internal/handlers/catalog/handlers_crud.go
CreateReview  internal/handlers/catalog/handlers_crud.go
DeleteProduct  internal/handlers/catalog/handlers_crud.go
...
UpdateReview  internal/handlers/catalog/handlers_crud.go
```

A handler counts as reading the caller when it calls `middleware.GetUser`, directly or through a helper in its own package.

**2. Decide what each RPC needs**

Every RPC on the list gets one of three answers:

* **Rows belong to someone.** Filter by the caller. `Review` and any order or account table are this case: follow [Scope rows to their owner](https://docs.reliantlabs.io/guides/forge/scope-rows-to-owner.md).
* **Only some callers may do it.** Check a role. Changing the product catalog is this case.
* **It is the same for every signed-in caller.** Say so in code. Reading the catalog is this case.

**3. Check a role**

Write the check once, as a helper in the handler package:

```go internal/handlers/catalog/authz.go theme={null}
func requireAdmin(ctx context.Context) (*middleware.Claims, error) {
	claims, err := middleware.GetUser(ctx)
	if err != nil {
		return nil, err
	}
	if !slices.Contains(claims.Roles, "admin") {
		return nil, svcerr.PermissionDenied("admin role required")
	}
	return claims, nil
}
```

Call it first in `CreateProduct`, `UpdateProduct` and `DeleteProduct`:

```go internal/handlers/catalog/handlers_crud.go theme={null}
	if _, err := requireAdmin(ctx); err != nil {
		return nil, err
	}
```

`Claims.Roles` comes from the token's roles claim. Roles kept in your own tables can be added in the `enrichClaims` hook in `pkg/middleware`, which runs before any handler.

**4. Mark the global reads**

Put the marker on the handler's doc comment. The reason after the colon is required: a bare `// forge:auth-unscoped-ok` is ignored, and the RPC stays on the list.

```go internal/handlers/catalog/handlers_crud.go theme={null}
// ListProducts delegates CRUD list to pkg/crud.
// forge:auth-unscoped-ok: the product catalog is the same for every signed-in caller
func (s *Service) ListProducts(
```

Do the same for `GetProduct`.

**5. Run the audit again**

```bash terminal theme={null}
reliant forge project audit --json | jq '.categories.unscoped_auth | {summary, scoped: .details.scoped_rpcs, acknowledged: [.details.acknowledged_rpcs[] | {method, reason}]}'
```

```json jq output theme={null}
{
  "summary": "5 of 10 authenticated RPC(s) never resolve the caller — every signed-in caller is treated identically (middleware.GetUser)",
  "scoped": 3,
  "acknowledged": [
    { "method": "GetProduct", "reason": "the product catalog is the same for every signed-in caller" },
    { "method": "ListProducts", "reason": "the product catalog is the same for every signed-in caller" }
  ]
}
```

The three product writes now count as scoped, the two reads appear with their reasons for a reviewer, and the five `Review` RPCs are left for owner scoping.

**6. Prove the check with a test**

The audit proves a handler reads the caller, not that it decides correctly. A test does. Give the scaffolded test context the role (`crudTestCtx` in `handlers_crud_test.go` now needs `Roles: []string{"admin"}`, or the lifecycle test fails with `admin role required`), and add a caller without it:

```bash terminal theme={null}
task test:short -- -v -run 'TestProduct_|TestCRUD_Product' ./internal/handlers/catalog/...
```

```text theme={null}
--- PASS: TestCRUD_Product_Lifecycle (0.13s)
    product_admin_test.go:24: bob (no role) CreateProduct: admin role required
--- PASS: TestProduct_WritesNeedAdmin (0.10s)
ok  	example.com/shop/internal/handlers/catalog	0.245s
```

**7. Check that each listener serves one kind of caller**

A user's token must not reach a service meant for daemons or operators. `lint --graph` checks that every listener serves only services of its authenticator's audience (`//forge:audience user` on `NewUserAuth` in `internal/app/providers.go`):

```bash terminal theme={null}
reliant forge lint --graph
```

```text theme={null}
✓ graph
✅ All 1 gating linters passed.
```

A mismatch fails with [`forge-graph-audience`](https://docs.reliantlabs.io/forge/linting/rules-deploy-and-secrets#forge-graph-audience).

## What this does not do

* **It is a static check.** It finds handlers that never read the caller. It can't tell whether a handler that does read the caller uses the answer correctly; that is what your tests are for.
* **It warns, and `project audit` exits 0, until you declare an owner.** A `forge:owner` column turns the RPCs over that table into errors that fail the audit. See [Scope rows to their owner](https://docs.reliantlabs.io/guides/forge/scope-rows-to-owner.md).
* **A custom RPC can't arm the gate.** The audit matches RPCs to tables by their CRUD names, so a custom RPC is listed as a warning only.
* **Forge writes no access rules.** It has no roles or permission model of its own. Every check on this page is code in your repository.

## Troubleshooting

> [accordion] jq prints null
>
> The category is nested: use `.categories.unscoped_auth.details.unscoped_rpcs`, not `.unscoped_auth`.

> [accordion] The RPC stays on the list after you add the marker
>
> The marker needs a reason after a colon, and it must sit on the handler method's doc comment: `// forge:auth-unscoped-ok: <reason>`.

> [accordion] create #1: admin role required
>
> The scaffolded lifecycle test calls with `crudTestCtx()`, which has no roles. Add the role your check requires to the claims there.

## Next steps

> [card] [Scope rows to their owner](https://docs.reliantlabs.io/guides/forge/scope-rows-to-owner.md)
>
> Declare a `forge:owner` column and filter every query by the caller

> [card] [Security model](https://docs.reliantlabs.io/deep-dives/security-model.md)
>
> Fail-closed auth, the audit, audiences and error redaction

> [card] [Add sign-in](https://docs.reliantlabs.io/guides/forge/add-sign-in-passkeys.md)
>
> Passkeys, magic links or social login, and the RPCs that stay public

> [card] [Middleware and the request path](https://docs.reliantlabs.io/forge/concepts/middleware-and-request-path.md#auth-fails-closed)
>
> Where the auth interceptor and your enrich hook run


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.