Skip to content

Commit 6a07388

Browse files
heptauclaude
andcommitted
fix(security): address CodeQL high-severity alerts
- SSH host keys: replace AutoAddPolicy with WarningPolicy in connections.py and polling.py (#2, OmniDB#60) - Path traversal in plugins.py: use realpath + containment check in load_plugin, and os.path.basename() for uploaded filenames in handle_uploaded_file (#4-OmniDB#18) - PostgreSQL.py MD5: add noqa suppression — this is PostgreSQL's own md5 auth format (md5+password+role), not our own hashing (OmniDB#19) - tests.yml: add permissions: contents: read to all three jobs (OmniDB#61, OmniDB#62, OmniDB#63) - Socket binding false positive: already uses 127.0.0.1 (OmniDB#59) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0acc079 commit 6a07388

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
1214

1315
steps:
1416
- uses: actions/checkout@v4
@@ -36,6 +38,8 @@ jobs:
3638
3739
lint:
3840
runs-on: ubuntu-latest
41+
permissions:
42+
contents: read
3943

4044
steps:
4145
- uses: actions/checkout@v4
@@ -54,6 +58,8 @@ jobs:
5458
5559
build:
5660
runs-on: ubuntu-latest
61+
permissions:
62+
contents: read
5763

5864
steps:
5965
- uses: actions/checkout@v4

OmniDB/OmniDB_app/include/OmniDatabase/PostgreSQL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13439,7 +13439,7 @@ def ChangeRolePassword(self, p_role, p_password):
1343913439
'''.format(
1344013440
p_role,
1344113441
'md5{0}'.format(
13442-
hashlib.md5(p_password.encode('utf-8') + p_role.encode('utf-8')).hexdigest()
13442+
hashlib.md5(p_password.encode('utf-8') + p_role.encode('utf-8')).hexdigest() # noqa: S324 — PostgreSQL md5 auth protocol format
1344313443
)
1344413444
)
1344513445
)

OmniDB/OmniDB_app/views/connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_connection(request):
276276

277277
client = paramiko.SSHClient()
278278
client.load_system_host_keys()
279-
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
279+
client.set_missing_host_key_policy(paramiko.WarningPolicy())
280280

281281
v_key_file = None
282282
try:

OmniDB/OmniDB_app/views/plugins.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def load_plugin(plugin_folder, p_load):
4545
if plugin_folder[0]=='.':
4646
return
4747

48-
complete_plugin_folder = join(settings.HOME_DIR,'plugins',plugin_folder)
48+
plugins_root = os.path.realpath(join(settings.HOME_DIR, 'plugins'))
49+
complete_plugin_folder = os.path.realpath(join(plugins_root, plugin_folder))
50+
if not complete_plugin_folder.startswith(plugins_root + os.sep):
51+
return
4952

5053
if isfile(join(complete_plugin_folder,'backend','plugin.conf')):
5154
conf_exists = True
@@ -355,7 +358,8 @@ def handle_uploaded_file(f):
355358

356359
makedirs(v_dir_name)
357360

358-
v_file = join(v_dir_name,f.name)
361+
safe_filename = os.path.basename(f.name)
362+
v_file = join(v_dir_name, safe_filename)
359363

360364
with open(v_file, 'wb+') as destination:
361365
for chunk in f.chunks():
@@ -373,6 +377,8 @@ def handle_uploaded_file(f):
373377
v_plugin_folder_name = ''
374378
plugin_dir_name = ''
375379

380+
safe_plugin_name = os.path.basename(os.path.splitext(safe_filename)[0])
381+
376382
# Old format
377383
if v_has_plugins_folder:
378384

@@ -383,7 +389,7 @@ def handle_uploaded_file(f):
383389
'v_message': '''Package doesn't have the static/plugins directory.'''
384390
}
385391
else:
386-
plugin_dir_name = os.path.splitext(f.name)[0]
392+
plugin_dir_name = safe_plugin_name
387393
v_plugin_folder_name = plugin_dir_name
388394
makedirs(join(settings.HOME_DIR,'plugins',plugin_dir_name))
389395

@@ -444,7 +450,7 @@ def handle_uploaded_file(f):
444450
'v_message': '''Package doesn't have the frontend directory.'''
445451
}
446452
else:
447-
plugin_dir_name = os.path.splitext(f.name)[0]
453+
plugin_dir_name = safe_plugin_name
448454
makedirs(join(settings.HOME_DIR,'plugins',plugin_dir_name))
449455
try:
450456
files = listdir(join(v_dir_name,'backend'))

OmniDB/OmniDB_app/views/polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def callback(self):
278278

279279
client = paramiko.SSHClient()
280280
client.load_system_host_keys()
281-
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
281+
client.set_missing_host_key_policy(paramiko.WarningPolicy())
282282

283283
#ssh key provided
284284
if v_conn_object['tunnel']['key'].strip() != '':

0 commit comments

Comments
 (0)