-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented sanitisation to satisfy CodeQL warning on uncontrolled co…
…mmand line input
- Loading branch information
Showing
1 changed file
with
6 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
from murfey.client.multigrid_control import MultigridController | ||
from murfey.client.rsync import RSyncer | ||
from murfey.client.watchdir_multigrid import MultigridDirWatcher | ||
from murfey.util import sanitise_nonpath, secure_path | ||
from murfey.util import sanitise, sanitise_nonpath, secure_path | ||
from murfey.util.instrument_models import MultigridWatcherSpec | ||
from murfey.util.models import File, Token | ||
|
||
|
@@ -278,19 +278,16 @@ class GainReference(BaseModel): | |
|
||
@router.post("/sessions/{session_id}/upload_gain_reference") | ||
def upload_gain_reference(session_id: MurfeySessionID, gain_reference: GainReference): | ||
safe_gain_path = sanitise(str(gain_reference.gain_path)) | ||
safe_visit_path = sanitise(gain_reference.visit_path) | ||
safe_destination_dir = sanitise(gain_reference.gain_destination_dir) | ||
cmd = [ | ||
"rsync", | ||
str(gain_reference.gain_path), | ||
f"{urlparse(_get_murfey_url(), allow_fragments=False).hostname}::{gain_reference.visit_path}/{gain_reference.gain_destination_dir}/{secure_filename(gain_reference.gain_path.name)}", | ||
safe_gain_path, | ||
f"{urlparse(_get_murfey_url(), allow_fragments=False).hostname}::{safe_visit_path}/{safe_destination_dir}/{secure_filename(gain_reference.gain_path.name)}", | ||
] | ||
gain_rsync = subprocess.run(cmd) | ||
Check failure Code scanning / CodeQL Uncontrolled command line Critical
This command line depends on a
user-provided value Error loading related location Loading This command line depends on a user-provided value. |
||
if gain_rsync.returncode: | ||
safe_gain_path = ( | ||
str(gain_reference.gain_path).replace("\r\n", "").replace("\n", "") | ||
) | ||
safe_visit_path = gain_reference.visit_path.replace("\r\n", "").replace( | ||
"\n", "" | ||
) | ||
logger.warning( | ||
f"Gain reference file {safe_gain_path} was not successfully transferred to {safe_visit_path}/processing" | ||
) | ||
|