Skip to content

🔒 [security] Fix hardcoded PostHog API key#369

Open
jbhannah wants to merge 1 commit intotrunkfrom
security-fix-hardcoded-posthog-key-14109616286549088816
Open

🔒 [security] Fix hardcoded PostHog API key#369
jbhannah wants to merge 1 commit intotrunkfrom
security-fix-hardcoded-posthog-key-14109616286549088816

Conversation

@jbhannah
Copy link
Copy Markdown
Owner

🎯 What: The vulnerability fixed
Hardcoded PostHog API key in web/src/App.tsx.

⚠️ Risk: The potential impact if left unfixed
Exposure of API keys in source control can lead to unauthorized use of the analytics account, data manipulation, or exhaustion of usage quotas.

🛡️ Solution: How the fix addresses the vulnerability
The hardcoded key was replaced with a reference to an environment variable (import.meta.env.PUBLIC_POSTHOG_KEY). A template .env.example file was added to document the requirement, and TypeScript definitions were added to ensure type safety.


PR created automatically by Jules for task 14109616286549088816 started by @jbhannah

Removed the hardcoded PostHog API key from the frontend application and
replaced it with an environment variable.

Changes:
- Modified `web/src/App.tsx` to use `import.meta.env.PUBLIC_POSTHOG_KEY`.
- Created `web/.env.example` to document the required environment variable.
- Added `web/src/env.d.ts` for TypeScript type safety of environment variables.

Co-authored-by: jbhannah <179194+jbhannah@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pkpw Ready Ready Preview, Comment Mar 14, 2026 6:31am

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a hardcoded PostHog project key from the Preact web frontend and replaces it with an environment-variable-based configuration to avoid committing keys to source control.

Changes:

  • Replaced the hardcoded PostHog key in App.tsx with import.meta.env.PUBLIC_POSTHOG_KEY.
  • Added a TypeScript env declaration file to type the expected environment variable.
  • Added web/.env.example to document the required configuration.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
web/src/App.tsx Switches PostHog initialization to use an env-provided key instead of a committed literal.
web/src/env.d.ts Introduces TypeScript typings for import.meta.env.PUBLIC_POSTHOG_KEY.
web/.env.example Documents the required env var for local/dev/prod configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread web/src/App.tsx
Comment on lines +12 to 16
const POSTHOG_KEY = import.meta.env.PUBLIC_POSTHOG_KEY;

const App = () => (
<PostHogProvider apiKey={REACT_APP_PUBLIC_POSTHOG_KEY} options={options}>
<PostHogProvider apiKey={POSTHOG_KEY} options={options}>
<div class="min-h-screen w-full flex flex-col">
Comment thread web/src/App.tsx

const REACT_APP_PUBLIC_POSTHOG_KEY =
"phc_6rKhMfbzpccKI3EcDXbng8EuP7h2FC2rQga9nRBV8G";
const POSTHOG_KEY = import.meta.env.PUBLIC_POSTHOG_KEY;
Comment thread web/.env.example
@@ -0,0 +1 @@
PUBLIC_POSTHOG_KEY=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants