Join our Newsletter — 33% off our NHI Course
Home› Guides› Leaked Source Code for Beginners: What Happens When…
Guide Secrets Management

Leaked Source Code for Beginners: What Happens When a Company’s Code Gets Out

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 1 December 2026 10 min read
On this page

A source code leak is when a company's private program code ends up where outsiders can read it.

This guide is for developers, managers and anyone who wants to know why a code leak is a big deal. You do not need to read code. If your organisation writes any software, even small scripts, this applies to you.

In short

  • Code leaks through attacks, open servers, weak or default credentials and repositories made public by mistake.
  • The code itself shows how products work, which helps attackers look for weak spots.
  • The bigger danger is often the secrets written into the code, such as keys and tokens that still open real systems.
  • Leaked code cannot be pulled back, but leaked secrets can be revoked and replaced.

What you will learn

  • Name the common ways source code leaks.
  • Explain why secrets in code cause more harm than the code itself.
  • Describe the first steps after a leak: revoke, rotate and remove.
  • Name simple habits that keep secrets out of code.
Source code
the human-readable instructions that make up a program.
Repository
a store, such as a Git server, that holds code and its full change history.
Secret
a password, key or token that lets software prove who it is and get access.

What is a source code leak?

Think of an architect's plans for a bank going missing. The plans show where the walls and doors are. That is bad, but it is worse if someone taped the vault key to the back page.

Leaked code works the same way. The code shows how a product works. But code often also holds secrets that software uses to reach other systems. A leading web security project notes that many organisations hardcode secrets in plain text in source code and configuration files [1].

Those secrets belong to software, not people. They are credentials for non-human identities, such as apps, scripts and build systems. A copied secret keeps working until someone revokes it [1].

Where the comparison stops working: a lost key can be found again. A leaked copy of code can be copied endlessly and spread to many places.

For the basics of keeping secrets safe, read Secrets Management for Beginners.

Why does it matter?

A code leak can expose ideas, weak spots and working keys all at once. How bad it gets depends mostly on what secrets were inside.

If you write code

What could happen: a key you pasted into a config file for a quick test is still in the history when the code leaks.

Check this: turn on secret scanning before you commit, so keys are caught early.

Next: Secret Scanning for Beginners

If you run code servers or IT

What could happen: a code server left online with a default password lets anyone copy everything.

Check this: confirm no code server accepts default credentials or open sign-up from the internet.

Next: Default Passwords for Beginners

If you lead a team or a company

What could happen: after a leak, nobody knows which keys were in the code or who owns them.

Check this: ask whether there is a plan for revoking and replacing every secret in a leaked repository.

Next: Leaked Secret Response for Beginners

What does it look like?

Here is a made-up settings file of the kind found in many leaked repositories. It shows where the real risk hides.

Example only. All values are made up.

# config.yaml for EXAMPLE-orders-service       (1)
db_host: db.example.invalid                     (2)
db_password: FAKE-not-a-real-password           (3)
payments_api_key: EXAMPLE-0000-0000             (4)
cloud_key_id: FAKE0000EXAMPLE                   (5)
  1. The file name and service. On its own, harmless.
  2. Where the database lives. Useful to an attacker, but not a way in by itself.
  3. A database password written straight into the file. In a real file, this line would contain a working password.
  4. A key for an outside payments service, which still works wherever the code ends up.
  5. A cloud key that could reach storage or servers.

Why this is risky: anyone with a copy of this file has working access. Old versions in the history hold the secrets too.

The safer way: keep secrets in a secrets manager and have the code fetch them at run time, so the code holds no keys.

How does it work?

  1. The code gets out. Common routes include attackers stealing it, a code server left open on the internet, or a repository made public by mistake.
  2. Copies spread. Leaked code can spread on forums and chat channels, as Nissan's did [4]. It cannot be recalled.
  3. People search it for secrets. Keys and tokens are easy to spot, because many have a set format [1].
  4. Secrets are tried. A secret that still works gives access to the system it was made for.
  5. The owner contains it. OWASP's response steps are revoke the exposed keys, rotate in new ones, remove them from code and logs, and check the logs for use [1].
Diagram titled Why secrets inside leaked code do the real damage. Four boxes in a row joined by arrows. Box 1, Code gets out: stolen by a group, an open server or a public repository. Box 2, What is inside: product logic, comments and designs, plus keys, tokens and passwords. Box 3, Secrets work: a copied key still opens the system it was made for until revoked. Box 4, Contain it: revoke and rotate every secret, then remove it and move to a vault. A note says code that leaks cannot be called back, but secrets can be switched off, and keeping secrets out of code means a code leak exposes ideas, not working keys.
Figure 1. The code cannot be recalled, but the secrets inside it can be switched off.

Two cases to learn from

Samsung, 2022: secrets in stolen code. Samsung said a breach involved some source code relating to the operation of Galaxy devices [2]. A secrets detection firm scanned the leaked code and reported 6,695 secrets, including 2,408 private keys [3]. It did not test whether the keys still worked [3]. See the Samsung source code leak case page.

Nissan North America, 2021: an open code server. A news report said the company's Git server was left online with the default username and password admin/admin [4]. The leaked code covered mobile apps, dealer systems and connected vehicle services [4]. See the Nissan source code leak case page.

A worked example

This story is made up to show the idea.

Jonah Thorne is head of engineering at a small delivery app company. On Friday a customer emails a link to a forum post. It contains a copy of one of the company's code repositories.

Jonah's first thought is the code. Then he remembers the settings files. He asks a developer, Bruno Rinaldi, to run a secret scanner over the leaked copy, including its full history.

Bruno finds nine secrets. There is a database password, two cloud keys, a payments key and several tokens for internal tools.

They work through the list in order of risk. Each secret is revoked, a new one is created and the services are updated. Bruno checks the logs for each old key and finds no use from unknown places.

Next they find the cause. A contractor's old account on the code server was never removed, and its password had been reused elsewhere. They remove the account and require a second factor for everyone.

Finally, they move all secrets into a secrets manager. The code now fetches them at run time, and a scanner blocks new secrets before each commit.

Jonah learned that the code itself was embarrassing but survivable. The secrets inside it were what needed action that same day.

Myths and mistakes

What people thinkWhat is true
A code leak only hurts our competitive edge.Secrets in the code can give working access. One scan of a leak found thousands[3].
Deleting the secret from the latest version fixes it.It stays in the history. OWASP says exposed secrets must be revoked and rotated, not just removed[1].
Our code is private, so secrets in it are safe.Private servers can be left open. Nissan's code server reportedly accepted a default password[4].
We can get the leaked copies taken down.Copies spread quickly. Treat every secret in the leak as exposed.
Only big companies have code worth stealing.Any code with working keys in it is worth stealing, whatever the size of the firm.

What can I do this week?

  • Run a secret scanner over one of your main repositories, including its history.
  • Check that your code servers do not allow default credentials or open sign-up.
  • List who has access to your code servers, and remove old accounts.
  • Read Leaked Secret Response for Beginners so you know the steps before you need them.

Checklist

  • I know the common ways code leaks.
  • I know secrets in code are often the biggest risk in a leak.
  • Our secrets live in a secrets manager, not in code or config files.
  • A scanner checks for secrets before code is committed.
  • Our code servers use strong sign-in and no default credentials.
  • We have a plan to revoke and rotate every secret in a leaked repository.
  • We check logs for use of any exposed secret.

Common questions

What should we do first if our code leaks?

Scan the leaked code, including its history, for secrets. Revoke and replace each one, starting with the most powerful. Then check the logs for use of the old secrets, find how the code got out and close that gap.

Is leaked code itself dangerous?

It can be. It shows attackers how a product works, which may help them find weak spots. But the most direct harm usually comes from working secrets found inside it, because they give access straight away.

Why do secrets end up in code?

It is often the quickest way to get something working. A developer pastes a key into a file to test, and it gets committed. OWASP notes that many organisations still hardcode secrets in source code and configuration files.

How do we keep secrets out of code?

Store them in a secrets manager and have software fetch them when it runs. Add secret scanning at the developer level, for example as a check before each commit. OWASP suggests this to catch secrets before they reach the repository.

Where next?

Ready for the detail? Read the practitioner guide: Source Code Leak Response Playbook. It sets out who does what, in what order, after code gets out.

Also useful:

Related NHI Mgmt Group resources: Secrets Management Guide, Secret Sprawl Measurement Guide and Default Passwords for Beginners.

Key terms

Source code leak
When a company's private program code ends up where outsiders can read it.
Hardcoded secret
A password, key or token written directly into code or config files instead of being kept in a secrets manager.
Git history
The full record of every past version of the files in a repository.
Secrets scanning
Automatically checking code and files for passwords, keys and tokens.
Secret revocation
Switching off a secret so it no longer gives access.
Secrets manager
A secure store that holds secrets and hands them to software when it runs.

Sources and further reading

  1. OWASP, "Secrets Management Cheat Sheet", OWASP Cheat Sheet Series. https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html (accessed 1 Dec 2026).
  2. The Register, report on the Samsung data theft quoting Samsung's statement, 7 March 2022. https://www.theregister.com/2022/03/07/samsung_lapsus_data_theft/ (accessed 1 Dec 2026).
  3. GitGuardian, "Samsung and Nvidia are the latest companies to involuntarily go open-source, potentially leaking company secrets", 9 March 2022. https://blog.gitguardian.com/samsung-and-nvidia-are-the-latest-companies-to-involuntarily-go-open-source-potentially-leaking-company-secrets/ (accessed 1 Dec 2026).
  4. Dark Reading, "Nissan Source Code Leaked via Misconfigured Git Server", January 2021. https://www.darkreading.com/risk/nissan-source-code-leaked-via-misconfigured-git-server (accessed 1 Dec 2026).

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.