Skip to main content
MediumCodeOWASP A07:2021CWE-798

How to fix: Hard-coded secret in source (client-exposed key)

A Discord webhook URL, Sentry DSN, or Mapbox public token is embedded in the source. These formats are designed by their vendors to be used from client-side code and are secured through restrictions (URL allowlists, write-only scopes) rather than secrecy, so presence alone is expected, not a leak.

Why it matters

A leaked Discord webhook lets anyone post messages to the target channel (spam or impersonation). An unrestricted Sentry DSN or Mapbox token can be abused to exhaust your event or request quota. None of these expose stored data or grant account access on their own.

These are the same category of finding this codebase already scores as medium elsewhere (google-api-key-exposed, secret-google-maps-api-key): a client-exposed-by-design identifier, not a secret whose security model depends on staying hidden.

How to fix it

  1. 1Restrict the credential where the vendor supports it (Mapbox URL restrictions, Sentry allowed origins)
  2. 2Rotate the Discord webhook if it is receiving unexpected traffic
  3. 3Move the credential server-side if your usage does not actually require client-side access

Code examples

Proxy a Discord webhook through your own backend instead of exposing it client-side

TypeScript
// Client posts to your own API, never the Discord webhook URL directly
export async function POST(req: Request) {
  const payload = await req.json();
  await fetch(process.env.DISCORD_WEBHOOK_URL!, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload),
  });
  return Response.json({ ok: true });
}

References

Detected automatically by VulnRadar. The check id is hardcoded-secrets-client-exposed, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is Hard-coded secret in source (client-exposed key)?
VulnRadar rates this medium severity in the code 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 hardcoded-secrets-client-exposed, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Hard-coded secret in source (client-exposed key) 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.

Propose a checkHow a check is built

Scan your own site for hard-coded secret in source (client-exposed key)

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Hard-coded secret in source (client-exposed key) | VulnRadar