Skip to content

fix: escape single quotes in Policy.pm shell output#17

Draft
Koan-Bot wants to merge 1 commit intoPerl-Toolchain-Gang:mainfrom
Koan-Bot:koan.atoomic/fix-shell-injection-policy
Draft

fix: escape single quotes in Policy.pm shell output#17
Koan-Bot wants to merge 1 commit intoPerl-Toolchain-Gang:mainfrom
Koan-Bot:koan.atoomic/fix-shell-injection-policy

Conversation

@Koan-Bot
Copy link

@Koan-Bot Koan-Bot commented Mar 19, 2026

What

Escape single quotes in default_Policy() before interpolating ccflags into shell script output.

Why

ccflags array values were interpolated directly into a single-quoted shell string (ccflags='@ccflags'). A value containing ' (e.g. -DPATH='/usr/local') would break shell quoting and could enable command injection in the generated Policy.sh.

SECURITY — Shell injection via unescaped single quotes in generated Policy.sh. Values with crafted single quotes could break out of the shell string and execute arbitrary commands.

How

Added _shell_escape_sq() helper that applies the standard shell idiom: replace each ' with '\'' (close quote, escaped literal quote, reopen quote). Called on every ccflag value in default_Policy() before interpolation.

Note: _do_subst() has a similar pattern (substituting values into ccflags lines) but operates on user-provided policy templates where the quoting context varies — flagged for separate evaluation.

Testing

  • 4 new tests covering: no-op on clean strings, single-quote escaping, backtick passthrough, mixed flags
  • All 41 tests pass (existing + new)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 37 insertions(+), 2 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

ccflags values were interpolated directly into a single-quoted shell
string without escaping. A value containing a single quote (e.g.
-DPATH='/usr/local') would break the shell quoting and could enable
command injection in the generated Policy.sh script.

Add _shell_escape_sq() helper that replaces ' with '\'' (the standard
shell idiom: close quote, escaped literal quote, reopen quote). Apply
it to all ccflags values before interpolation in default_Policy().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant