Skip to main content
CriticalSecretsOWASP A07:2021CWE-798

How to fix: Google OAuth client_secret in source

Google client_secret values must never appear in client-side code.

Why it matters

An exposed OAuth client_secret lets an attacker impersonate your application in the OAuth flow, exchange authorization codes for access tokens, and access Google APIs (Drive, Gmail, Calendar) on behalf of any user who has authorized your app.

Google client_secret values must never appear in client-side code.

How to fix it

  1. 1Move client_secret to a server-only environment variable
  2. 2Use the OAuth Authorization Code flow with PKCE for browser clients (no client_secret needed)
  3. 3Rotate the secret immediately in Google Cloud Console if it has been exposed

Code examples

Server-only OAuth: store secret as env var

TypeScript
// Server-only: never import this in client components
import { google } from 'googleapis';

const oauth2Client = new google.auth.OAuth2(
  process.env.GOOGLE_CLIENT_ID,
  process.env.GOOGLE_CLIENT_SECRET,  // server-only env var
  process.env.GOOGLE_REDIRECT_URI
);

Public client: use PKCE, no client_secret

TypeScript
// For browser-based apps, use PKCE flow (no client_secret)
const authUrl = new URL('https://accounts.google.com/o/oauth2/v2/auth');
authUrl.searchParams.set('client_id', process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!);
authUrl.searchParams.set('response_type', 'code');
authUrl.searchParams.set('code_challenge_method', 'S256');
authUrl.searchParams.set('code_challenge', codeChallenge);  // PKCE

References

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

See every secrets check

Questions

How severe is Google OAuth client_secret in source?
VulnRadar rates this critical 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-google-oauth-client-secret, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Google OAuth client_secret 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.

Propose a checkHow a check is built

Scan your own site for google oauth client_secret in source

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

How to fix: Google OAuth client_secret in source | VulnRadar