Agent security
Can AI-Generated APIs Enforce Tenant Boundaries? A Worked Security Review
Review generated APIs for trusted tenant authority, object authorization and meaningful rejected-case tests using synthetic identities and invoices.

Executive summary
AI-generated APIs can enforce tenant boundaries when the application derives tenant authority from trusted identity, checks access to each object and operation, and verifies those checks with meaningful tests. Generated code needs the same review as any access-sensitive change. Our illustrative review follows an invoice endpoint where a user supplies an object identifier. It is a constructed example, not a finding in a customer application or a claim about a particular coding model.
Start with an object and two tenants
Assume a billing service stores invoices for two synthetic tenants, North and South. A North user requests an invoice through an authenticated endpoint. The security requirement is that the user can access only the objects and operations authorized for that identity.
The client can submit an invoice identifier. That identifier should locate a candidate object, not establish permission to access it. A correct-looking response is insufficient if changing the identifier returns another tenant's invoice.
OWASP's API guidance on broken object-level authorization describes this class of failure. Its central relevance here is the authorization check on the requested object. Authentication alone does not settle whether the authenticated user may access that invoice.
Write the expected behavior before reviewing the implementation. North can read an authorized North invoice; North cannot read South's invoice; unauthenticated requests follow the service's authentication policy. Define permitted writes and administrative exceptions separately.
Trace tenant authority from the identity
Inspect how the server determines the user's tenant and role. A request body field called tenantId is client input. It cannot independently grant access merely because the generated handler includes it in a database filter.
Follow the trusted identity through middleware, authorization logic, service calls, and queries. Confirm where membership is resolved and what happens when it is absent, stale, or inconsistent. The reviewer needs the actual authority source rather than a variable with a reassuring name.
Check special roles carefully. A support or administrator path may intentionally span tenants, but it needs explicit scope, ownership, and evidence. Avoid allowing an ordinary request to select an administrative context through an unchecked parameter.
Use synthetic identities and fixtures for the exercise. Do not copy real customer invoices into a test simply to create two tenants. The important properties are ownership, permitted operations, and the ability to distinguish authorized from unauthorized access.
Inspect every operation that touches the object
An endpoint may check tenant ownership on reads while omitting the same condition on updates, downloads, exports, or related resources. Trace the object across the full operation the user can request.
For the invoice example, inspect the invoice record, line items, attachments, and any generated download link. A protected invoice page can still expose an attachment through a separate route. The review should name those paths instead of describing the feature as one indivisible endpoint.
Look for authorization checks before consequential effects. Loading an object and then returning an error does not necessarily prevent a preceding write, queued job, or external request. Examine the order and the execution path, including error handling.
Background jobs need their own context. If the request queues an export, determine which identity and tenant scope the worker receives. An authorization decision made in the HTTP handler can be lost when the job reconstructs its query without the same boundary.
Use a test matrix that can expose the mistake
Create rows for identity, target object, operation, expected decision, and observable effect. Include an authorized same-tenant read and an unauthorized cross-tenant read. Add writes, bulk operations, and related resources when the changed feature supports them.
Test missing objects and inaccessible objects according to the service's response policy. Decide how errors should avoid exposing unnecessary information. Keep the expected behavior explicit rather than treating every non-success response as proof of the correct authorization path.
Verify the target state after rejected writes. An HTTP denial and an unchanged invoice are complementary evidence. If a job was queued before the denial, inspect whether it ran and what scope it used. The test should reveal the effect the policy was intended to prevent.
Avoid assertions that merely mirror implementation details. A test that checks whether a tenant-filter helper was called can pass while the helper uses untrusted input. Exercise the behavior with distinct synthetic identities and objects, and inspect the actual result.
Review the generated patch as an argument
Ask the coding agent to explain where tenant authority originates, which operations enforce it, and which tests would fail if the boundary were removed. Inspect those claims against code and test artifacts. A persuasive explanation is useful context, not independent verification.
Read adjacent paths when the change introduces a shared helper. A fix for one endpoint can alter behavior elsewhere. Conversely, a correct helper does not protect a route that bypasses it. Use the diff and dependency relationships to decide the necessary review scope.
Record unresolved assumptions. A service may rely on database row policies, gateway context, or an internal API's authorization. Obtain evidence from the responsible layer rather than assuming the check exists because the handler lacks it.
The review result should identify the tested revision, synthetic fixtures, permitted and rejected operations, and remaining gaps. Do not convert a small endpoint exercise into a claim that the whole application is tenant safe.
Keep runtime agent controls distinct from API authorization
Harden evaluates supported actions proposed by coding agents before execution. That can be relevant while the agent edits files, runs tests, or attempts to access data. It does not replace the application authorization that protects deployed APIs when end users send requests.
If the agent needs to inspect a database during review, constrain that identity and use synthetic data. A code-review task should not acquire unrestricted production access simply because it concerns a production feature.
Use our generated-code review article for the broader release checklist. For a Harden evaluation, bring the agent's supported tool path to Control. Book a Call if the development workflow crosses sensitive data or deployment boundaries that need a separate action-control review.
FAQs
Does authentication prevent cross-tenant access?
Authentication establishes an identity through the configured mechanism. Authorization determines what that identity may do to a particular object. Verify the object and operation checks separately. A valid session can still request an invoice belonging to another tenant.
Can the client send the tenant identifier?
It can send an identifier as input, but the server must validate the requested scope against trusted authority. Do not let a client-controlled field grant membership or administrative access. Review how the application resolves identity, tenant membership, and exceptions.
Should we test only the endpoint changed by the agent?
Start with the changed behavior, then examine shared helpers, related resources, and background paths affected by the patch. The necessary scope follows the code and authority relationships. A passing read test does not establish write, export, attachment, or queued-job behavior.
Does a database tenant filter settle the review?
Inspect where the filter value comes from, which queries use it, and whether another path bypasses it. Database policy can be an important layer, but the review needs evidence of the deployed configuration and its interaction with application identities.
Can Harden secure the deployed invoice API?
Do not treat coding-agent action checks as an API authorization implementation. The deployed service still needs its own access controls and tests. Evaluate Harden for supported agent operations during development, while assigning application-security ownership to the resulting software.


