VOOZH about

URL: https://thenewstack.io/how-to-prevent-secrets-from-creeping-into-code/

⇱ How to Prevent Secrets from Creeping into Code - 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-03-25 06:13:00
How to Prevent Secrets from Creeping into Code
sponsor-sonarsource,sponsored-post-contributed,
Security / Software Development

How to Prevent Secrets from Creeping into Code

Hardcoding corporate secrets in code is a serious security risk that can be avoided.
Mar 25th, 2024 6:13am by Robert Curlee
👁 Featued image for: How to Prevent Secrets from Creeping into Code
Featured image by  东旭 王 on Unsplash.
Sonar sponsored this post. Insight Partners is an investor in Sonar and TNS.

All too often, secrets are found in released code, exposing the owner to security risks. These secrets include passwords, API keys, encryption keys, tokens, database credentials and other private company information.

Having hardcoded secrets in source code is dangerous, and despite developers’ most serious efforts, secrets can still creep in. Developers may take shortcuts while writing code and pass secrets into it, or they may not recognize the impact of the secrets in their code. Also, most scanning solutions leave it up to the developer to determine why their code is flagged for an issue. Finally, most tools look for secrets in code repositories, after the leakage has occurred, which requires painful remediation (i.e., rotating the secret).

Properly managing, storing and securing secrets can be complicated, misunderstood or simply skipped due to time constraints. In addition, if companies don’t know when and where secrets enter projects, they can’t prevent releasing them with the project and compromising their security.

Credentials and other secrets that creep into code regularly make news headlines — and the number of exposures is increasing due to human error. Tools that catch secrets in the IDE and throughout the CI/CD pipeline — before they have the chance to cause issues — are game changers.

Understanding How Secrets Get in Code

Being able to detect secrets before they are leaked in code enables organizations to reduce their risk exposure. By detecting them in the IDE, you can avoid the pain of having to remediate them by rotating the secret. But first you need to understand how secrets end up in code at all. Some reasons are:

1. Lack of Knowledge

Possibly due to inexperience or improper training, some developers simply may not be aware of proper secrets management and source code security. It takes only one developer being unaware of best practices for handling secrets in code to put a company in the hands of a threat actor. If knowledge is power, then the best line of defense is a knowledgeable team.

2. By Mistake

A developer may temporarily hardcode credentials or confidential information for a quick local test, with the intention to remove them afterward. However, sometimes those files are accidentally committed to a public repo, making those temporary changes permanent. Even if the code is deleted afterward, someone could have made a copy that contains the secret before it was cleaned up. To err is human, but when the consequences can have a potentially massive impact, it’s best to proactively prevent mistakes as much as possible.

3. Blind Trust

Problem-solving on your own is a great way to learn, and sometimes the problem is so specific that the only way to approach it is by hacking it yourself. If it’s eating up a lot of time and you aren’t finding a solution, it’s better to look for help from a mix of product documentation and sites like Stack Overflow. However, while these materials offer useful explanations and examples, they should not be simply copied and pasted and trusted at face value.

Code on Stack Overflow and in documentation can answer questions, but it’s not the most secure way to achieve a solution. For example, documentation often includes snippets of code to illustrate a product’s features but may not mention whether it should be used carefully and whether there’s a more secure option. Result? Bad code. Any solution you pull into the codebase should be properly assessed to confirm it’s aligned with quality standards and won’t bring issues into the code.

Another trust issue leading to secrets leaking into code is the increased use of AI-generated code. As generative AI becomes increasingly popular for code development, you can expect the number of lines of code that need to be scanned and the number of issues with secrets to increase. AI-generated code can lead you to think that the right way to connect to a service is to hardcode the token or secret. Depending on the quality of the prompt and the awareness of this problem, the AI may not produce clean code, and it can lead to secrets leaking. AI-generated code can be a good basis for understanding how to connect to a service, but you must modify it to use a secrets vault.

Ultimately, you must challenge any code you find or generate with AI. Organizations must ensure their developer teams have the proper code-quality tooling to prevent secrets from creeping into code and to resolve any that do leak as early as possible in code development.

Catch Secrets from the Start

When an exposed secret is flagged at the point of introduction, whether in real time during coding or when it is about to be committed, it can save teams a lot of trouble. Human error happens, but with the right checks at the right time, you can prevent the error’s repercussions early on.

The best place to detect and address these issues in the development workflow is at the very beginning, in the IDE. Secrets detection capabilities in SonarLint, SonarQube and SonarCloud enable organizations to detect publicly known secrets in source code, eliminate their leakage and reduce the security risk of illicit or unsanctioned access to private data. Developers using SonarQube Enterprise Edition 10.3 and above can also create custom secret pattern detection rules. Pairing them with Clean as You Code (CaYC) and Learn as You Code approaches support delivery of clean code — code that produces maintainable, reliable and secure software.

By eliminating secrets in code in the IDE from the start of development, teams can prevent secrets from entering their repository. Detecting and removing secrets early in project development reduces complicated and costly remediation required when exposed secrets are discovered late in the release cycle.

Sonar is the industry standard for code verification and automated code review, trusted by 75% of the Fortune 100. Its SonarQube platform analyzes over 750 billion lines of code daily, helping to prevent outages, reduce risk, lower technical debt, and ensure compliance.
Learn More
The latest from Sonar
Hear more from our sponsor
TRENDING STORIES
Robert Curlee is a software product management leader with 18 years of experience working in the Enterprise IT Services Management, IT Operations, Storage, and Security markets. Having started his career in software engineering, he currently serves as Product Marketing Manager...
Read more from Robert Curlee
Sonar sponsored this post. Insight Partners is an investor in Sonar and TNS.
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.