security: tighten readable/regular file checks in CLI tools

This commit is contained in:
Dylan M. Taylor
2026-10-22 19:18:41 -04:00
parent 3a9b35c687
commit ac2d7623e3
2 changed files with 8 additions and 1 deletions
+6 -1
View File
@@ -5,10 +5,15 @@ from pathlib import Path
def _jsonl_path(arg):
"""Resolve the CLI file argument; require an existing regular file."""
"""Resolve the CLI file argument; require an existing readable regular file."""
path = Path(arg).resolve()
if not path.is_file():
sys.exit(f"not a readable file: {arg}")
try:
with path.open("rb"):
pass
except OSError:
sys.exit(f"not a readable file: {arg}")
return path
def call(method, params):
+2
View File
@@ -35,6 +35,8 @@ def _out_path(arg):
path = Path(arg).resolve()
if not path.parent.is_dir():
sys.exit(f"output directory does not exist: {arg}")
if path.exists() and not path.is_file():
sys.exit(f"output path is not a regular file: {arg}")
return str(path)
WL = np.arange(380, 781, 5)