Cloud, DevOps & Security 9 min read

API Security Best Practices: Authentication, Authorisation, Rate Limiting and More

How to secure REST and GraphQL APIs used by mobile apps and websites: tokens and keys, object-level authorisation, input validation, rate limits, CORS, webhooks and logging — with simple examples.

Umer Hasan

Umer Hasan

Co-Founder & CTO at Zapprex

API Security Best Practices: Authentication, Authorisation, Rate Limiting and More
Table of contents

Your API is your app’s front door

Mobile apps and modern websites talk to the backend through APIs, and attackers can call those APIs directly — skipping your app’s screens and checks entirely. Anything the app hides, the API must still protect.

At a glance: The biggest API risks — Broken object-level authorisation, Broken authentication, Excessive data exposure, No rate limiting
At a glance: The biggest API risks

The biggest API risks

  • Broken object-level authorisation: changing /orders/1001 to /orders/1002 shows someone else’s order.
  • Broken authentication: weak tokens, tokens that never expire or missing checks on some endpoints.
  • Excessive data exposure: returning whole database records and relying on the app to hide fields.
  • No rate limiting: attackers brute-force logins, scrape data or run up SMS and AI costs.
  • Mass assignment: users set fields they should not, such as role or price, by adding them to the request.

Best practices, step by step

Best practices, step by step: 7 steps
  1. 1

    Authenticate every request: use short-lived access tokens and refresh tokens, or secure session cookies for web apps.

  2. 2

    Authorise every object: check ownership or role on the server for each record requested or changed.

  3. 3

    Return only needed fields: use response schemas or DTOs instead of raw database rows.

  4. 4

    Validate input with a schema: reject unknown fields and wrong types (for example with Zod or Joi).

  5. 5

    Rate-limit and throttle: per user, per IP and per endpoint, with stricter limits on login, OTP and search.

  6. 6

    Configure CORS narrowly: allow only your own domains for browser access.

  7. 7

    Verify webhooks: check signatures from payment gateways and other providers before trusting the payload.

Object-level authorisation in an Express routejavascript
app.get("/api/orders/:id", requireAuth, async (req, res) => {
  const order = await db.order.findUnique({ where: { id: req.params.id } })
  if (!order || order.userId !== req.user.id) return res.status(404).end()  // not 403: do not reveal it exists
  res.json({ id: order.id, status: order.status, total: order.total })      // only needed fields
})

Keys, secrets and mobile apps

“Assume every API endpoint will be called by someone who is not using your app.”

— Umer Hasan, CTO
  • No secrets in the app: anything inside a mobile app or JavaScript bundle can be extracted.
  • Proxy third-party APIs: call payment, SMS and AI providers from your server, not from the client.
  • Rotate keys: and revoke immediately if a leak is suspected.
  • Log and monitor: track 401/403 spikes, unusual volumes and access to sensitive endpoints.

Topics

API SecurityJWTRate LimitingOWASP API Security
Umer Hasan
Written by

Umer Hasan

Co-Founder & CTO at Zapprex

Leads engineering, cloud infrastructure and AI automation at Zapprex Technologies, with 7+ years of full-stack and mobile experience.

FAQ

Questions readers ask

JWTs can be secure when signed with strong keys, kept short-lived, validated properly on every request and paired with a revocation strategy such as refresh tokens.

Have a project in mind?

Let's build something that moves your business forward.

Share your idea, process or problem — we will come back with a clear plan, timeline and cost range. No technical spec needed.

  • Founder reply within 1 business day
  • NDA on request · 100% code ownership
  • Talk directly to the engineers