An API can work perfectly for every feature and still be wide open to anyone who calls it. This flaw rarely lives in the encryption algorithm. It usually comes from forgetting to lock individual routes.
The Common Problem: Public APIs by Default
When building an API quickly, developers often put routes into a shared group without authentication middleware. Nobody calls them outside the intended flow, so the gap stays hidden. Once someone discovers the URL, they can create, edit, or delete data without logging in.
In a recent review, many routes managing data, including creating, updating, and deleting objects and users, sat outside the authentication group. Once the public group was separated from the authenticated one, the public surface shrank considerably, leaving only the home page and guest endpoints that truly needed to be open.
Three Layers of Checks
The first is authentication: who is calling? Every route handling sensitive data must sit behind authentication middleware. Hiding a button in the interface is not enough.
The second is role-based authorization: being logged in is not sufficient. Actions such as creating, editing, or deleting categories should be restricted to administrators, enforced on the server.
The third is object-level authorization: may user A edit user B's profile? This flaw is commonly called IDOR (Insecure Direct Object Reference). Checking "is logged in" alone won't stop it. You must compare ownership or role against the specific object. A simple rule might allow the action only for administrators or the account owner.
Don't Rely on the Frontend
Hiding a delete button does not stop anyone from calling the API directly with Postman or curl. Every critical permission check must live on the server. The frontend improves experience; it is not a security boundary.
Business Rules Are Part of Security
For example, blocking the deletion of a category that still has active shops. This rule should be enforced on the server, returning a 422 status with a clear message.
Note that "check whether child records exist, then delete" is a two-step operation. If another request adds a child record between those steps, the check can be outdated. A safer approach is to run both steps inside one transaction with proper locking, and use a foreign key constraint in the database as the final safeguard.
Password Reset Tokens Must Be Bound to the Account
If a reset token is looked up by the token string alone, a valid token could be used against another account in unusual situations. Look it up by both email and token, and enforce an expiry time.
Reduce the Attack Surface
If public registration isn't needed, turn it off. For a session-based SPA, enable the appropriate authentication middleware, and handle 401 (not logged in) and 419 (expired CSRF token) on the client, so users return to the login page instead of seeing confusing errors.
An API Review Checklist
Before merging, ask: are all routes with sensitive data behind authentication? Do write operations check roles? Do routes with an id check permission on that specific object? Do critical business rules run on the server? Could error messages accidentally expose internal details?
API security isn't a feature you bolt on at the end. It starts with every route closed by default, then opened deliberately, one at a time.
References
OWASP API Security Top 10 (2023)