How to secure your API secret keys from being exposed? (2024)

API Security

Learn about the dangers of API secret key exposure and discover our selection of prevention strategies.

Alexandra Charikova

7 min read

How to secure your API secret keys from being exposed? (2)

The uncontrolled sprawl of exposed, insecure APIs puts sensitive personal and corporate data at high risk, as shown by the numerous data breaches like the T-Mobile hack ($350M fine in 2022), the Peloton data exposure in 2021, and many others.

However, in some cases, instead of the API itself being insecure, the main reason for the breaches is the leaking of API secret keys and tokens. The 2023 incidents, including the leaked Microsoft Account Consumer Key and the OpenSea third-party vendor breach, perfectly illustrate how secrets can be exploited in attacks (we'll show how below 😬).

The exposure of API secret keys, which authenticate and authorize requests to your API, to outsiders can jeopardize the security and privacy of your application and have a substantial financial impact - think $17M we discovered via one exposed Stripe token.

In this blog post, we dive into the nature of API secret keys, the risks associated with their exposure, and the potential repercussions for your business. More than that, we’ll share essential practices for securing your API secret keys against leaks in front ends - when it's too late. Adopting these strategies will help you protect your applications - which is a continuous journey anyway!

What are secret API keys?

Secret API keys are unique identifiers used by applications to authenticate and authorize access to an API. They serve as a form of authentication, allowing the API to verify the identity of the requesting application. These keys are typically kept confidential and should be securely managed to prevent unauthorized access to sensitive data or actions within the API.

Secret API keys serve as secure tokens to authenticate and authorize requests made to your API. They are deemed secret because their exposure to unauthorized individuals or the public could lead to security breaches. If a malicious entity gains access to your secret API key, they could potentially impersonate you, gaining the ability to access or alter your data, functionality, and resources.

What's the difference with the regular API keys you might ask yourself?

These secret keys are distinct from regular API keys, which primarily serve to identify you to the API. Unlike regular keys that are often transmitted in an unencrypted manner, such as within a URL’s query string or in the headers of a request, secret API keys encrypt your requests. These encrypted requests are then decrypted by the server using the matching secret key, ensuring that the request is indeed originating from you.

Moreover, some APIs opt for a dual-key security mechanism, incorporating a pair of keys like an API key and an App ID, or an API key and a secret. In such scenarios, both keys must be submitted with requests. However, only one is exploited for encryption purposes, while the other assists the server in retrieving the corresponding secret key for decryption. This dual-key approach fortifies security by enabling the server to verify both the requester’s identity and the request’s authenticity.

What causes API key exposure?

API key exposure is a grave security concern that arises from several practices. Identify and avoid the following common causes to protect your API keys:

  • Embedding API keys in code: This dangerous practice can unintentionally reveal your API keys to the public, especially if your code is shared on platforms like GitHub. If your code is accessible, so are your API keys, making them vulnerable to misuse by malicious actors.
  • Storing API keys in your application's source tree: Another hazardous approach is to store your API keys within your application’s source files. Such a practice makes your API keys vulnerable to being leaked if your source code control system is compromised or if it's publicly accessible.
  • Storying API keys in front-end code like Javascript: in our research 35% of the exposed secrets were found in a JavaScript file. Some developers opt to compile all code, including sensitive setup files, into a single extensive JavaScript file for convenience. However, this approach unwittingly exposes crucial secrets to unauthorized access, which is critical for the seamless operation and intercommunication of the application.
  • Sending API keys in plain text: A frequent oversight is transmitting API keys without encryption, leaving them exposed to anyone who might intercept your network traffic - this includes hackers, internet service providers, or government entities. To prevent this, always encrypt your API keys and use secure communication protocols like HTTPS when interacting with your API server.
  • Using the same API keys for multiple APIs or services: Employing the same API key across different services not only indicates poor design but also magnifies the consequences of a single API key exposure. An exposed key could jeopardize multiple services or APIs. Maintain separate API keys for each service and limit their use to necessary scopes and domains.

Steering clear of these common pitfalls can significantly lower the risk of your API keys becoming exposed, thus ensuring the security, privacy, and efficiency of your application.

💡

For more information, check out our report "The API Secret Sprawl" and learn how we discovered over 18,000 API secret tokens by analyzing 1 million domains on the web.

If you're not convinced of the dangers posed by leaked API secret keys, here are some examples for you:

  • In the case of Microsoft, a cyberattack involved the advanced persistent threat (APT) actor, Storm-0558, who gained access to unclassified email data from various government agencies. This was achieved by discovering a leaked Microsoft Account Consumer Key, which allowed the threat actor to forge access tokens to enterprise email accounts. This incident underscores the importance of secure handling and regular rotation of API keys and access tokens.
  • In February 2023, publicly accessible environment files were discovered on Lowe's Market website. These files leaked access tokens to AWS S3 buckets and API keys to third-party services. One of these leaked keys, GrocerKey API, allowed access to partial credit card information, addresses, and top-spending users, as well as the ability to send unsolicited orders, issue refunds, launch ad campaigns, reset passwords, and check in-store and in-app balances. Such exposure could potentially allow threat actors to access sensitive user information and manipulate website functionality.
  • In a more recent case,OpenSea, an NFT marketplace, notified their customers of a breachwith a third-party vendor. The data breach could have a significant impact since OpenSea is the second-largest non-fungible token (NFT) marketplace by trading volume (36.5%) after Blur (56.8%), which launched only a year ago. This incident highlights the risks associated with third-party integrations and the importance of securing API tokens that provide access to such services.

💡

Check out this article if you want to learn more about recent application security breaches.

How API key exposure can affect your business?

When your API keys are exposed, it could spell trouble for your business in a myriad of ways, both immediately and over time. Here are some of the potential repercussions:

  • Data breaches: If your API keys fall into the wrong hands, they can be used to access or alter your sensitive data. This includes customer information, financial details, or proprietary data. The consequences could range from data loss to identity theft, fraud, or even legal issues. Moreover, a data breach can severely harm your reputation and the trust you've built with your customers and partners.
  • API abuse: Exposed API keys open the door for attackers to exploit weaknesses in your API or carry out unauthorized actions. This could lead to the creation of fake accounts, data scraping, spamming of users, or even DDoS attacks. Such abuses can compromise your application’s security, disrupt its performance, and lead to potential downtime.
  • Financial loss: Attackers can use exposed API keys to generate costs on your behalf. This might involve using up your API resources, going over your allotted quotas, or triggering billing. The fallout can lead to unexpected expenses, wasted resources, or a decrease in profits, impacting your budget and financial planning. Just from simple 3-day research, we have accessed $20M in Stripe tokens; think what dangers experienced hackers might present!
  • Regulatory compliance: Using exposed API keys inappropriately can also lead to violations of regulatory obligations. This might mean exposing personal data, breaking contracts, or infringing upon laws, leading to fines, penalties, legal action, or sanctions. Your legal standing and credibility can be seriously affected. Regulatory bodies are only getting stricter and stricter each year - think PCI DSS 4.0.

Being aware of how API key exposure can impact your business underlines the critical importance of protecting your API keys and preventing their unauthorized disclosure.

Best practices to secure your API secret keys

Here are the essential steps to mitigate the risks of secret API keys exposure:

  • Centralize API keys and tokens management: Centralizing token management enables secure storage, access, and rotation. Consolidating all tokens in one location allows you to monitor their usage comprehensively, identifying potential vulnerabilities in your system.
  • Rotate API keys and tokens Regularly: Regularly rotating tokens mitigates the risk in case of compromise. For instance, AWS Secrets Manager supports the automated rotation of secrets.
  • Assign Tokens to Specific Teams or Services: Ensure that only necessary personnel or services have access to each token by assigning them to specific teams or services.
  • Create a Revocation Process: Establish a clear revocation process to promptly revoke tokens in the event of a compromise.
  • Grant Correct Permissions: Grant only the necessary permissions for each token to minimize potential damage.
  • Limit Token Scope: Restrict the access scope of each token within your system.
  • Monitor Usage Patterns: Keep a vigilant eye on how tokens are used to identify any unusual activity.
  • Educate Your Internal Teams: Ensure that all team members understand the importance of token security and adhere to best practices. Consider enhancing the security experience through gamification or implementing a Security Champion Program, following The Security Champion Program Success Guide.

These measures are crucial for protecting your API tokens and maintaining secure and compliant systems. For more detailed information, you can refer to the resources provided by AWS Secrets Manager and Hashicorp.

Conclusion

In this blog post, we've explored the importance of API secret keys, shedding light on their roles, the risks involved if they're exposed, and the substantial effects this exposure can have on your business.

But more than that, we've offered a selection of best practices to keep your API secret keys in check, minimizing the risk of leaks or theft.

These strategies will help you protect your API secret keys, ensuring both the safety of your applications and the security of your business operations.

Recognizing the crucial role that API secret keys play in the functionality and security of your app is essential.

Using an automated security testing tool like Escape can enhance your security posture by identifying issues in your exposed API endpoints and detecting any secret leaks, so you can start fixing them right away. Don’t wait until it’s too late!

Secure your APIs now!

💡 Want to learn more?

Check out the following articles and research:

  • Methodology: How we discovered over 18,000 API secret tokens
  • Top 6 API security testing tools in 2024: a full review
  • How to secure gRPC APIs
  • What is API Sprawl? Understanding the growing challenge of 2024 and how to navigate it
How to secure your API secret keys from being exposed? (2024)

FAQs

How to not expose API keys? ›

Back-End Proxy Server

One of the simplest ways to avoid exposing API keys is to never send them to the client in the first place. Instead, you can set up a lightweight back-end server to handle API requests on behalf of the front-end. Here's how it works: The client sends a request to your back-end server.

How to keep API keys secure? ›

Best practices to secure your API secret keys
  1. Centralize API keys and tokens management: Centralizing token management enables secure storage, access, and rotation. ...
  2. Rotate API keys and tokens Regularly: Regularly rotating tokens mitigates the risk in case of compromise.
Mar 1, 2024

How to secure a secret key? ›

Protecting against key leakage
  1. Use secure key management systems (KMS) to store secret keys. ...
  2. Grant access only to those who need it. ...
  3. Don't share secret keys using insecure means. ...
  4. Don't store keys in source code repositories (such as GitHub). ...
  5. Don't embed secret keys in applications.

How do I protect API keys in scripts? ›

TL;DR
  1. Store keys away from code, preferably in environmental variables.
  2. Use secure storage solutions with encryption.
  3. Rotate keys regularly and delete obsolete ones.
  4. Monitor key usage and set access limits.
  5. Train teams on API key security.
  6. Avoid exposing keys in public channels or repositories.
Oct 17, 2023

Should I hide my API key? ›

FAQ. Do I need to hide my API keys? API secret keys should never be put in a client-side code or should be hidden. However, read-only API keys won't pose any risk if you paste them into your JavaScript code that will commit in your browser.

How do I create a secure API key? ›

To generate a platform API key:
  1. Log in to the web client.
  2. From the toolbar, click your avatar.
  3. Click Profile and settings.
  4. Click API key > Generate new key.
  5. Click Generate.
  6. Click Copy and save your key somewhere safe. You cannot recover this key if you lose it.

How do I keep my keys secure? ›

How To Keep Your Keys Safe: 4 Basic Tips
  1. Leave your keys in an obvious place. You have a designated place for your keys, but somehow, you always end up putting them somewhere else. ...
  2. Make your keys stand out. ...
  3. Keep your keys on a leash. ...
  4. Use a smart key finder.

How do you keep private keys safe? ›

How Should Your Protect Your Private Key?
  • Use a Trusted Key Management System (KMS) A KMS is a centralized system that provides secure storage, management, and protection of cryptographic keys. ...
  • Encrypt the Private Key. ...
  • Back-Up Your Private Keys. ...
  • Limit Access. ...
  • Verification Monitoring.

How can you ensure your code is not exposing any secrets? ›

Regularly audit code repositories to ensure no secrets are exposed. Keep detection tools updated to benefit from the latest features and security improvements. Provide continuous training for developers on secure coding practices and the importance of secrets management to reinforce a security-conscious culture.

Should I store API keys in a database? ›

Just like passwords, API keys should not be directly stored in your database. Storing API keys directly in your database is bad practice and not secure. They should be hashed and/or encrypted first before being stored.

Where is the best place to store secret keys? ›

As part of your secrets-management system: you can store a secret in a secrets management system, such as facilities provided by a cloud provider (AWS Secret Manager, Azure Key Vault, Google Secret Manager), or other third-party facilities (Hashicorp Vault, Conjur, Keeper, Confidant).

How do you keep rest APIs secure? ›

The top five ways to build security into a REST API design are:
  1. Always use TLS encryption.
  2. Implement a sound and scalable authentication and authorization model.
  3. Don't include sensitive information in URLs.
  4. Narrowly define allowed RESTful API requests and responses.
  5. Implement continuous API discovery capabilities.
Nov 15, 2023

How do I protect my API from Unauthorised access? ›

API Security: Authorization, Rate Limiting, and Twelve Ways to Protect APIs
  1. Implement Strong Authentication Mechanisms. ...
  2. Ensure Strong Authorization Practices. ...
  3. Validate Inputs and Responses. ...
  4. Rate Limiting. ...
  5. Encrypt Data Transmitted over APIs. ...
  6. Monitoring and Logging. ...
  7. Perform Regular API Security Testing.
Nov 3, 2023

What are the best practices for API key authentication? ›

Summary of API authentication security best practices

Use secure vaults and rotation policies to handle API keys. Ensure that all API communications are encrypted using TLS. To mitigate cross-site attacks, only allow requests from known and trusted sources. Keep API components and authentication services up to date.

How do I hide API key in requests? ›

Backend Proxy

Probably the first solution that comes to mind is to upload the file to your backend service, and then from there, re-upload it into the third party's service. Well, at least this solution keeps the API key hidden on the server side.

How do I block access to API? ›

If you want to block all API requests from a specific application/user/specific IP address or to a specific API, you can use request blacklisting. Blocking can be done at two levels: Block production and sandbox access : API access is blocked with both production and sandbox keys.

How to hide API key in HTML? ›

Hide API Keys
  1. If you have already pushed commits with sensitive data, follow this guide to remove the sensitive info while. ...
  2. In the terminal, create a config.js file and open it up: ...
  3. In the config file, enter your API keys in an object like so (naming them whatever you like, and putting the keys in.

Top Articles
How Long Does It Take to Format an External Hard Drive [Full Guide]
1.5 Planning, Organizing, Leading, and Controlling – Principles of Management
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 5650

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.