AI-generated login: hiding a button does not protect an API
A local lab checks access for the owner, another account and an anonymous user before and after a server-side check.
The check must exist on the route
The screen can hide a button from a user while leaving the corresponding route accessible. The lab deliberately constructs this defect with a fictional document owned by Alice. Bob should not be able to read it. In the initial state, however, Bob's direct request receives a 200 response.
The scenario is not the result of an application-generator audit. It explains a security boundary to verify regardless of the code's origin. Requests were executed only against the local server created for this article.
Separate identity from rights to the object
Authentication establishes an identity through the chosen mechanism. Authorisation decides whether that identity can perform that action on that resource. In this example, logging into an account does not grant access to another owner's document.
The example replaces authentication with an x-demo-user header to isolate the authorisation decision. This header is forgeable and must not be reused as a login mechanism. A real application must obtain identity from a session or token verified on the server.
A minimal matrix actually executed
Ressource : doc-a, propriétaire : alice
Avant contrôle : bob -> 200, défaut volontaire
Après contrôle :
anonyme -> 401
bob, autre propriétaire -> 403
alice, propriétaire -> 200const status = !user ? 401
: user !== document.owner ? 403
: 200;The script checks these statuses with assertions and closes the server after the experiment. It includes no real secret. In some API contracts, a 404 response for an inaccessible resource can avoid revealing its existence; define that choice and check it consistently.
Extend checks to the actions actually offered
- Check reading, editing and deletion, not just the main screen.
- Check client-supplied resource identifiers and rights on every request.
- Provide for administration roles with an explicit scope.
- Test missing identity and another owner's account using fictional data.
OWASP ASVS provides a framework of security requirements. This lab covers only one simplified decision and is not a complete review. It tests neither session creation, renewal, rights revocation nor database-level isolation.
When requesting work from an agent, attach the authorisation matrix and expected denial tests. A convincing login screen never removes the need to replay these requests in the authorised environment.