API Security: JWT, Rate Limiting, and the Mistakes We See in the Field

Mobile apps, admin panels, third-party integrations... They all sit on top of APIs, and attackers know it. Your web interface may be solid, but if your API is exposed, you've built your front door out of glass. We've compiled the most critical topics distilled from the security reviews we've done on projects we've taken over: from token architecture to authorization, from rate limiting to webhook security, each one a concrete measure with a real-world counterpart in the field.

JWT: the right tool, used the wrong way

JWT itself is a secure standard; the problems are in the implementation details. What we see most often in the field:

  • Access tokens that never expire or stay valid for months. The right way: a short-lived access token (15-60 minutes) plus a refresh token for renewal, together with refresh token rotation.
  • Embedding sensitive data in the token. A JWT is not encrypted, only signed; anyone can read the payload. Don't put phone numbers, addresses, or permission details in it.
  • Accepting the signing algorithm from the client. The "alg: none" attack is still real; pin the algorithm on the server side.
  • Tokens that stay valid after logout. In critical systems, a short lifetime plus a server-side revocation list is a must.
A comparison of JWT mistakes seen in the field and the correct practices.
JWT is a secure standard; the problems are in the implementation details.

Authorization: the other half of authentication

The item at the top of OWASP's API security list hasn't changed in years: broken object level authorization (BOLA). The user may be logged in; but on a call to /api/orders/8412, do you check every single time whether that order actually belongs to that user? It's the first place we look in our code reviews, and unfortunately, in most projects it's where we report our first finding. The rule is simple: an ownership check on every endpoint, for every record; "the frontend doesn't show it anyway" is not a security measure.

Rate limiting: the forgotten insurance policy

A login endpoint with no limits is an open invitation to brute force. An SMS-sending endpoint with no limits can mean a bill of thousands of lira (Turkish currency) overnight; we took over a project from a client who went through exactly that, so we know. We recommend layered limits: a general IP-based limit, per-user endpoint limits, and separate strict quotas for costly operations (SMS, email, report generation). Setting up a layered structure with Laravel's throttle middleware and Cloudflare or nginx limits in front of it is half a day's work; the payoff is priceless.

Rate limiting layers: Cloudflare/nginx, IP-based limit, per-user limit, and quota for costly operations.
Layered limits take half a day; the payoff is big.

Machine-to-machine communication: webhooks and service accounts

API security isn't only about the link between the mobile app and the server; webhooks from the payment provider, shipping integrations, and third-party service accounts demand the same discipline. If signature verification (an HMAC check with the secret the provider gives you) is skipped on webhook endpoints, it becomes possible to get an order approved with a fake "payment received" notification; this scenario isn't theoretical, it has happened many times across the industry. For service accounts, the principle of least privilege applies: an integration that pulls reports shouldn't have delete permissions, and every integration should have its own key so that, in a leak, only that key needs to be revoked. Keeping keys in environment variables rather than in code, rotating them at regular intervals, and disabling unused ones are also part of this hygiene.

Other small but effective measures

  • Simplify your error messages: even distinguishing between "user not found" and "wrong password" gives an attacker information.
  • Version your API and actually shut down old versions; a forgotten v1 becomes your weakest link.
  • Log all request/response traffic centrally; you can't defend against an attack you can't detect.

At Rich Design, we have been building backends and APIs since 2010; we take on security audits of your existing APIs, JWT architecture setup, and rate limiting design end to end. To get an X-ray of your API, get in touch.