Secret in a URL
Secret in a URL. Puts a credential in a query string, where proxies, logs and browser history keep it.
This is how the comment reads inline, under the flagged line.
Why it matters
URLs are logged everywhere: load balancers, CDNs, analytics, referrer headers.
What to do
Send it in an Authorization header.
Examples
fetch(`${BASE}/items?api_key=${key}`)fetch(`${BASE}/items`, { headers: { Authorization: `Bearer ${key}` } })What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
fetch(`${BASE}/v1/items?api_key=${key}`);Left alone
fetch(`${BASE}/v1/items?page=${n}`);Research
Tokens or keys in URL query strings. Proxies, server logs and browser history keep the URL.
- skill: code-review
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"secret-in-url"
],
"severity": {
"secret-in-url": "low"
}
}
}