Infosec Watchtower Logo

Exposed Secrets in Open-Source Code: A Growing Threat in GitHub and PyPI

Charles M. Walls | April 11, 2024 | Views: 176

A dramatic digital illustration of a hacker at a computer with multiple screens showing code and API keys exposed.

GitGuardian has once again captured the attention of the tech community with its annual State of Secrets Sprawl report. The 2023 edition revealed a staggering 10 million passwords, API keys, and other sensitive data inadvertently exposed in public GitHub commits. Their 2024 report goes further, spotlighting an alarming 12.8 million new exposed secrets on GitHub, and shedding light on similar vulnerabilities within the Python Package Index (PyPI).

PyPI, the go-to hub for Python developers, houses over 20 terabytes of files that fuel countless Python projects worldwide. The convenience of fetching a package with a simple pip install command masks a critical vulnerability: the exposure of secrets within these packages. According to GitGuardian, a whopping 90% of production code relies on these open-source packages, making the implications of their exposure significant.

The 2024 GitGuardian report uncovers more than 11,000 newly exposed secrets, with PyPI contributing 1,000 of these in 2023 alone. While this number pales in comparison to GitHub's millions, the smaller scale of PyPI makes each exposed secret potentially more impactful. Among the lingering vulnerabilities, about 100 secrets dating back to 2017 were found still active, posing a persistent risk despite their age.

GitGuardian's sophisticated array of secret detectors, refined over the years, frequently identified exposed OpenAI API keys, Google API keys, and Google Cloud keys in the latest study. These discoveries highlight the ongoing challenge and the critical importance of robust security practices in software development.

Conventional wisdom in the development community holds that any key exposed in a public repository like GitHub or PyPI is compromised. GitGuardian’s tests with honeytokens—harmless API keys designed to detect unauthorized access—demonstrate that bots can verify these tokens within minutes of their public release. This rapid validation serves as a warning system for developers, signaling potential snooping through the telemetry data collected from the honeytokens’ use.

The consequences of an exposed secret extend beyond immediate unauthorized use, such as inflated cloud service bills. More severe is the potential for broader system access, leading to data breaches or compromised infrastructure. The best preventative measure upon discovering an exposed secret is immediate revocation, reducing the narrow window of opportunity for exploitation.

The risks are not confined to public repositories. Private repositories are equally vulnerable through social engineering and phishing attacks, underscoring the pervasive threat of exposed secrets. The enduring lesson is clear: Secrets embedded in source code will inevitably be uncovered, whether through accidental public exposure or illicit private access.

In conclusion, safeguarding your source code—whether stored in private repositories or published in public ones—requires adherence to strict security practices. Avoid storing plain text secrets in source code, limit secret permissions, and swiftly revoke any exposed secrets. Implementing automated tools like those offered by GitGuardian can help bridge the gap between human error and security best practices, potentially sparing developers the harsh lessons learned from leaked secrets.

Source of Inspiration