Skip to main content
LowSecretsOWASP A05:2021CWE-200

How to fix: PostHog project API key in source

PostHog project API keys (phc_*) are write-only capture keys meant to ship in client bundles. The risk is event-quota/data-poisoning abuse, not read access to analytics data.

Why it matters

PostHog project API keys (phc_*) are intentionally public: the browser snippet cannot capture events without shipping one. The residual risk is that anyone with the key can submit arbitrary fake events, polluting your analytics and dashboards or exhausting your event quota. This key cannot read stored data; that requires a separate personal API key (phx_*), which must stay server-side.

PostHog project API keys (phc_*) are write-only capture keys meant to ship in client bundles. The risk is event-quota/data-poisoning abuse, not read access to analytics data.

How to fix it

  1. 1Confirm only the phc_* project key ships to the client; never expose a phx_* personal API key in client code
  2. 2Enable autocapture/event allow-listing in PostHog project settings to reduce the value of spoofed events
  3. 3Monitor event volume for anomalies and rotate the project key if you see abusive traffic

Code examples

PostHog init: phc_* key is expected in client code

TypeScript
// instrumentation-client.ts: shipping the project key to the browser is normal
import posthog from 'posthog-js';

posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, { // phc_*, public by design
  api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
});

// Never do this client-side: phx_* personal API keys can read all project data
// posthog.init(process.env.POSTHOG_PERSONAL_API_KEY!) -- WRONG, server-only

References

Detected automatically by VulnRadar. The check id is secret-posthog-project-api-key, stable across every scan so you can filter or diff on it.

See every secrets check

Questions

How severe is PostHog project API key in source?
VulnRadar rates this low 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-posthog-project-api-key, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does PostHog project API key in source map to?
It maps to CWE-200. In the OWASP Top 10 it falls under A05: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 posthog project api key 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: PostHog project API key in source | VulnRadar