fix: preserve # in unquoted environment variable values - #5107
Open
AbiRaditya wants to merge 1 commit into
Open
Conversation
User environment variables were parsed with dotenv, which truncates unquoted values at any #, so passwords like 'secret#' reached containers as 'secret'. Replace dotenv.parse with a parser that follows Docker Compose comment semantics: # starts an inline comment only at line start or when preceded by whitespace. Quoted values, inline comments after whitespace, multiline values and escape expansion behave as before. Fixes Dokploy#5095 Related Dokploy#4694
AbiRaditya
force-pushed
the
fix/env-comment-truncation
branch
from
August 17, 2026 13:33
fade246 to
a47157e
Compare
AbiRaditya
marked this pull request as ready for review
August 17, 2026 13:45
Collaborator
|
This PR is too complex for the issue is fixing. Can you check https://github.com/Dokploy/dokploy/pull/5119/changes#diff-b781cff2d9de42192bd4d8a3315140d2299e52187af2c715f561c484568af1edR462 and try to get a close implementation to that one? Simpler if possible. |
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
Fixes #5095 (related: #4694)
User environment variables containing
#were silently truncated.prepareEnvironmentVariablesparsed all user env text (service, project, and environment level) withdotenv.parse, whose unquoted-value regex[^#\r\n]+treats any#as the start of an inline comment:PASSWORD=secret#→secretMID=sec#ret→secThe truncated values propagated to Docker service
Envarrays (applications and databases), the generated.envfor Compose deployments, and shell env preparation. In #5095, the reporter's Postgres password ended with#: the database container received the full password (Dokploy's internal template quotes it), but their app's env var was truncated — so the app authenticated with the wrong password and crashed.Fix
Replace
dotenv.parseon user env text with a parser (packages/server/src/utils/docker/env-parser.ts, a modified copy of dotenv v16.4.5'sparse, BSD-2-Clause) that follows Docker Compose comment semantics: a#starts an inline comment only at line start or when preceded by whitespace. This also makes Dokploy's parsing agree with howdocker composeitself reads the.envfiles Dokploy generates.KEY=secret#secretsecret#KEY=sec#retsecsec#retKEY=#foo#fooKEY=value # commentvaluevalue(unchanged)KEY="val#ue"val#ueval#ue(unchanged)Quoted values, inline comments after whitespace, multiline values,
\n/\rescape expansion, theexportprefix, and empty values all behave exactly as before — the three pre-existing env test files pass unchanged.dotenvremains a dependency (still used for Dokploy's own boot env inapps/dokploy).Tests
apps/dokploy/__test__/env/comment-handling.test.ts(14 tests), written before the fix — the 7#cases failed with the exact truncated values, locking in the repro.Manual verification (local dev, Docker Swarm)
mysecret#: container env showsPOSTGRES_PASSWORD=mysecret#;psqlover the overlay network (where scram auth is enforced) authenticates withmysecret#and rejects the truncatedmysecretwithpassword authentication failed— the exact error from Incorrect Postgres password parsing for Spring Boot apps #5095, now only occurring for genuinely wrong passwords.TEST_PASSWORD=mysecret#in Environment Settings, referenced as${TEST_PASSWORD}: running container env shows the full value.docker compose configround-trip on a generated.envconfirms Docker parsesmysecret#/sec#retidentically to Dokploy's new parser.KEY=value # commententries still resolve tovalue.Tested with app
Tested with postgres
Greptile Summary
The PR replaces
dotenv.parsefor user-supplied environment text with a Compose-compatible parser that preserves unquoted#characters unless preceded by whitespace.Confidence Score: 5/5
The PR appears safe to merge, with no concrete blocking or non-blocking defects identified in the changed behavior.
The parser retains dotenv’s established parsing behavior outside the explicitly documented hash-comment semantic change, and the shared deployment paths receive the intended untruncated values.
Reviews (1): Last reviewed commit: "fix: preserve # in unquoted environment ..." | Re-trigger Greptile
Context used: