VOOZH about

URL: https://thenewstack.io/4-api-security-best-practices/

⇱ 4 API Security Best Practices - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-07-12 05:50:12
4 API Security Best Practices
sponsor-curity,sponsored-post-contributed,
API Management / Security

4 API Security Best Practices

By adding an API gateway and using OAuth or OpenID Connect to base authorization on access tokens, you can mitigate a bunch of top API security risks.
Jul 12th, 2024 5:50am by Judith Kahrer
👁 Featued image for: 4 API Security Best Practices
Image from SWKStock on Shutterstock.
Curity sponsored this post.

APIs are the backbone of modern digital solutions. Consequently, API security should be a top business concern. Yet, as with developing businesses, there is always something that you can improve with regard to API security. Therefore, do not consider this article a comprehensive guide but an inspiration on where to start. If you consider the following two bullet points, you will have a good foundation for your API security to build upon:

  • Use an API gateway.
  • Use access tokens for authorization.

Let me elaborate on their benefits and show examples of how you can evolve your API security.

1. Use an API Gateway

When going live and exposing an API, place an API gateway in front of it. The API gateway then serves as a single entry point to your API (or APIs). As a result, you can use it to enforce common policies. For example, you can ensure that all publicly available endpoints support HTTPS.

HTTPS uses an encrypted communication channel (TLS). However, TLS is not limited to HTTPS. I recommend using TLS for any protocol that runs on TCP. This way, you can encrypt data in transit, protect it from eavesdropping and thus avoid (some) unauthorized access to the data you expose via your API.

HTTPS is scarcely the bare minimum of securing an API. You should also consider implementing authentication and authorization. Use a protocol like OAuth or OpenID Connect for that purpose. Both protocols allow you to delegate access to your API with the help of an access token while keeping trust management central.

2. Use Access Tokens for Authorization

In practical terms, the access token commonly implies a JSON Web Token (JWT) format. At its core, a JWT is a signed JSON object that conveys information about an access grant in a verifiable manner. In OAuth, the authorization server is central for processing and communicating that grant. It is the authorization server’s responsibility to add accurate data to the access token and sign it.

Carefully Design JWTs

JWTs are a handy tool for API authorization. They can carry all necessary information for your API and its microservices to apply access rules and grant or deny a request. One thing you should spend time on is sketching out what information your API needs for its rules. This exercise is called the token design. As part of designing the token, make sure you use an asymmetric signature algorithm.

Asymmetric signatures provide nonrepudiation, which implies that only one authority, the authorization server, can issue the access token because it is the only authority with access to the required keys. Using asymmetric signatures, you can be sure that the authorization server issued the access token and not any other party. This is how you can build trust in technical terms.

Validate JWTs

Once you know what to expect from an access token, you are ready to integrate. Use the API gateway for coarse-grained access control. It should reject any request that is obviously malformed, like when it is missing the access token or when it includes an invalid token. An invalid token can also be a token that does not have the appropriate scope for the request. JWT security best practices include the following:

  • Always validate the access token.
  • Specify and check expected values for the following:
    • signature algorithm
    • issuer (identifier of the authorization server)
    • audience (identifier for your API)
  • Validate time-based claims, such as:
    • expired
    • issued at
    • not-before
  • Do not trust values in JWT header parameters.

Be cautious if you depend on JWT header parameters to load the key material. For example, only load referenced keys of the kid parameter from a trusted source such as a configured URL (JSON Web Key Set URI, jwks_uri) or, alternatively, use discovery mechanisms like OpenID Connect Discovery. As mentioned, the key is essential for building trust, so you must be careful. Once you have validated the syntax of the JWT, you can validate the signature and, if successful, use the claims to process the access rules.

3. Avoid Common Risks

With an API gateway and access tokens for authorization, you can avoid common API security risks. For example, among OWASP top 10 you can find the following items:

  • Broken object-level authorization (BOLA)
  • Broken user authentication (BUA)
  • Broken object property-level authorization (BOPLA)
  • Unrestricted resource consumption
  • Unrestricted access to sensitive business flows

You can configure rate limiting in the API gateway and thus avoid unrestricted resource consumption. In addition, the API gateway can require an access token on all requests by default. In combination with having the API validate the access token on every request and base its access control on the claims within the token, you can avoid both broken object-level authorization and broken object property-level authorization.

With OAuth, the authorization server takes over important and difficult security work. Among other things, it authenticates users, which minimizes broken user authentication due to flaws in proprietary implementations. You can enable multifactor authentication at the authorization server to mitigate the risk of unrestricted access to sensitive business flows.

4. Evolve API Security

By adding an API gateway and using OAuth or OpenID Connect to base authorization on access tokens, you can mitigate a bunch of top API security risks. Furthermore, you can evolve your architecture in a scalable manner. For example, implement and combine best practice patterns like the privacy-preserving phantom token pattern or the token handler pattern for browser-based applications. All you need to kick off is an API gateway and access tokens for authorization.

Curity is a leading IAM and API security technology provider that enables user authentication and authorization for digital services. The Curity Identity Server is highly scalable, handles the complexities of the leading identity standards, making them easier to use, customize and deploy.
Learn More
The latest from Curity
TRENDING STORIES
Judith is a Product Marketing Engineer, with a keen interest in security and identity. She started her working life as a developer and moved onto being a security engineer and consultant before joining the Curity team.
Read more from Judith Kahrer
Curity sponsored this post.
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.