Leaking secrets is like leaving your front door wide open. Most wonβt notice, but it only takes one bad actor to walk in and cause havoc.
Even a tiny leak can lead to a massive data breach. Consider these real-world examples:
Uber breach (2016)
One of the most catastrophic data breaches due to leaked secrets was the Uber breach in 2016. Hackers exposed the personal data of 57 million customers and drivers, including names, email addresses, and phone numbers.
The breach happened because attackers accessed Uberβs GitHub repository, where sensitive information, including AWS credentials, was stored. With these credentials, they gained access to Uberβs cloud servers and found a data archive containing personal information.
Equifax breach (2017)
The Equifax data breach exposed the personal information of 147 million people, including Social Security numbers, birth dates, and addresses. The breach occurred due to a vulnerability in a web application that Equifax failed to patch.
Additionally, sensitive data was stored in plaintext, and administrative credentials were compromised, allowing attackers to access and steal data over several months.
Capital One breach (2019)
In 2019, Capital One experienced a breach that exposed the personal information of over 100 million customers. A former AWS employee exploited a misconfigured firewall in Capital Oneβs cloud infrastructure, accessing to sensitive data stored on AWS S3.
The breach included Social Security numbers, bank account numbers, and credit scores. The incident highlighted the importance of securing cloud infrastructure and properly configuring access controls.
Adobe breach (2013)
Adobe experienced a massive data breach in 2013, affecting 38 million users. Hackers accessed Adobeβs servers and stole source code for several Adobe products, along with user information, including encrypted passwords and payment card details.
The breach occurred due to weak password storage practices and poor security controls. It demonstrated the risks of storing sensitive information without adequate encryption and access controls.
LinkedIn breach (2012)
In 2012, LinkedIn suffered a data breach that exposed the passwords of approximately 6.5 million users. The passwords were stored using a weak hashing algorithm without proper salt, making them easy to crack.
How do secrets leak?
- Hardcoded Values: Putting sensitive data directly in your code is risky. It happens more often than youβd think.
- Version Control: Even if you remove a secret, it might still exist in your Git history.
- Misconfigured Access: Accidentally exposing a private repository or granting too much access can spill your secrets.
Preventive measures
- Use Environment Variables: Keep sensitive information out of your codebase by storing it in environment variables.
- Regularly Scan Your Codebase: Regular scans can help catch potential leaks before they become a problem.
- Audit Your Git History: Regularly audit and clean up your Git history. Tools like git filter-repo can help remove sensitive data from past commits.
- Secure Access: Limit who can access your repositories and use two-factor authentication to add an extra layer of security
Gitleaks
Gitleaks is an open-source, free tool that I have no affiliation with. Itβs freely available and easy to use, making it a great choice for regular security checks.
Scanning Gitleaks repository with Gitleaks
To demonstrate Gitleaksβ effectiveness, I ran a scan on its own repository.
Gitleaks currently shows 38 leaks. You might be asking, how can a tool designed to find leaks have leaks itself? These are likely false positives, and the rules may need further tweaking to filter them out.
You can also use the -v (verbose) flag and get a full report.
Note: I replaced the actual secrets and personal details with asterisks ( * ) for privacy and security reasons.
What Gitleaks detected
The scan revealed multiple leaks, including API keys and tokens. For each finding, Gitleaks provided specific details:
- File: The file containing the sensitive information.
- Line Number: The exact line where the secret was found.
- Commit Hash: The unique identifier for the commit that introduced the secret.
- Author: The author of the commit.
These details are invaluable for understanding the context of the leak and taking corrective action. They help pinpoint when the leak occurred and who might be aware of it.
Scanning popular Github repositories with Gitleaks
Even well-maintained projects can have secrets accidentally committed. This demonstrates the importance of regularly scanning your repositories, regardless of the projectβs size or reputation.
rust-lang/rust
You read that right. Rust has 2,437 leaks, lol. Letβs be real here; the severity and legitimacy of some of them might vary. For example, this is reported as a security issue.
We canβt see the actual value of CACHES_AWS_ACCESS_KEY_ID here. Even if we did, it wouldnβt pose a threat since cache access key IDs alone arenβt valuable to malicious users.
This shows why itβs crucial to double-check the results from any tool. Not every reported leak is a real security issue. For example:
- over 2000 βleaksβ were DNA sequences formed entirely of the letters ACGT. The DNA sequences are in files like this one.
- 14 βleaksβ were non-sensitive IDs from the AWS token pair, found in .travis.yaml
- 2 βleaksβ were similar non-sensitive IDs in jobs.yml
Itβs crucial to customize tools like Gitleaks to reduce false positives and focus on genuine threats. When projects are this complex, reporting large numbers of potential leaks without proper analysis can lead to unnecessary alarm and confusion.
Proper use of Gitleaks: A case study with the Rust repository
To effectively use Gitleaks and minimize false positives, itβs essential to tailor the tool to your projectβs specific context.
Customizing gitleaks configuration
- Create a .gitleaks.toml configuration file
- Define rules and exceptions to refine the scan.
For example, if certain patterns (like DNA sequences or specific IDs) are not sensitive, they can be excluded.
- Run Gitleaks with the custom config: Use the βconfig flag to specify the custom configuration file.
- βsource ./rust: Specifies the directory of the Rust repository.
- βconfig .gitleaks.toml: Points to the custom configuration file.
- -v: Verbose mode for detailed output.
- βreport-path gitleaks-report.json: Specifies the output file for the report.
Analyzing the Results
After running Gitleaks with a tailored configuration:
The customized rules help eliminate common false positives, like non-sensitive IDs or known patterns. Feel free to tweak the rules and experimenting with the scanner too.
Preventing leaks with Gitleaks pre-commit hook
A pre-commit hook lets you run scripts before code is committed. Hereβs a quick setup for Gitleaks as a pre-commit hook:
- Install Gitleaks
- Create and Edit Hook Script:
-
βsource . Specifies the current directory as the source to scan. The . denotes the root of the current Git repository.
-
-v: Stands for verbose mode, which provides more detailed output during the scan process. It helps in understanding what the tool is doing and any findings it may encounter.
-
βreport-path gitleaks-report.json: Specifies the path and filename where the scan results will be saved in JSON format. In this case, the report will be saved as gitleaks-report.json in the current directory.
- Make Script Executable:
This setup scans the git changes for secrets before committing. If leaks are found, the commit is stopped, ensuring sensitive data stays out of your repository.
How to evaluate tools for finding leaks
-
Open-Source Nature: The tool should have its source code available. This lets the community check for unauthorized data transmissions.
-
Network Monitoring: Monitor network traffic during scans. Ensure the tool doesnβt communicate with external servers.
Your code is only as safe as your secrets. Donβt let a tiny leak sink your ship.