Update security report and enhance subprocess environment handling

- Generated a new security scan report with detailed findings, including 888 total findings and 33 critical issues.
- Revised the `soffice.py` scripts across multiple skills to implement a secure environment variable forwarding mechanism, minimizing the risk of exposing sensitive information to subprocesses.
- Enhanced documentation in `SKILL.md` and related files to clarify the implications of using `trust_remote_code=True` and the importance of user consent when executing code from external repositories.
- Improved the command submission process in `run_pacsomatic.py` to ensure safer execution of scripts across different executors.
This commit is contained in:
Timothy Kassis committed 2026-07-26 08:48:30 -07:00
1 parent 489de4ce4c
commit cb83780242
9 files changed
+30121 -34

No files matched your search

File diff suppressed because it is too large. Load diff
+2950 -20
View File
File diff suppressed because it is too large. Load diff
+27 -1
View File
@@ -24,8 +24,34 @@ from collections.abc import Iterable
from pathlib import Path
# soffice inherits only these. LibreOffice needs a working process environment,
# not the caller's credentials, so the env is built from an allowlist rather than
# copied: an API key or token exported for the agent must not reach a converter
# subprocess just because it happened to be in scope.
FORWARDED_ENV_VARS = (
# Locating soffice, its native libraries, and scratch space.
"PATH", "HOME", "LD_LIBRARY_PATH", "TMPDIR", "TMP", "TEMP",
# Locale decides number, date, and currency formatting in converted output.
"LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_NUMERIC", "LC_TIME",
# soffice writes its profile and cache under these when they are set.
"XDG_RUNTIME_DIR", "XDG_CACHE_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME",
# For callers that run against a real display instead of the svp backend.
"DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY",
"USER", "LOGNAME",
# Windows needs these for process startup, temp files, and DLL resolution.
"SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT", "SYSTEMDRIVE",
"APPDATA", "LOCALAPPDATA", "USERPROFILE",
"PROGRAMFILES", "PROGRAMFILES(X86)", "PROGRAMDATA",
)
def get_soffice_env() -> dict:
env = os.environ.copy()
"""Return a minimal environment for a soffice subprocess.
Assembled from FORWARDED_ENV_VARS instead of inheriting the parent
environment, so secrets in scope for the caller are not passed to soffice.
"""
env = {name: os.environ[name] for name in FORWARDED_ENV_VARS if name in os.environ}
env["SAL_USE_VCLPLUGIN"] = "svp"
if _needs_shim():
+1 -1
View File
@@ -112,7 +112,7 @@ If you're creating a new project, also add `.env` to `.gitignore` if it isn't al
**The entries are pointers.** Don't try to "use Hugging Science" as if it were an API. There is no Hugging Science inference endpoint. Every actionable resource lives on HF Hub or as a HF Space, and you use it via the standard HF tooling.
**Many scientific models require `trust_remote_code=True`.** Custom architectures (Evo-2, many genomics/materials models) ship custom modeling code. This is normal in this ecosystem. Pass the flag and inform the user.
**Many scientific models require `trust_remote_code=True`.** Custom architectures (Evo-2, many genomics/materials models) ship custom modeling code. This is normal in this ecosystem, but the flag executes arbitrary Python from the model repo on the user's machine — so ask the user before you set it, naming the repo, and wait for an answer. Appearing in the catalog is not a vetting signal: entries are pointers fetched over the network, not code review. The same applies to sending files or tokens to a Space via `gradio_client`.
**Scientific datasets are often large and weirdly-shaped.** Genomics corpora can be billions of tokens; cosmology images can be hundreds of GB; materials datasets contain non-standard objects (crystal structures, graphs). Use streaming (`streaming=True` on `load_dataset`) by default for anything claimed to be over a few GB, and inspect schema before assuming columns.
@@ -52,7 +52,9 @@ A large fraction of scientific models — Evo-2, many Nucleotide Transformer var
model = AutoModel.from_pretrained("arcinstitute/evo2_7b", trust_remote_code=True)
```
Tell the user when you set this flag and why. It executes Python from the repo, so the user should trust the org. The catalog only lists reputable orgs (Arc Institute, Meta/Facebook AI, EleutherAI, SandboxAQ, Merck, etc.), but the user gets to make the call.
Ask the user before you set this flag, and wait for an answer — don't set it and report afterwards. It runs Python from the model repo on their machine, with their filesystem and credentials in scope, so the decision is theirs to make with the repo named.
The catalog's curation is not a security control. It generally lists reputable orgs (Arc Institute, Meta/Facebook AI, EleutherAI, SandboxAQ, Merck, etc.), but it is a markdown file fetched over the network at read time: a repo name reaching you through `llms.txt` or a topic file has been curated for scientific relevance, not audited for what its modeling code does. Treat every catalog entry as an untrusted pointer, and don't let "it was in the catalog" stand in for the user's decision.
### Sizing the GPU
@@ -35,6 +35,8 @@ from dotenv import load_dotenv
load_dotenv() # gradio_client picks up HF_TOKEN automatically
```
Note what that convenience implies: once `HF_TOKEN` is loaded, `gradio_client` sends it to whatever Space you call, and `file(...)` uploads local data to that Space's operator. Both are fine for the `hugging-science` org's own Spaces. Neither is fine for a Space name you picked up from the catalog and haven't looked at — catalog entries are curated for scientific relevance, not audited, and the catalog is fetched over the network at read time. Before calling a Space outside the `hugging-science` org, name it to the user along with the files you intend to upload, and let them decide.
## The general pattern
```python
+27 -9
View File
@@ -545,14 +545,28 @@ def ensure_dependency_tools(args):
def submit_command_for_executor(executor, script_path):
quoted = shlex.quote(script_path)
"""Return (argv, stdin_path) for submitting the launch script.
lsf reads the script from stdin (`bsub < script`); every other executor
takes it as an argument. Returning an argv list rather than a shell string
keeps submission off a shell entirely, so a script path containing shell
metacharacters cannot extend the command that runs.
"""
if executor == "lsf":
return f"bsub < {quoted}"
return ["bsub"], script_path
if executor == "slurm":
return f"sbatch {quoted}"
return ["sbatch", script_path], None
if executor in {"pbs", "sge"}:
return f"qsub {quoted}"
return f"bash {quoted}"
return ["qsub", script_path], None
return ["bash", script_path], None
def format_submit_command(argv, stdin_path):
"""Render a submission as a copy-pasteable shell line, for display only."""
line = shlex.join(argv)
if stdin_path:
line += f" < {shlex.quote(stdin_path)}"
return line
def extract_job_id(executor, output):
@@ -574,8 +588,12 @@ def extract_job_id(executor, output):
def execute_launch(args, script_path):
cmd = submit_command_for_executor(args.executor, script_path)
completed = subprocess.run(cmd, shell=True, text=True, capture_output=True)
argv, stdin_path = submit_command_for_executor(args.executor, script_path)
if stdin_path:
with open(stdin_path, "rb") as handle:
completed = subprocess.run(argv, stdin=handle, text=True, capture_output=True)
else:
completed = subprocess.run(argv, text=True, capture_output=True)
stdout = (completed.stdout or "").strip()
stderr = (completed.stderr or "").strip()
@@ -708,14 +726,14 @@ def main():
nextflow_cmd = build_nextflow_command(args, samplesheet_path)
write_launch_script(args, launch_script_path, nextflow_cmd)
submit_cmd = submit_command_for_executor(args.executor, launch_script_path)
submit_argv, submit_stdin = submit_command_for_executor(args.executor, launch_script_path)
print("--- Pacsomatic Launch Assets Prepared ---")
print(f"Samplesheet : {os.path.abspath(samplesheet_path)}")
print(f"Launch script: {os.path.abspath(launch_script_path)}")
print(f"Params YAML : {os.path.abspath(args.generated_params_file)}")
print(f"Executor : {args.executor}")
print(f"Run cmd : {submit_cmd}")
print(f"Run cmd : {format_submit_command(submit_argv, submit_stdin)}")
if args.dry_run and not args.run:
info("Dry run complete. Inputs and runtime dependencies validated.")
+27 -1
View File
@@ -24,8 +24,34 @@ from collections.abc import Iterable
from pathlib import Path
# soffice inherits only these. LibreOffice needs a working process environment,
# not the caller's credentials, so the env is built from an allowlist rather than
# copied: an API key or token exported for the agent must not reach a converter
# subprocess just because it happened to be in scope.
FORWARDED_ENV_VARS = (
# Locating soffice, its native libraries, and scratch space.
"PATH", "HOME", "LD_LIBRARY_PATH", "TMPDIR", "TMP", "TEMP",
# Locale decides number, date, and currency formatting in converted output.
"LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_NUMERIC", "LC_TIME",
# soffice writes its profile and cache under these when they are set.
"XDG_RUNTIME_DIR", "XDG_CACHE_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME",
# For callers that run against a real display instead of the svp backend.
"DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY",
"USER", "LOGNAME",
# Windows needs these for process startup, temp files, and DLL resolution.
"SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT", "SYSTEMDRIVE",
"APPDATA", "LOCALAPPDATA", "USERPROFILE",
"PROGRAMFILES", "PROGRAMFILES(X86)", "PROGRAMDATA",
)
def get_soffice_env() -> dict:
env = os.environ.copy()
"""Return a minimal environment for a soffice subprocess.
Assembled from FORWARDED_ENV_VARS instead of inheriting the parent
environment, so secrets in scope for the caller are not passed to soffice.
"""
env = {name: os.environ[name] for name in FORWARDED_ENV_VARS if name in os.environ}
env["SAL_USE_VCLPLUGIN"] = "svp"
if _needs_shim():
+27 -1
View File
@@ -24,8 +24,34 @@ from collections.abc import Iterable
from pathlib import Path
# soffice inherits only these. LibreOffice needs a working process environment,
# not the caller's credentials, so the env is built from an allowlist rather than
# copied: an API key or token exported for the agent must not reach a converter
# subprocess just because it happened to be in scope.
FORWARDED_ENV_VARS = (
# Locating soffice, its native libraries, and scratch space.
"PATH", "HOME", "LD_LIBRARY_PATH", "TMPDIR", "TMP", "TEMP",
# Locale decides number, date, and currency formatting in converted output.
"LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_NUMERIC", "LC_TIME",
# soffice writes its profile and cache under these when they are set.
"XDG_RUNTIME_DIR", "XDG_CACHE_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME",
# For callers that run against a real display instead of the svp backend.
"DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY",
"USER", "LOGNAME",
# Windows needs these for process startup, temp files, and DLL resolution.
"SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT", "SYSTEMDRIVE",
"APPDATA", "LOCALAPPDATA", "USERPROFILE",
"PROGRAMFILES", "PROGRAMFILES(X86)", "PROGRAMDATA",
)
def get_soffice_env() -> dict:
env = os.environ.copy()
"""Return a minimal environment for a soffice subprocess.
Assembled from FORWARDED_ENV_VARS instead of inheriting the parent
environment, so secrets in scope for the caller are not passed to soffice.
"""
env = {name: os.environ[name] for name in FORWARDED_ENV_VARS if name in os.environ}
env["SAL_USE_VCLPLUGIN"] = "svp"
if _needs_shim():