Fast. Simple. No meetings. No delays.
Home / Blog / Israel / Secure API Development for SaaS Products: Where to Start

Secure API Development for SaaS Products: Where to Start

The essential controls for a customer-facing API: authentication, authorization, input validation, rate limiting, logging and versioning.

Cover graphic for the article: Secure API Development for SaaS Products: Where to Start

Secure API development starts with five controls: authenticate every caller, authorise every request against the specific object being touched, validate all input, limit how fast clients can call you, and log security events without leaking data. Get those right before adding features, because an exposed API is probed constantly.

Why secure API development matters: APIs are attacked first

A web page hides logic behind a user interface. An API exposes the logic directly: predictable URLs, structured requests, and responses designed to be read by programs. That makes it easy for legitimate customers to integrate and equally easy for an attacker to automate.

Attackers do not need to be clever. They try the same request with a different ID, with a missing token, with a ten-megabyte body, or ten thousand times in a minute. The OWASP API Security Top 10 is a useful reference for the categories that recur: broken object-level authorisation, weak authentication, excessive data in responses, unrestricted resource consumption and poor inventory of old endpoints. Check the current edition on the OWASP site, since the list is revised from time to time.

For a SaaS product, the stakes are higher because one flaw can expose many customers at once. Treat the API as a product surface with its own design and review process, not a by-product of the front end.

Authentication vs authorization

These two words are often mixed up, and so are their bugs.

  • Authentication answers who is calling. Typical mechanisms are API keys, session cookies, and tokens issued through OAuth 2.0 or OpenID Connect.
  • Authorisation answers what this caller may do with this specific resource. It must be checked on every request, on the server, every time.

The most common serious flaw is authentication without proper authorisation. A logged-in user changes an invoice ID in the URL and sees another company's invoice. The fix is a rule, not a patch: every query that fetches or changes data must be scoped to the caller's account or tenant, and ownership must be verified in a central place rather than remembered by each developer.

Practical choices:

  • Use API keys for simple server-to-server access by a customer's own systems. Keys identify an account, can be rotated and revoked, and should carry limited scopes.
  • Use OAuth 2.0 when third-party applications act on behalf of your users, so users can grant and withdraw access without sharing passwords.
  • Use short-lived tokens where possible, and a clear refresh and revocation story.
  • Define roles and scopes explicitly, and default to the least access that works.

Never invent your own cryptography or token format. Use well-reviewed libraries and standard flows.

Validate everything, trust nothing

Treat every part of a request as hostile: path, query string, headers, body and uploaded files. Validation should be strict and happen on the server regardless of what the client application does.

  • Define a schema for each endpoint: allowed fields, types, formats, lengths and ranges. Reject unknown fields rather than silently accepting them, which also prevents callers from setting fields they should not, such as role or price.
  • Limit sizes: request body size, page size, nesting depth and upload size.
  • Use parameterised queries for databases, and encode output according to where it is used.
  • Return only what is needed. Build explicit response shapes rather than dumping a database record, which tends to leak internal fields.
  • Fail predictably. Use consistent error formats with a useful message for the developer but no stack traces, SQL or internal paths.

If your API is built in PHP, the OWASP-based PHP security checklist covers code-level issues, while designing a REST API in PHP shows how structure and error handling fit together.

Rate limiting and abuse protection

Rate limiting protects availability, controls cost and slows down credential guessing. Without it, one misbehaving integration, or one attacker, can degrade service for everybody.

  • Limit per API key or account, and separately per IP address for unauthenticated endpoints such as login and password reset.
  • Apply stricter limits to expensive operations: search, exports, report generation and anything that calls a paid third party.
  • Return a clear response when the limit is reached, typically HTTP 429 with a hint about when to retry, so well-behaved clients can back off.
  • Consider quotas per plan, which doubles as a commercial control.
  • Add protections around login: gradual delays, lockouts that cannot be abused to block real users, and notifications for suspicious activity.

Rate limiting is also a design question: make bulk operations available in a sensible way, so honest customers are not tempted to hammer your endpoints in loops.

Secrets, tokens and rotation

Many API breaches come from a credential that was somewhere it should not have been: in a repository, a log, a screenshot, or a former employee's laptop.

  • Keep secrets out of source code. Load them from environment configuration or a secrets manager.
  • Give each environment its own credentials, so a leak from staging does not touch production.
  • Store customers' API keys hashed, the way you would a password, and show the full value only once when it is created.
  • Support multiple active keys so customers can rotate without downtime, and let them revoke a key instantly.
  • Rotate your own secrets on a schedule and after any suspected exposure, and write down how to do it before you need to.
  • Always use HTTPS, with no fallback to plain HTTP.

Logging without leaking data

Logs are essential for investigating incidents and spotting abuse, but they are also a data store that people forget to protect.

Log security-relevant events: authentication successes and failures, authorisation denials, key creation and revocation, rate-limit hits, and unusual patterns. Include a request identifier, timestamp, account and endpoint so incidents can be traced end to end.

Do not log passwords, tokens, full API keys, payment details or entire request bodies by default. Mask or hash sensitive values. Set retention periods, restrict who can read logs, and check what privacy rules apply to personal data in them. Requirements differ by jurisdiction and change over time, so confirm with a qualified adviser.

Versioning and deprecation

Customers build their systems on your API, so changes can break them. A versioning policy is part of security too: old, forgotten endpoints are a favourite target because nobody maintains them.

  • Version the API from the first release, in the path or a header, and keep the rule consistent.
  • Make additive changes where possible, such as new optional fields, and reserve a new version for breaking changes.
  • Publish a deprecation policy: how much notice you give, how deprecated endpoints are flagged, and when they are removed.
  • Keep an inventory of all endpoints and versions, including internal and test ones, and switch off what is no longer used.
  • Document the API accurately, with examples, error codes and limits. Documentation that matches reality reduces misuse.

Putting it together

A short review checklist before any endpoint ships: who may call it, which object does it touch, what happens with unexpected input, how often can it be called, what does it log, and which version is it in. If you are designing an API for a customer-facing product and want a second pair of eyes, see software development in Israel, and for related design ideas read designing scalable, maintainable APIs for business systems and practices for maintainable .NET APIs.

Frequently asked questions

Should I use API keys or OAuth?

Use API keys for simple server-to-server access by a customer's own systems, with scopes, rotation and instant revocation. Use OAuth 2.0 when third-party applications act on behalf of your users, so users can grant and withdraw access without sharing passwords. Many SaaS products offer both, for different integration types.

How do I rate-limit a REST API?

Count requests per API key or account, and per IP for unauthenticated endpoints, within a time window or using a token-bucket approach. Set tighter limits on expensive operations, return HTTP 429 with retry guidance, and monitor hits. Many gateways and frameworks provide this built in, so you rarely need to write it yourself.

What should an API log?

Log authentication results, authorisation denials, key changes, rate-limit hits, errors and a request identifier, timestamp, account and endpoint. Avoid passwords, tokens, full keys, payment data and complete request bodies. Restrict access to logs, set retention periods and confirm which privacy rules apply to any personal data they contain.

Related articles

🚀 Start Now