Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Security Fix Summary

Issue Resolved

Critical Security Vulnerability: Gemini API key was embedded in static JavaScript files deployed to GitHub Pages, making it publicly accessible to anyone who inspected the website source code.

Evidence of Breach

  • Location: gh-pages branch, file assets/js/main.*.js
  • API key pattern found: [REDACTED]
  • Risk Level: CRITICAL - Full API access exposed

Solution Implemented

Migrated from insecure client-side API key to secure serverless proxy architecture using Netlify Functions.

Before (Vulnerable)

User Browser

Static HTML/JS (contains API key) ← EXPOSED TO PUBLIC

Gemini API

After (Secure)

User Browser

Static HTML/JS (no secrets)

Netlify Function (API key in environment) ← SERVER-SIDE ONLY

Gemini API

Technical Changes

1. Removed API Key from Build Process

File: docusaurus.config.js

- customFields: {
- GEMINI_API_KEY: process.env.GEMINI_API_KEY || '',
- },

2. Created Secure Proxy Function

File: netlify/functions/gemini-proxy.mjs (NEW)

  • Handles all Gemini API requests server-side
  • API key stored in Netlify environment (never sent to client)
  • Input validation: 10K char limit for messages
  • Secure error handling: no information disclosure
  • Debug logging: no sensitive data exposure

3. Updated Frontend

File: src/components/AutoBot/index.tsx

- const genAI = new GoogleGenerativeAI(apiKey); // Direct API call
+ const response = await fetch('/api/gemini-proxy', { // Proxy call

4. Added Netlify Configuration

File: netlify.toml (NEW)

  • Build configuration
  • Function routing: /api/*/.netlify/functions/*

Security Verification

Build Artifact Analysis

# Build without API key
yarn build

# Verify no API key in output
grep -r "AIza" build/ # No results ✅
grep -r "GEMINI_API_KEY" build/ # No results ✅

Security Scan Results

  • CodeQL: 0 alerts ✅
  • API Key Exposure: None found ✅
  • Information Disclosure: Prevented ✅

Deployment Requirements

Required Actions

  1. Create Netlify Account: https://netlify.com
  2. Connect Repository: Link ShaftHQ/shafthq.github.io
  3. Set Environment Variable:
    • Name: GEMINI_API_KEY
    • Value: Your Gemini API key
    • Scope: All deploys
  4. Deploy: Netlify auto-deploys from master branch

Post-Deployment Verification

  1. Visit deployed site
  2. Open AutoBot chatbot
  3. Send test message
  4. Check DevTools → Network tab
  5. Verify request goes to /api/gemini-proxy
  6. Inspect JavaScript bundles to confirm no API key present

Local Development

Setup

# Install dependencies
yarn install

# Install Netlify CLI
npm install -g netlify-cli

# Set up environment
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

# Run dev server with functions
netlify dev

Important: Use netlify dev instead of yarn start to enable Netlify Functions locally.

Migration Path

For detailed step-by-step migration instructions, see:

  • MIGRATION_GUIDE.md - Complete deployment guide
  • README.md - Updated setup instructions

API Key Recommendations

For Production (Netlify)

  1. Generate new API key in Google AI Studio
  2. Restrict to "Generative Language API" only
  3. Store in Netlify environment variables
  4. Do not add HTTP referrer restrictions (key is server-side)

For Testing (GitHub Actions)

  1. Add GEMINI_API_KEY to repository secrets
  2. Used only for running tests in CI/CD
  3. Never exposed in build artifacts

Old Key Action Required

Historical action: the exposed API key required immediate revocation.

  1. Go to Google Cloud Console
  2. Find the compromised key
  3. Delete or regenerate it immediately

Compliance Checklist

  • API key removed from source code
  • API key removed from build artifacts
  • API key removed from git history (in customFields, not hardcoded)
  • Secure storage implemented (Netlify environment)
  • Input validation added
  • Error messages sanitized
  • Security scan passed
  • Documentation updated
  • Migration guide created

Benefits Achieved

  1. Security: API key never exposed to clients
  2. Control: Server-side validation and rate limiting possible
  3. Monitoring: Centralized logging of API usage
  4. Maintenance: Easy to rotate keys without redeployment
  5. Compliance: Follows industry best practices

Support & Questions

  • Technical Details: See MIGRATION_GUIDE.md
  • Local Setup: See README.md
  • Issues: Open GitHub issue or contact team via Slack

Status: ✅ READY FOR DEPLOYMENT Security Level: 🔒 SECURE Action Required: Deploy to Netlify and revoke old API key