- Remove hardcoded database credentials from all scripts - Remove hardcoded Legacy API tokens from backend scripts - Remove hardcoded MQTT credentials from mqtt-test.js - Update backend/.env.example with DB_HOST, DB_USER, DB_PASSWORD, DB_NAME - Update backend/.env.example with LEGACY_API_TOKEN and MQTT credentials - Add dotenv config to all scripts requiring credentials - Create comprehensive documentation: - scripts/README.md - Root scripts usage - backend/scripts/README.md - Backend scripts documentation - MQTT_TESTING.md - MQTT testing guide - SECURITY_CREDENTIALS_CLEANUP.md - Security changes summary All scripts now read credentials from backend/.env instead of hardcoded values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.7 KiB
3.7 KiB
Security: Hardcoded Credentials Cleanup
Summary
All hardcoded credentials have been removed from the codebase and replaced with environment variables.
Changes Made
1. Updated Files (Removed Hardcoded Credentials)
Backend Scripts
backend/check-legacy-deployments.js- Database and Legacy API credentialsbackend/fix-legacy-deployments.js- Legacy API tokenbackend/scripts/create-test-user.js- Database credentialsbackend/scripts/inspect-db.js- Database credentials
Root Scripts
scripts/fetch-otp.js- Database credentialsscripts/legacy-api/create_deployment.sh- Legacy API tokenmqtt-test.js- MQTT credentials
2. Updated Configuration
backend/.env.example
Added the following environment variables:
# Database (PostgreSQL)
DB_HOST=your-db-host
DB_PORT=5432
DB_NAME=your-db-name
DB_USER=your-db-user
DB_PASSWORD=your-db-password
# Legacy API (eluxnetworks.net)
LEGACY_API_USERNAME=your-username
LEGACY_API_TOKEN=your-jwt-token
# MQTT Configuration
MQTT_BROKER=mqtt://mqtt.eluxnetworks.net:1883
MQTT_USER=your-mqtt-username
MQTT_PASSWORD=your-mqtt-password
3. New Documentation Files
scripts/README.md- Documentation for root scriptsbackend/scripts/README.md- Documentation for backend scriptsMQTT_TESTING.md- MQTT testing guideSECURITY_CREDENTIALS_CLEANUP.md- This file
Required Action
Before Running Scripts
Ensure that backend/.env contains all required credentials:
# Database
DB_HOST=eluxnetworks.net
DB_PORT=5432
DB_NAME=wellnuo_app
DB_USER=your-username
DB_PASSWORD=your-password
# Legacy API
LEGACY_API_USERNAME=robster
LEGACY_API_TOKEN=your-actual-jwt-token
# MQTT
MQTT_BROKER=mqtt://mqtt.eluxnetworks.net:1883
MQTT_USER=your-mqtt-username
MQTT_PASSWORD=your-mqtt-password
Security Best Practices
- ✅ Never commit
.envfiles (already in.gitignore) - ✅ Use environment variables for all credentials
- ✅ Keep
.env.exampleupdated but without real values - ✅ Document required environment variables in README files
- ✅ Review code regularly for accidentally committed secrets
Remaining Credentials in Repository
The following files contain credentials but are acceptable:
Documentation (Examples Only)
docs/API_INTEGRATION_REQUEST.md- Example JWT formatdocs/MQTT_NOTIFICATIONS_ARCHITECTURE.md- Example usageMQTT-DESCRIPTION.md- Historical documentation with example commands
Configuration (Git-Ignored)
backend/.env- Git-ignored - Contains actual credentials
Test Data (Git-Ignored)
wellnuoSheme/*.json- Schema files (should be git-ignored)
External Collections
api/Wellnuo_API.postman_collection.json- Postman collection (expired test tokens)
Verification
To verify no credentials are hardcoded in active code:
# Check for database passwords
grep -r "W31153Rg31" --exclude-dir=node_modules --exclude-dir=.git \
--exclude-dir=temp_serve --exclude-dir=wellnuoSheme
# Check for MQTT passwords
grep -r "anandk_8" --exclude-dir=node_modules --exclude-dir=.git \
--exclude-dir=temp_serve --exclude-dir=wellnuoSheme
# Check for JWT tokens (should only be in .env and docs)
grep -r "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" \
--exclude-dir=node_modules --exclude-dir=.git \
--exclude-dir=temp_serve --exclude-dir=wellnuoSheme \
--exclude-dir=api
Status
✅ All hardcoded credentials removed from active code ✅ Environment variables configured ✅ Documentation updated ✅ Scripts updated to use .env
Next Steps
- Review
backend/.envand ensure all credentials are up to date - Update any expired JWT tokens
- Consider rotating credentials that were previously hardcoded
- Add
wellnuoSheme/to.gitignoreif it contains sensitive data