This document outlines the security measures implemented in The Republic project and best practices for maintaining security.
- API keys hardcoded in
frontend/.env.production - Keys exposed in client-side JavaScript bundles
- Anyone could extract and abuse API keys
- All API keys removed from frontend
- API keys stored only in backend environment variables
- Backend proxy endpoints handle API calls
- Keys never exposed to client-side code
Implementation:
- Backend proxy for Semantic Scholar:
/api/semantic-scholar/* - Frontend config updated to use backend proxy
.env.productionadded to.gitignore
- Server started without checking required variables
- Silent failures when keys missing
- Placeholder values not detected
- Startup validation checks all required environment variables
- Warns about missing optional keys
- Exits with error if placeholder values detected
- Clear error messages guide configuration
Location: backend/src/index.js
.env.productionnot in.gitignore- Risk of committing secrets to repository
- All environment files properly ignored
.env.production.exampletemplate provided- Clear documentation in templates
DO:
- ✅ Store all secrets in
.envfiles - ✅ Use
.env.exampleas templates - ✅ Keep
.envfiles in.gitignore - ✅ Use different keys for dev/staging/production
- ✅ Rotate API keys periodically
DON'T:
- ❌ Hardcode API keys in source code
- ❌ Commit
.envfiles to Git - ❌ Share API keys in chat/email
- ❌ Use production keys in development
- ❌ Store keys in frontend environment variables (anything with
VITE_prefix)
DO:
- ✅ Generate unique wallets for each environment
- ✅ Use hardware wallets for production
- ✅ Encrypt private keys at rest
- ✅ Limit private key access to necessary services
DON'T:
- ❌ Log private keys to console (except in dev wallet generators)
- ❌ Store private keys in plain text
- ❌ Reuse private keys across projects
- ❌ Share private keys between team members
DO:
- ✅ Use backend proxies for all external API calls
- ✅ Implement rate limiting
- ✅ Validate all input parameters
- ✅ Use HTTPS for all requests
- ✅ Monitor API usage for abuse
DON'T:
- ❌ Expose API keys in client-side code
- ❌ Allow direct API access from frontend
- ❌ Trust user input without validation
- ❌ Log sensitive data
DO:
- ✅ Use Vercel/Netlify environment variables UI
- ✅ Enable automatic HTTPS
- ✅ Use CSP headers
- ✅ Regular dependency updates
- ✅ Monitor for security vulnerabilities
DON'T:
- ❌ Deploy with default/placeholder credentials
- ❌ Expose debug endpoints in production
- ❌ Use outdated dependencies with known CVEs
Vulnerability:
// ❌ NEVER DO THIS
const API_KEY = "sk-1234567890abcdef";Solution:
// ✅ ALWAYS DO THIS
const API_KEY = process.env.API_KEY;
if (!API_KEY) {
throw new Error('API_KEY environment variable is required');
}Vulnerability:
// ❌ EXPOSED in client bundle
const apiKey = import.meta.env.VITE_API_KEY;
fetch('https://api.example.com', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});Solution:
// ✅ SECURE via backend proxy
fetch(`${BACKEND_URL}/api/proxy/endpoint`, {
method: 'GET'
// No API key needed - backend handles it
});Vulnerability:
// ❌ SQL Injection risk
const query = `SELECT * FROM users WHERE id = ${userId}`;Solution:
// ✅ Parameterized queries
const query = 'SELECT * FROM users WHERE id = ?';
db.execute(query, [userId]);Before deploying to production:
- All
.envfiles are in.gitignore - No API keys in frontend environment variables
- All API calls go through backend proxies
- Environment validation passes on startup
- Private keys are unique per environment
- HTTPS enabled on all endpoints
- Dependencies updated and scanned
- Secrets stored in platform environment variables (Vercel/etc)
- Rate limiting enabled on public endpoints
- Error messages don't leak sensitive info
- Audit logs enabled for critical operations
# Required for blockchain operations
PRIVATE_KEY=your_private_key_here
# Required for AI features
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=...
# Required for research data
S2_API_KEY=...
# Optional
KAGGLE_API_TOKEN=...
GITHUB_TOKEN=...# Only contract addresses and backend URL
VITE_BACKEND_URL=https://your-backend.vercel.app
VITE_RESEARCH_GRAPH=0x...
VITE_RESEARCH_TOKEN=0x...
# NO API KEYS IN FRONTEND!If you discover a security vulnerability:
- DO NOT open a public GitHub issue
- Email security concerns to your team lead
- Include detailed reproduction steps
- Allow time for patch before disclosure
Last Updated: February 9, 2026
Version: 1.0.0