Repository navigation
fix(config): do not crash when DATABASE_URL is set without a config section - #6907
Open
mayuriphad wants to merge 1 commit into
Open
mayuriphad wants to merge 1 commit into
mayuriphad wants to merge 1 commit into
Conversation
…ection The legacy-settings loop read fileConfig[key] although fileConfig is undefined when config.json has no section for the current environment, as in the official Docker image. Any legacy setting such as DATABASE_URL then crashed the server on startup. The loop also only looked at config.json, so DATABASE_URL overrode CMD_DB_URL. Check every source that sets a value under its current name instead. Fixes hedgedoc#6905 Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
ErikMichelson
self-requested a review
October 28, 2026 20:08
This branch has not been deployed
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.
Component/Part
config
Description
This PR fixes the startup crash from #6905.
The "merge legacy values" loop in
lib/config/index.jscheckedfileConfig[keys[i]], butfileConfigisundefinedwhenconfig.jsonhas no section for the currentNODE_ENV. That is the case in the official image, whoseconfig.jsonis{}. As soon as a legacy setting is present, for exampleDATABASE_URL(read intodburlbyoldEnvironment.js), the loop throwsTypeError: Cannot read properties of undefined (reading 'dbURL').The loop also only looked at
config.jsonwhen deciding whether a setting was already given under its current name. So even with the crash guarded,DATABASE_URLwould still overrideCMD_DB_URL. That matters on hosts that injectDATABASE_URLinto every app.The loop now skips a legacy value when the current-name setting comes from any source that uses that name:
config.json, theCMD_andHMD_environment variables, or Docker secrets. A legacy lowercase setting inconfig.json(for exampledburl) still works when nothing else sets the value.Steps
test/config.jsloads the config in a child process for three cases:DATABASE_URLwith an empty config file,CMD_DB_URLtogether withDATABASE_URL, and a legacydburlin the config file. The first two fail onmasterand pass with the change; the third passes on both. ESLint is clean on the changed files. I ran only this test file locally, not the whole mocha suite (which needs the full dependency install).Related Issue(s)
Fixes #6905