CVE-2023-28627: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (CWE-78)
value: pymedusa is an automatic video library manager for TV Shows. In versions prior 1.0.12 an attacker with access to the web interface can update the git executable path in /config/general/ > advanced settings with arbitrary OS commands. An attacker may exploit this vulnerability to take execute arbitrary OS commands as the user running the pymedusa program. Users are advised to upgrade. There are no known workarounds for this vulnerability.
CWE description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
CVSS v3 base score: 8.8
Published: 2023-03-27T21:15Z
Repository: https://github.com/pymedusa/Medusa
Language: Python
Files changed: medusa/updater/github_updater.py
Commit date: 2023-02-22 11:23:45 +0100
Commit message: Ensure that git_path is a valid file (#11138)

* Ensure that git_path is a valid file

* Update github_updater.py
Diff: diff --git a/medusa/updater/github_updater.py b/medusa/updater/github_updater.py
index bb3481c8c..9d825ea5f 100644
--- a/medusa/updater/github_updater.py
+++ b/medusa/updater/github_updater.py
@@ -1,10 +1,11 @@
 # coding=utf-8
 
 from __future__ import unicode_literals
 
 import logging
+import os
 import platform
 import re
 import subprocess
 import sys
 
@@ -70,15 +71,11 @@ class GitUpdateManager(UpdateManager):
     def commits_ahead(self):
         return self._num_commits_ahead
 
     def _find_working_git(self):
         test_cmd = 'version'
-
-        if app.GIT_PATH:
-            main_git = '"' + app.GIT_PATH + '"'
-        else:
-            main_git = 'git'
+        main_git = app.GIT_PATH or 'git'
 
         log.debug(u'Checking if we can use git commands: {0} {1}', main_git, test_cmd)
         _, _, exit_status = self._run_git(main_git, test_cmd)
 
         if exit_status == 0:
@@ -124,10 +121,15 @@ class GitUpdateManager(UpdateManager):
                     log.warning(u"No git specified, can't use git commands")
                     app.NEWEST_VERSION_STRING = ERROR_MESSAGE
                 exit_status = 1
                 return output, err, exit_status
 
+        if git_path != 'git' and not os.path.isfile(git_path):
+            log.warning(u"Invalid git specified, can't use git commands")
+            exit_status = 1
+            return output, err, exit_status
+
         # If we have a valid git remove the git warning
         # String will be updated as soon we check github
         app.NEWEST_VERSION_STRING = None
         cmd = git_path + ' ' + args
 

Vulnerable code: 
        if app.GIT_PATH:
            main_git = '"' + app.GIT_PATH + '"'
        else:
            main_git = 'git'
Fixed code: import os
        main_git = app.GIT_PATH or 'git'
        if git_path != 'git' and not os.path.isfile(git_path):
            log.warning(u"Invalid git specified, can't use git commands")
            exit_status = 1
            return output, err, exit_status