T09 · Insecure Skill Coding Practices
- Location
scripts/guard_and_run.py:366- Finding
Human-review findings are permitted to execute by default
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This skill is a disclosed outbound guardrail tool, but its optional command-running wrapper has unsafe defaults and escape hatches that warrant careful review before installation.
Install only if you need both the policy checker and the command wrapper. For production use, prefer direct checker-only mode or require --strict, absolute-path allowlists, --sanitize-env with narrow keep rules, no --allow-any-command, and careful audit-log handling because command arguments and inherited credentials can be sensitive.
scripts/guard_and_run.py:366Human-review findings are permitted to execute by default
scripts/guard_and_run.py:107Executable-name allowlist can be bypassed through PATH substitution
scripts/guard_and_run.py:678Rejected command arguments can be written to audit logs in plaintext
The declared description frames this as a legal/compliance guardrail, but the documented behavior includes a generic command-execution adapter, environment propagation controls, allowlist bypasses, and audit logging. This mismatch is dangerous because users may invoke or approve the skill assuming it only evaluates text, while it can act as an execution boundary that launches local commands, which materially increases attack surface and the risk of misuse or privilege abuse.
The skill metadata and docstring frame this as enterprise legal/compliance guardrails, but the implementation includes generic local command execution. That mismatch materially increases risk because operators may grant this skill trust and permissions appropriate for policy review, not for arbitrary process execution.
The --allow-any-command path explicitly bypasses the command allowlist and permits execution of any local command when a reason and token are provided, both of which can come from flags or environment variables. For a legal/compliance guardrail skill, this creates a direct arbitrary command execution escape hatch that undermines the control's stated purpose.
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
def run(*args: str, env: dict[str, str] | None = None, input_text: str | None = None) -> tuple[int, str, str]:
if env is None:
base_env = dict(os.environ)
if not any(
base_env.get(name)
for name in (
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
assert "requires delimiter --" in err, (out, err)
# 6b) Missing allowlist by explicit env var should block execution.
env_no_allowlist = {k: v for k, v in os.environ.items() if k not in {
"ENTERPRISE_LEGAL_GUARDRAILS_ALLOWED_COMMANDS",
"ELG_ALLOWED_COMMANDS",
"BABYLON_ALLOWED_COMMANDS",
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
assert "requires delimiter --" in err, (out, err)
# 6b) Missing allowlist by explicit env var should block execution.
env_no_allowlist = {k: v for k, v in os.environ.items() if k not in {
"ENTERPRISE_LEGAL_GUARDRAILS_ALLOWED_COMMANDS",
"ELG_ALLOWED_COMMANDS",
"BABYLON_ALLOWED_COMMANDS",
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
"--",
"cat",
"/etc/hosts",
env={**os.environ.copy(), "BABYLON_ALLOWED_COMMANDS": "python3"},
)
assert code == 1, (code, out, err)
assert "not in the allowlist" in err, (out, err)
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
"--",
"cat",
"/etc/hosts",
env={**os.environ.copy(), "BABYLON_ALLOWED_COMMANDS": "python3"},
)
assert code == 1, (code, out, err)
assert "not in the allowlist" in err, (out, err)
The tested --allow-any-command escape hatch intentionally bypasses the command allowlist when a reason and token are supplied, defeating the primary execution safeguard. In a guardrails skill, this is especially risky because it creates a built-in path from constrained execution to arbitrary command execution if tokens are exposed, guessed, mishandled, or approved too broadly.
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
"python3",
"-c",
"import os; print('KEEP_ME' in os.environ, any(k.startswith('SHARED_') for k in os.environ), 'DROP_ME' in os.environ)",
env={
**os.environ,
"KEEP_ME": "1",
"SHARED_TOKEN": "2",
Code enumerates, copies, or searches environment variables for secrets. Bulk environment access can collect credentials unrelated to the skill's stated purpose.
# 16) Execution requires explicit enablement unless --dry-run is used.
with tempfile.TemporaryDirectory() as tmpdir:
log_path = Path(tmpdir) / "execute_disabled.jsonl"
env_execute_off = {
**os.environ,
"ENTERPRISE_LEGAL_GUARDRAILS_EXECUTE": "0",
}
The skill exposes shell, file read/write, and environment-dependent behavior but does not declare an explicit tool scope or permissions boundary in the skill manifest. That creates a trust gap: downstream users and orchestrators may treat it as a passive policy checker, while the documented wrapper can execute commands and handle environment variables, increasing the chance of over-privileged or unintended use.
The manifest says the skill provides legal/compliance guardrails for anti-spam, defamation, privacy, and financial claims, but the code additionally scans for harassment and targeted abuse. While related to moderation, this is a distinct policy domain not represented in the stated purpose, creating a description-to-behavior mismatch.
The manifest describes guardrails for anti-spam, defamation, privacy, and financial claims, but the code also enforces a separate HR-sensitive workplace language policy. This expands the skill from the declared outbound legal/compliance domains into employee-relations content moderation, which is not disclosed in the manifest description.
The documentation minimizes the capability as a guardrail adapter for outbound/public-facing workflows, while the code can launch broad local commands unrelated to outbound actions. This deceptive or incomplete framing increases the chance of unsafe deployment, overtrust, and accidental exposure of powerful execution capability.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
start = time.perf_counter()
try:
proc = subprocess.run(
args,
text=True,
capture_output=True,
This subprocess invocation executes a user-supplied command after only allowlist checks, turning a legal/compliance guardrail skill into a general local command runner. In this skill context, that is dangerous because any misconfiguration, overbroad allowlist, or enabled bypass can lead to arbitrary local code execution under the agent's privileges.
command_ms = None
command_start = time.perf_counter()
try:
proc = subprocess.run(command, check=False, env=env, timeout=args.command_timeout)
command_ms = int((time.perf_counter() - command_start) * 1000)
except FileNotFoundError:
msg = f"Command not found: {command[0]}"
The test suite validates and normalizes behavior for a command-executing adapter far beyond the stated legal/compliance purpose, including command execution, environment passing, allowlist logic, and bypass cases. That widens the operational scope of the skill into a generic execution wrapper, increasing the chance it is reused as an execution primitive in contexts where only content guardrails were expected.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
base_env["ENTERPRISE_LEGAL_GUARDRAILS_EXECUTE"] = "1"
command = [sys.executable, str(SCRIPT), *args]
proc = subprocess.run(
command,
env=base_env,
input=input_text,
Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.
env=env_no_allowlist,
)
assert code == 2, (code, out, err)
assert "Refusing --allow-any-command without approval token" in err, (out, err)
# 12d) Unsafe escape hatch: allow any command only when explicitly enabled + reason+token.
code, out, err = run(
Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.
env=env_no_allowlist,
)
assert code == 2, (code, out, err)
assert "Refusing --allow-any-command without approval token" in err, (out, err)
# 12d) Unsafe escape hatch: allow any command only when explicitly enabled + reason+token.
code, out, err = run(
The top-level docstring presents the tool as a deterministic local scan with no outside dependencies, but the implementation is also parameterized by multiple environment variables, including Babylon-specific app/scope settings. This is not a direct security problem, but the documentation overstates self-containment and omits behavior that materially affects when guardrails apply.
No suspicious patterns detected.