Remove hardcoded MongoDB root credentials from docker-compose.yaml (CWE-798)#207
Open
sebastiondev wants to merge 1 commit intoEverMind-AI:mainfrom
Open
Conversation
Replace hardcoded MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
with Docker Compose variable substitution that reads from the shell
environment / .env file.
MONGO_INITDB_ROOT_PASSWORD now uses the ${VAR:?error} syntax so
`docker compose up` will fail fast with a clear message when the
password has not been set, preventing accidental deployment with
well-known credentials.
env.template is updated to remove the shipped default password
("memsys123") and instead prompt the user to set a strong value.
CWE-798
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docker-compose.yamlships with hardcoded MongoDB root credentials (admin/memsys123) and publishes the database on27017:27017to the host. Anyone who clones the repo and runsdocker compose upwithout manually editing the file ends up exposing a MongoDB instance with publicly-known root credentials — which is trivially discoverable by Shodan-style scanners and search-engine indexing of the repository.This PR removes the hardcoded password and forces the operator to supply one via environment /
.env.Vulnerability details
docker-compose.yaml(themongodbservice block), with the same secret mirrored as a default inenv.template27017:27017, so the credentials are reachable on any interface the Docker host listens onExploit sketch
On any host where an operator has run
docker compose upfrom an unmodified clone:The credentials are publicly visible in the repo, so no guessing is required.
Fix
Rationale:
${VAR:?error}form makes Compose fail fast ifMONGODB_PASSWORDis unset or empty, so operators can't silently inherit a known-bad default.admin) is preserved because it is not the secret material; the password is.env.templateno longer carries a working credential — it carries a clearREQUIREDmarker so that a copy-paste-and-forget workflow surfaces the missing value immediately.What I tested
docker compose configwith noMONGODB_PASSWORDset → fails with the configured error message, as intended.docker compose configwithMONGODB_PASSWORD=somevalueexported → renders correctly with the supplied value.Adversarial review
Before submitting I tried to talk myself out of this one. The compose file is the actual runtime artifact a self-hoster uses, port
27017is mapped to the host with no reverse-proxy in front of it, and there is no application-layer guard that would prevent direct connections — so neither network position nor framework protections mitigate the issue in the default deployment. The credentials are also already public in the repo, which removes any "attacker needs prior access" caveat. The docs underdocs/installation/still mentionmemsys123in examples; that's poor hygiene worth a follow-up sweep, but those are documentation strings, not executable defaults, so this PR focuses on closing the runtime exposure.References
:?cc @lewiswigmore