Skip to content

Commit 452fe9b

Browse files
authored
Merge pull request #1773 from Jayyk09/secure-mongodb-setup
Add database security guidelines for MongoDB in local setup documenta…
2 parents 40201ca + 260726f commit 452fe9b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ Write imperative, present-tense commit subjects (e.g., "Add BLE retry delay") an
117117

118118
Cloud services require `.env` files copied from `.env.example` that stay local. Mobile secrets belong in `mobile/app.config.ts` or the secure config service—avoid committing device-specific tokens. Rebuild native projects after modifying BLE or camera modules to keep generated code in sync, and install Java 17, Android Studio, Xcode, Docker, and Bun/Node before the first build.
119119

120+
### Database Security
121+
122+
**CRITICAL**: When running MongoDB locally with Docker, always bind to localhost only:
123+
124+
```yaml
125+
ports:
126+
- "127.0.0.1:27017:27017" # Correct - localhost only
127+
# NOT "27017:27017" which exposes to all interfaces
128+
```
129+
130+
Automated ransomware scanners actively target exposed MongoDB instances. Use MongoDB Atlas for production deployments.
131+
120132
## Project Resources
121133

122134
- [GitHub Project Board - General Tasks](https://github.com/orgs/Mentra-Community/projects/2)

cloud/docs/development/local-setup.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ CLOUD_PUBLIC_HOST_NAME=localhost:8002
6262
CLOUD_LOCAL_HOST_NAME=cloud
6363

6464
# MongoDB (required)
65+
# If running MongoDB locally, ensure it's bound to 127.0.0.1 only (see MongoDB Setup section below)
6566
MONGO_URL=mongodb://localhost:27017/mentraos
6667
# For MongoDB Atlas (cloud):
6768
# MONGO_URL=mongodb+srv://username:password@cluster.mongodb.net/mentraos?retryWrites=true&w=majority
@@ -170,13 +171,18 @@ Internal team members can skip this section and get the configured `.env` from S
170171
#### MongoDB Setup
171172

172173
**Option 1: Local MongoDB with Docker**
174+
175+
<Warning>
176+
**Security Critical**: Always bind MongoDB to localhost only (`127.0.0.1`) to prevent exposure to the public internet. Automated ransomware scanners actively search for exposed MongoDB instances.
177+
</Warning>
178+
173179
```bash
174180
# Add to docker-compose.dev.yml
175181
services:
176182
mongodb:
177183
image: mongo:7.0
178184
ports:
179-
- "27017:27017"
185+
- "127.0.0.1:27017:27017" # IMPORTANT: Bind to localhost only!
180186
volumes:
181187
- mongo_data:/data/db
182188
environment:
@@ -612,10 +618,17 @@ db.apps.insertOne({
612618

613619
## Security Reminders
614620

621+
<Warning>
622+
**Database Security**: Never expose MongoDB to the public internet. Automated ransomware scanners actively target open database ports. Always use `127.0.0.1:PORT:PORT` instead of `PORT:PORT` in Docker port bindings for databases.
623+
</Warning>
624+
625+
- **Always bind databases to localhost**: Use `127.0.0.1:27017:27017` not `27017:27017`
615626
- **Never commit .env files**
616627
- **Don't share ngrok URLs** with sensitive data
617628
- **Use strong JWT secrets** in production
618629
- **Rotate secrets regularly**
630+
- **Use MongoDB Atlas** for cloud deployments (handles security automatically)
631+
- **Enable authentication** on any exposed services
619632

620633
## Next Steps
621634

0 commit comments

Comments
 (0)