8000 fix(config): do not crash when DATABASE_URL is set without a config section by mayuriphad · Pull Request #6907 · hedgedoc/hedgedoc · GitHub
[go: up one dir, main page]

Skip to content

fix(config): do not crash when DATABASE_URL is set without a config section - #6907

Open
mayuriphad wants to merge 1 commit into
hedgedoc:masterfrom
mayuriphad:fix/config-legacy-db-url
Open

mayuriphad wants to merge 1 commit into
hedgedoc:masterfrom
mayuriphad:fix/config-legacy-db-url

Conversation

@mayuriphad
Copy link
Copy Markdown

Component/Part

config

Description

This PR fixes the startup crash from #6905.

The "merge legacy values" loop in lib/config/index.js checked fileConfig[keys[i]], but fileConfig is undefined when config.json has no section for the current NODE_ENV. That is the case in the official image, whose config.json is {}. As soon as a legacy setting is present, for example DATABASE_URL (read into dburl by oldEnvironment.js), the loop throws TypeError: Cannot read properties of undefined (reading 'dbURL').

The loop also only looked at config.json when deciding whether a setting was already given under its current name. So even with the crash guarded, DATABASE_URL would still override CMD_DB_URL. That matters on hosts that inject DATABASE_URL into every app.

The loop now skips a legacy value when the current-name setting comes from any source that uses that name: config.json, the CMD_ and HMD_ environment variables, or Docker secrets. A legacy lowercase setting in config.json (for example dburl) still works when nothing else sets the value.

Steps

  • Added implementation
  • Added / updated tests
  • Added changelog snippet
  • I read the contribution documentation and signed-off my commits to accept the DCO.

test/config.js loads the config in a child process for three cases: DATABASE_URL with an empty config file, CMD_DB_URL together with DATABASE_URL, and a legacy dburl in the config file. The first two fail on master and 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

…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>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 06:49

This comment was marked as off-topic.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container crashes on start when DATABASE_URL is set: Cannot read properties of undefined (reading 'dbURL')

2 participants

0