Skip to content

Commit 5e8a75c

Browse files
Added escaping for the placeholder parameters before passing it to the passexec command. #6794
1 parent d8ed75d commit 5e8a75c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

web/pgadmin/browser/server_groups/servers/static/js/server.ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ export default class ServerSchema extends BaseUISchema {
349349
group: gettext('Advanced'), controlProps: {maxLength: null},
350350
mode: ['properties', 'edit', 'create'],
351351
disabled: pgAdmin.server_mode == 'True' && pgAdmin.enable_server_passexec_cmd == 'False',
352+
helpMessage: gettext('The server hostname, port, and username can be passed as variables by using the placeholders %HOST%, %PORT%, and %USERNAME%, which will be replaced with the corresponding server connection information.')
352353
},
353354
{
354355
id: 'passexec_expiration', label: gettext('Password exec expiration (seconds)'), type: 'int',

web/pgadmin/utils/passexec.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from flask import current_app
1515

1616
import config
17+
from pgadmin.utils.driver import get_driver
1718

1819

1920
class PasswordExec:
@@ -22,9 +23,9 @@ class PasswordExec:
2223

2324
def __init__(self, cmd, host, port, username, expiration_seconds=None,
2425
timeout=60):
25-
cmd = str(cmd).replace('%HOSTNAME%', host)
26-
cmd = cmd.replace('%PORT%', str(port))
27-
cmd = cmd.replace('%USERNAME%', username)
26+
self.host = host
27+
self.port = port
28+
self.username = username
2829
self.cmd = cmd
2930
self.expiration_seconds = int(expiration_seconds) \
3031
if expiration_seconds is not None else None
@@ -36,6 +37,12 @@ def get(self):
3637
if config.SERVER_MODE and not config.ENABLE_SERVER_PASS_EXEC_CMD:
3738
# Arbitrary shell execution on server is a security risk
3839
raise NotImplementedError('Passexec not available in server mode')
40+
driver = get_driver(config.PG_DEFAULT_DRIVER)
41+
self.cmd = str(self.cmd)
42+
self.cmd = self.cmd.replace('%HOSTNAME%', self.host)
43+
self.cmd = self.cmd.replace('%PORT%', str(self.port))
44+
self.cmd = self.cmd.replace('%USERNAME%',
45+
driver.qtIdent(None,self.username))
3946
with self.lock:
4047
if not self.password or self.is_expired():
4148
if not self.cmd:

0 commit comments

Comments
 (0)