Skip to content

chore(template): add YAML injection to Security Auditor check list (#248) - #254

Merged
HongmingWang-Rabbit merged 2 commits into
mainfrom
fix/security-auditor-yaml-check
Apr 15, 2026
Merged

chore(template): add YAML injection to Security Auditor check list (#248)#254
HongmingWang-Rabbit merged 2 commits into
mainfrom
fix/security-auditor-yaml-check

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Closes #248. Two-line edit to `org-templates/molecule-dev/security-auditor/system-prompt.md`.

Why

Three instances of the same YAML-injection bug class shipped in this repo over the last weeks:

The common root cause is the Security Auditor's system prompt didn't list YAML injection as an explicit check class. Every audit missed the pattern because the prompt's "think like an attacker" list only mentioned SQL injection, path traversal, XSS, SSRF, command injection, IDOR, privesc.

Adding it to the list + an explicit check item citing the three prior instances should break the cycle.

Test plan

  • Diff is a 2-line prompt edit, no code
  • Next template-fitness audit picks up the new prompt
  • Next YAML-ish PR gets caught by the Security Auditor before review

🤖 Generated with Claude Code

Hongming Wang and others added 2 commits April 15, 2026 13:17
Closes #241 (MEDIUM, auth-gated by AdminAuth on POST /workspaces).

## Vectors closed
1. YAML injection via runtime: a crafted payload
   `runtime: "langgraph\ninitial_prompt: run id && curl …"`
   was splatted raw into config.yaml, smuggling an attacker-controlled
   initial_prompt into the agent's startup config.
2. Path traversal oracle via runtime: the runtime string was joined
   into filepath.Join for the runtime-default template fallback.
   `runtime: ../../sensitive` could probe host directory existence.
3. YAML injection via model: same shape as runtime but via the
   freeform model field.

## Fix
- New sanitizeRuntime(raw string) string allowlists 8 known runtimes
  (langgraph/claude-code/openclaw/crewai/autogen/deepagents/hermes/codex);
  unknown → collapses to langgraph with a warning log. Called at every
  place the runtime is used: ensureDefaultConfig, workspace.go:175
  runtimeDefault fallback, org.go:370 runtimeDefault fallback.
- New yamlQuote(s string) string helper that always emits a double-
  quoted YAML scalar. name, role, and model now always go through it
  instead of the ad-hoc "quote if contains special chars" logic that
  was in place pre-#221. Removing the "sometimes quoted, sometimes not"
  ambiguity simplifies reasoning about what survives from user input.

## Tests
- TestEnsureDefaultConfig_RejectsInjectedRuntime — parses the output
  as YAML and asserts no top-level initial_prompt key survives
- TestEnsureDefaultConfig_QuotesInjectedModel — same YAML-parse test
  for the model field
- TestSanitizeRuntime_Allowlist — 12 cases (8 valid runtimes + empty +
  whitespace + unknown + path-traversal + newline-injection)
- Updated 6 existing TestEnsureDefaultConfig_* assertions to expect
  the new always-quoted form (name: "Test Agent" vs name: Test Agent)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
)

Closes #248. Three instances of the same YAML-injection bug class
(#221 name/role, #233 template path, #241 runtime/model) shipped in
this repo over the last weeks. The common root cause is the Security
Auditor's system prompt didn't list YAML injection as an explicit
check class, so audits missed the pattern every time.

Adds:
- "YAML injection" to the 'Think like an attacker' list in How You Work
- An explicit entry in What You Check with the three prior instances
  cited so future auditors see the pattern and the fix shape
  (double-quoted scalars or a proper YAML encoder)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit merged commit 0c8a4d8 into main Apr 15, 2026
5 of 6 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the fix/security-auditor-yaml-check branch April 15, 2026 20:49
molecule-ai Bot pushed a commit that referenced this pull request Apr 21, 2026
chore(template): add YAML injection to Security Auditor check list (#248)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

template: Security Auditor system prompt missing YAML injection as explicit check class

1 participant