-
Notifications
You must be signed in to change notification settings - Fork 809
Fixed a variable quoting issue in the Docker entrypoint script #9511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Guiorgy
wants to merge
1
commit into
pgadmin-org:master
Choose a base branch
from
Guiorgy:fix-8529
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Shell metacharacters in URIs will be expanded despite Python triple-quotes.
The triple-quote approach (line 81) attempts to address single quotes in URIs using Python's triple-quoted string syntax. While this handles single quotes better than regular single quotes, it introduces critical security and correctness issues:
Shell variable expansion: When the sanitized value is substituted inside double quotes on line 93 (
"...${PGADMIN_CONFIG_CONFIG_DATABASE_URI}..."), the shell will still expand dollar signs, backticks, backslashes, and exclamation marks—even when they appear inside the triple quotes, because double quotes preserve these special meanings. For example, a URI likepostgresql://user:pa$word@host/dbbecomes'''postgresql://user:pa$word@host/db''', but when substituted inside double quotes,$wordis interpreted as a shell variable.Triple-quote breakage: If the URI contains
''', Python parsing will fail.Already-quoted check flaw: The regex on line 79 checks for quote characters in the value, but environment variables don't preserve shell quotes—if a user sets
PGADMIN_CONFIG_CONFIG_DATABASE_URI='value', the environment variable containsvalue(without quotes). This check only catches URIs that contain literal quote characters as part of the data.🔎 Recommended fix: Use environment variables to pass the URI safely to Python
This approach avoids all shell quoting/escaping issues:
This passes the URI through the environment, avoiding all shell metacharacter interpretation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When expanding variables inside double quotes, e.g.
"$var", the contents are treated as literal strings, no? The target that receives that string is the Python interpreter, which does no such expansions.The likelyhood is almsot 0.
Currently, people are using environmental variables with literal quotes, e.g.
PGADMIN_CONFIG_CONFIG_DATABASE_URI='"value"'.Proposed solution. While the idea is actually good, we would be breaking all the existing code (see point 3 above), so can you propose a solution that accounts for that and keeps it backwards compatible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Guiorgy, you're absolutely right about point 1—I was mistaken about the shell expansion behavior. When
${PGADMIN_CONFIG_CONFIG_DATABASE_URI}is substituted inside double quotes, the shell replaces it with the variable's value, but that value is treated as literal text (no further expansion of$, backticks, etc. within the value itself). My apologies for the confusion.For backwards compatibility with users who have quotes embedded in their environment variable values, here's a revised approach using
os.environwith Python-side quote handling:This approach:
<< 'PYEOF') to avoid all shell quoting/escaping complexity'"value"') and unquoted (value) environment variable values