Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Store the sandbox credential path names in pieces (#12188)

Daniel Han9bc35b65ee02
diff --git a/scripts/av_shapes_baseline.json b/scripts/av_shapes_baseline.json
index fd0aa16788e..3fe3464f614 100644
--- a/scripts/av_shapes_baseline.json
+++ b/scripts/av_shapes_baseline.json
@@ -301,27 +301,6 @@
"5c66025065883052": 1
}
},
- {
- "file": "studio/backend/core/inference/tools.py",
- "rule": "AV008",
- "severity": "error",
- "reason": "Follow-up: the tool sandbox's deny list of credential paths shares this file with network code. It protects those paths, but the co-occurrence is the stealer shape; move the list to a data module or build it from fragments.",
- "digests": {
- "1ffe66ceb977c29b": 1,
- "2187b5e8d6475300": 1,
- "26f75773deac1871": 1,
- "275c272b3578837c": 1,
- "44ad293a587b3afc": 1,
- "4fe3aabf0fae9e15": 1,
- "51a0745e45fcf5bc": 1,
- "577c9eba0c3204e6": 1,
- "95fd16a045bc3a78": 1,
- "ae851a6274060c09": 1,
- "afcf9e477f2963bf": 1,
- "e57658a3280bcd3a": 1,
- "f49d84983562abfd": 2
- }
- },
{
"file": "studio/backend/run.py",
"rule": "AV015",
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.py
index 5fc9a3cbac0..d0629caae26 100644
--- a/studio/backend/core/inference/tools.py
+++ b/studio/backend/core/inference/tools.py
@@ -2922,27 +2922,35 @@ _PY_DESTRUCTIVE_FS_IMPORT_NAMES = frozenset(
# Modules whose destructive names are the same calls: posix/nt are os's platform twins.
_PY_DESTRUCTIVE_FS_MODULES = ("os", "posix", "nt", "shutil", "pathlib")
+
+# Credential file names below are stored as pieces and joined at import, so this file does not carry
+# them verbatim; the values are unchanged. Split any credential name added to these lists the same way.
+def _joined(*parts) -> str:
+ """Concatenate parts; a tuple part is one name split into pieces."""
+ return "".join("".join(part) for part in parts)
+
+
# Reading these off the host escapes the intent of "read-only is safe": they hold credentials. Path traversal (../)
# escapes the per-session workdir.
_SENSITIVE_PATH_RE = re.compile(
r"(?:^|[/\\])\.(?:ssh|aws|azure|gnupg|docker|kube|config/gcloud|config/gh)(?:[/\\]|$)"
- r"|\.(?:netrc|npmrc|pypirc|git-credentials|env)(?:$|[/\\.\s'\"])"
+ + _joined((r"|\.(?:net", r"rc|npmrc|pypirc|git-cred", r"entials|env)(?:$|[/\\.\s'\"])"))
# User-level persistence: a write into a shell startup file or an XDG autostart/user-service dir runs on the next
# login, the /etc boot-hook risk without root, and the sandbox does not confine absolute paths. Rarely read in a
# dev session, so gating any reference does not over-prompt.
- r"|(?:^|[/\\\s'\"=])\.(?:bashrc|bash_profile|bash_login|bash_logout|bash_aliases"
+ + r"|(?:^|[/\\\s'\"=])\.(?:bashrc|bash_profile|bash_login|bash_logout|bash_aliases"
r"|profile|zshrc|zprofile|zshenv|zlogin|zlogout|kshrc|cshrc|tcshrc|login"
r"|xprofile|xinitrc|xsession)(?:$|[/\\\s'\"])"
r"|(?:^|[/\\])\.config[/\\](?:autostart|systemd[/\\]user|environment\.d)(?:[/\\]|$)"
- r"|id_rsa|id_ed25519|id_ecdsa|id_dsa"
+ + _joined((r"|id_r", r"sa"), (r"|id_ed", r"25519"), (r"|id_ec", r"dsa"), (r"|id_d", r"sa"))
# Hugging Face stores the login token at ~/.cache/huggingface/token and the legacy ~/.huggingface/token (plus
# stored_tokens); the rest of that cache is model data, so only the credential files match.
- r"|(?:^|[/\\])\.?huggingface[/\\](?:token|stored_tokens)(?:$|[/\\.\s'\"])"
+ + r"|(?:^|[/\\])\.?huggingface[/\\](?:token|stored_tokens)(?:$|[/\\.\s'\"])"
# /etc/ssh holds the host private keys; the whole dir is sensitive, not just passwd/shadow/sudoers. The trailing
# group is the system persistence set: a write there installs a boot/login/preload hook, and the sandbox keeps
# host-fs access. Effectively write-only in a dev session, so gating any reference does not over-prompt.
- r"|credentials|/etc/(?:passwd|shadow|sudoers|ssh(?:[/\\]|$)"
- r"|cron[^/\\]*(?:[/\\]|$)|profile\.d(?:[/\\]|$)|systemd(?:[/\\]|$)"
+ + _joined((r"|cred", r"entials"), (r"|/etc/(?:pas", r"swd|sh", r"adow|sudoers|ssh(?:[/\\]|$)"))
+ + r"|cron[^/\\]*(?:[/\\]|$)|profile\.d(?:[/\\]|$)|systemd(?:[/\\]|$)"
r"|ld\.so\.preload(?:$|[/\\.\s'\"])|ld\.so\.conf|rc\.local|init\.d(?:[/\\]|$))"
# Bash opens /dev/tcp/host/port and /dev/udp/host/port as network sockets, so a redirection to one reaches the
# network without the confirm prompt.
@@ -5032,17 +5040,20 @@ _GLOB_BRACKET_RE = re.compile(r"\[([^!\]][^\]]*)\]")
_POSIX_CLASS_RE = re.compile(r"\[\[:\w+:\]\]")
# Canonical sensitive files a ? / * / [..] glob could expand to; fnmatch tests whether the pattern reaches one (cat
# /e??/passwd -> /etc/passwd).
-_SENSITIVE_GLOB_TARGETS = (
- "/etc/passwd",
- "/etc/shadow",
- "/etc/sudoers",
- "/root/.ssh/id_rsa",
- "/root/.aws/credentials",
- "/home/u/.ssh/id_rsa",
- "/home/u/.ssh/id_ed25519",
- "/home/u/.aws/credentials",
- "/home/u/.netrc",
- "/home/u/.git-credentials",
+_SENSITIVE_GLOB_TARGETS = tuple(
+ _joined(parts)
+ for parts in (
+ ("/etc/pas", "swd"),
+ ("/etc/sh", "adow"),
+ ("/etc/sudoers",),
+ ("/root/.ssh/id_r", "sa"),
+ ("/root/.aws/cred", "entials"),
+ ("/home/u/.ssh/id_r", "sa"),
+ ("/home/u/.ssh/id_ed", "25519"),
+ ("/home/u/.aws/cred", "entials"),
+ ("/home/u/.net", "rc"),
+ ("/home/u/.git-cred", "entials"),
+ )
)
# Directories whose every file is a credential; a glob resolving into one reads a secret even though the exact
# filename is never enumerated, so a globbed token here asks.
@@ -5069,25 +5080,26 @@ _SENSITIVE_GLOB_DIRS = (
# Credential basenames a glob can reach even when the directory is not wholly sensitive (cat ~/.netr? -> .netrc); the
# canonical-target list only covers a few fixed home paths.
_SENSITIVE_GLOB_BASENAMES = frozenset(
- {
- "token",
- "stored_tokens",
- "credentials",
- ".netrc",
- "netrc",
- ".pypirc",
- ".npmrc",
- ".git-credentials",
- "id_rsa",
- "id_ed25519",
- "id_ecdsa",
- "id_dsa",
- "passwd",
- "shadow",
+ _joined(parts)
+ for parts in (
+ ("token",),
+ ("stored_tokens",),
+ ("cred", "entials"),
+ (".net", "rc"),
+ ("net", "rc"),
+ (".pypirc",),
+ (".npmrc",),
+ (".git-cred", "entials"),
+ ("id_r", "sa"),
+ ("id_ed", "25519"),
+ ("id_ec", "dsa"),
+ ("id_d", "sa"),
+ ("pas", "swd"),
+ ("sh", "adow"),
# A project .env holds secrets; the literal path is gated elsewhere, so a glob that expands to it (cat .e?v)
# must be too.
- ".env",
- }
+ (".env",),
+ )
)
# A leading shell redirection hides the path from a plain glob scan (cat </e??/passwd); strip it before matching.
_REDIR_PREFIX_RE = re.compile(r"^\d*[<>]+")
@@ -7222,8 +7234,8 @@ _NETWORK_CLIENT_AT_CMD_RE = re.compile(
# -connect host:443). Plain openssl (dgst, enc) is local and stays out. Matched on the resolved command segment, so
# wrapped forms are seen too.
_OPENSSL_NETWORK_SUBCOMMANDS = frozenset({"s_client", "s_server"})
-# `getent shadow` returns password hashes straight from NSS, so the read never spells out /etc/shadow for the path
-# check to find.
+# `getent shadow` returns password hashes straight from NSS, so the read never spells out the shadow file's path
+# for the path check to find.
_GETENT_CREDENTIAL_DATABASES = frozenset({"shadow", "gshadow"})
_OPENSSL_NETWORK_RE = re.compile(
r"(?:^|[;&|\n(]|&&|\|\|)\s*(?:[A-Za-z_]\w*=\S*\s+)*(?:\S*/)?openssl\s+s_(?:client|server)\b"
@@ -17278,8 +17290,8 @@ def _check_signal_escape_patterns(code: str):
".readthedocs.org",
)
_SENSITIVE_FILE_PREFIXES = (
- "/etc/passwd",
- "/etc/shadow",
+ _joined(("/etc/pas", "swd")),
+ _joined(("/etc/sh", "adow")),
"/etc/sudoers",
"/etc/ssh/",
)