How to fix: Perplexity API key in source
Perplexity API keys (pplx-*) grant billable access to Perplexity's chat completion / search endpoints.
Why it matters
An exposed Perplexity API key lets an attacker consume your chat completion and search quotas without restriction, incurring billable usage charges and potentially exhausting rate limits your own application depends on.
Perplexity API keys (pplx-*) grant billable access to Perplexity's chat completion / search endpoints.
How to fix it
- 1Revoke the key at perplexity.ai → Settings → API
- 2Set a usage/spend limit on the account to cap potential abuse
- 3Keep Perplexity API calls server-side only; proxy browser requests through your own API route
Code examples
Next.js: proxy Perplexity through a server route
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const { query } = await req.json();
const res = await fetch('https://api.perplexity.ai/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PERPLEXITY_API_KEY}`, // server-only
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'sonar',
messages: [{ role: 'user', content: query }],
}),
});
return NextResponse.json(await res.json());
}References
Detected automatically by VulnRadar. The check id is secret-perplexity-api-key, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is Perplexity API key in source?
- VulnRadar rates this high severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-perplexity-api-key, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Perplexity API key in source map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.