Skip to content

fix(security): remove hardcoded API key and add secure env configuration#17

Open
KGFCH2 wants to merge 1 commit into
omroy07:mainfrom
KGFCH2:fix/security-remove-hardcoded-api-key
Open

fix(security): remove hardcoded API key and add secure env configuration#17
KGFCH2 wants to merge 1 commit into
omroy07:mainfrom
KGFCH2:fix/security-remove-hardcoded-api-key

Conversation

@KGFCH2
Copy link
Copy Markdown
Contributor

@KGFCH2 KGFCH2 commented Jun 2, 2026

Related Issue

Closes #16

Summary

Removes a hardcoded Google Gemini API key from chatbot.py and replaces it with a secure environment-variable lookup. Adds .env.example and .gitignore to prevent future credential exposure.

Changes Made

  • Replace API_KEY = "AIzaSy..." with os.environ.get("GEMINI_API_KEY")
  • Raise EnvironmentError at startup if GEMINI_API_KEY is not set
  • Add FLASK_DEBUG environment variable (defaults to false)
  • Add .env.example documenting all required environment variables
  • Add comprehensive .gitignore covering Python, Node.js, OS files, and .env
  • Sanitize error responses — no raw exception details sent to clients

Testing

  • Verified chatbot.py raises EnvironmentError when GEMINI_API_KEY is unset
  • Verified normal operation with GEMINI_API_KEY set in shell environment
  • Verified .gitignore correctly excludes .env files

Impact

Eliminates a critical security vulnerability. The compromised key must be revoked at https://console.cloud.google.com/apis/credentials

Checklist

  • Code follows project standards
  • Tested locally
  • No unrelated changes included
  • No secrets committed
  • Responsive design verified (N/A — backend change)

- Replace hardcoded GEMINI_API_KEY with os.environ.get() lookup
- Raise EnvironmentError at startup if key is missing (fail-fast)
- Sanitize error responses to avoid leaking exception details to clients
- Add FLASK_DEBUG env var support; disable debug in production by default
- Add .env.example template documenting all required environment variables
- Add comprehensive .gitignore to prevent secrets and generated files
  from being accidentally committed to version control

Security impact: The previously committed API key (AIzaSyCHaO_...) must
be revoked immediately at https://console.cloud.google.com/apis/credentials

Fixes: hardcoded credential exposure in chatbot.py
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 2, 2026

@KGFCH2 is attempting to deploy a commit to the Om Roy's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

🔒 [Security] Hardcoded Google Gemini API key exposed in source code

1 participant