Skip to content

Security: chaitanyakumar-d/upstox-chatbot

Security

SECURITY.md

πŸ”’ Security Guide - Protecting Your API Keys

⚠️ CRITICAL: Never Commit Secrets to GitHub!

This project uses sensitive credentials that should NEVER be pushed to GitHub or any public repository.

πŸ›‘οΈ What's Protected

Your .gitignore file protects:

  • βœ… .env - Contains your actual API keys (NEVER committed)
  • βœ… .venv/ - Python virtual environment
  • βœ… __pycache__/ - Python bytecode
  • βœ… *.log - Log files

βœ… What's Safe to Commit

  • βœ… .env.example - Template with placeholders only
  • βœ… Source code files (*.py)
  • βœ… requirements.txt
  • βœ… README.md
  • βœ… Dockerfile, docker-compose.yml

πŸ” Pre-Push Security Check

Always run this before pushing to GitHub:

./check_secrets.sh

This script checks for:

  • API keys accidentally committed
  • Real credentials in .env.example
  • Missing .gitignore file

πŸ“‹ Step-by-Step: Safe GitHub Push

1. Initial Setup (First Time Only)

# Initialize git
git init

# Add remote (replace with your GitHub repo)
git remote add origin https://github.com/yourusername/upstox-chatbot.git

2. Before Every Push

# Run security check
./check_secrets.sh

# If check passes, add files
git add .

# Commit
git commit -m "Your commit message"

# Push
git push origin main

🚨 If You Accidentally Committed Secrets

Option 1: Remove from Last Commit

# If you just committed but haven't pushed
git reset HEAD~1
git add .gitignore .env.example  # Add only safe files
git commit -m "Initial commit"

Option 2: Remove from Git History (Already Pushed)

# Remove .env from git tracking
git rm --cached .env

# Commit the removal
git commit -m "Remove .env from tracking"

# Push
git push origin main --force

⚠️ Important: If secrets were already pushed publicly, consider them compromised:

  1. Revoke the exposed API keys immediately
  2. Generate new keys from provider dashboards
  3. Update your local .env file

πŸ” Where to Store Secrets (Production)

For production deployments, use:

  1. Environment Variables (Recommended)

    export UPSTOX_API_KEY="your_key"
    export GOOGLE_API_KEY="your_key"
  2. Secret Management Services

    • AWS Secrets Manager
    • Google Cloud Secret Manager
    • Azure Key Vault
    • HashiCorp Vault
  3. Docker Secrets (for Docker deployments)

    docker run --env-file .env.production your-image

πŸ“¦ Docker Security

When using Docker, never include .env in your image:

# βœ… Good - .dockerignore prevents this
COPY . /app

# ❌ Bad - Never do this
COPY .env /app/.env

Use environment variables or Docker secrets instead:

# Pass secrets at runtime
docker run -e UPSTOX_API_KEY=$UPSTOX_API_KEY your-image

πŸ”„ Rotating API Keys

Regularly rotate your keys:

  1. Upstox API Keys

  2. Google Gemini API

  3. Access Tokens

    • Upstox tokens expire daily
    • Re-run python upstox_auth.py to refresh

βœ… Security Checklist

Before pushing code:

  • Ran ./check_secrets.sh - all checks passed
  • Verified .env is in .gitignore
  • Checked .env.example has no real credentials
  • Reviewed git status - no sensitive files staged
  • Confirmed no API keys in code comments
  • Tested locally after pull to ensure .env not lost

πŸ“š Resources


Remember: The only secret you can share is .env.example with placeholders! πŸ”’

There aren’t any published security advisories