Skip to content

Commit 2342c8d

Browse files
committed
Mask the secret key for restrict option in the process watcher when restoring plain SQL file. #9518
Fixed coderabbit review comment.
1 parent 3b184db commit 2342c8d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

web/pgadmin/tools/restore/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""Implements Restore Utility"""
1111

1212
import json
13-
import re
1413
import secrets
1514

1615
from flask import render_template, request, current_app, Response
@@ -26,7 +25,7 @@
2625
internal_server_error
2726

2827
from config import PG_DEFAULT_DRIVER
29-
from pgadmin.utils.constants import MIMETYPE_APP_JS, SERVER_NOT_FOUND
28+
from pgadmin.utils.constants import SERVER_NOT_FOUND, RESTRICT_COMMAND
3029
from pgadmin.tools.user_management.PgAdminPermissions import AllPermissionTypes
3130

3231
# set template path for sql scripts
@@ -75,7 +74,13 @@ def cmd_arg(x):
7574
return ''
7675

7776
for arg in _args:
78-
if arg and len(arg) >= 2 and arg.startswith('--'):
77+
if arg and RESTRICT_COMMAND in arg:
78+
# Find the index where \restrict ends
79+
idx = arg.find(RESTRICT_COMMAND) + len(RESTRICT_COMMAND)
80+
# Keep the prefix and mask everything after it
81+
masked_arg = arg[:idx + 1] + "x" * (len(arg) - idx - 1)
82+
self.cmd += cmd_arg(masked_arg)
83+
elif arg and len(arg) >= 2 and arg.startswith('--'):
7984
self.cmd += ' ' + arg
8085
else:
8186
self.cmd += cmd_arg(arg)

web/pgadmin/utils/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,4 @@ class MessageType:
177177

178178
RESTRICTION_TYPE_DATABASES = 'databases'
179179
RESTRICTION_TYPE_SQL = 'sql'
180+
RESTRICT_COMMAND = '\\restrict'

0 commit comments

Comments
 (0)