How I Used a Custom Regex Rule to Find Valid API Keys
A Brave Search API key was committed to a public repository, and the author found it by writing a custom regex rule for Gitleaks. The key was valid and allowed unauthorised API calls, potentially exhausting quota and incurring costs.
medium.com
Published on medium.com
I came across the Brave Search API which allowed developers to integrate Brave’s search capabilities into their applications. Documentation : Link
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
The key allowed unauthorised API calls that could exhaust the query quota and incur financial costs for paid plans; the key was later invalidated.
What the attacker needed
Public repository containing the key; custom regex rule for the key format
The fix
The key was revoked, as shown by the later invalid token error.
How it was found
- Sign up for the Brave Search API free tier to learn the key format.
- Write a custom Gitleaks rule using a regex for the key prefix.
- Clone an in-scope repository and run Gitleaks with the custom rule.
- Validate the found key by calling the Brave Search API video endpoint.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
An API key is like a password that lets a program use a service. Someone accidentally saved a Brave Search API key in a public code repository, so anyone could find it and use it to make searches on Brave's behalf. The author wrote a pattern-matching rule to spot keys that start with a specific prefix.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.