Skip to content

🔒 fix: Replace hardcoded API key with environment variable - #1401

Open
poliakarmai wants to merge 1 commit into
deep-learning-indaba:masterfrom
poliakarmai:fix/hardcoded-api-key
Open

🔒 fix: Replace hardcoded API key with environment variable#1401
poliakarmai wants to merge 1 commit into
deep-learning-indaba:masterfrom
poliakarmai:fix/hardcoded-api-key

Conversation

@poliakarmai

Copy link
Copy Markdown

📋 Summary

Hardcoded invoice-generator.com API key replaced with os.getenv("INVOICE_GENERATOR_API_KEY") — following the same pattern already used for GCP_API_KEY in api/app/utils/translation.py.

File: api/app/invoice/generator.py:12

Before:

_API_KEY = "sk_LexJK2eK0jY3Kmm9gE6R6nJ4M8RwrZpN"

After:

_API_KEY = os.getenv("INVOICE_GENERATOR_API_KEY")

📚 Understanding This Vulnerability

What is it?

Hardcoded credentials (API keys, passwords, tokens) stored directly in source code — visible to anyone with repository access.

Why it matters

If the code leaks (GitHub, laptop, backup), an attacker gains access to all services using those credentials. Hardcoded secrets are one of the OWASP Top 10 (A07:2021 — Identification and Authentication Failures) and the #1 cause of cloud breaches according to multiple industry reports.

When it happens

config.py, settings.py, example code, test fixtures with real data.

How to fix properly

  1. Environment variables: os.getenv("KEY_NAME")
  2. .env file (gitignored) for local development
  3. Secrets manager (AWS Secrets Manager, HashiCorp Vault) for production
  4. Rotate the exposed key immediately — treat it as compromised

🧠 Analogy

A house key under the doormat. Even if nobody sees it — one day someone will check.

📖 Further Reading


🐛 Found by GSC — understand your code, don't just accept it.

The invoice-generator.com API key was hardcoded in source code,
exposing it to anyone with repository access.

Fix: use os.getenv('INVOICE_GENERATOR_API_KEY') instead, following
the same pattern already used for GCP_API_KEY in translation.py.

Found by GSC (Git Security Checker)
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.

1 participant