Skip to content

fix: SEC-01 eliminate shell-variable injection in gc-scheduled.sh#60

Closed
majiayu000 wants to merge 3 commits intomainfrom
feat/fix-sec01-gc-shell-injection
Closed

fix: SEC-01 eliminate shell-variable injection in gc-scheduled.sh#60
majiayu000 wants to merge 3 commits intomainfrom
feat/fix-sec01-gc-shell-injection

Conversation

@majiayu000
Copy link
Copy Markdown
Owner

Summary

  • Replace all three python3 -c "...${VAR}..." invocations with <<'PYEOF' heredocs so the shell never expands variables inside Python source
  • Pass LOG_DIR, VIBEGUARD_DIR, REFLECTION_FILE, mf, and CUTOFF via the command's environment (VAR=value python3 -) and read them with os.environ[...]
  • Block 1 (metrics loop): Python now tracks the original line count internally, removing the ${BEFORE} interpolation
  • Block 2 (learn-digest): also fixes output.split('\\n')output.split('\n') (was only correct by accident in the -c "..." context)

Root cause

${LOG_DIR} derives from VIBEGUARD_LOG_DIR env var (line 12). A value containing a single-quote (e.g. /tmp/x'; import os; os.system('id') #) breaks the embedded Python syntax and enables arbitrary code execution when the scheduled GC job runs under systemd/launchd.

Test plan

  • bash -n scripts/gc/gc-scheduled.sh passes (syntax OK)
  • Manual smoke-test: set VIBEGUARD_LOG_DIR to a path containing a single-quote; confirm the script exits cleanly rather than executing injected code
  • Existing shell-script tests in tests/ continue to pass

Closes #56

…hon blocks

Replace all three python3 -c "...${VAR}..." invocations with
heredoc (<<'PYEOF') style so shell never expands variables inside
Python source code.

- Block 1 (metrics loop): pass ${mf} and ${CUTOFF} via env vars
  METRICS_FILE / CUTOFF; Python reads via os.environ; tracks
  original line count internally instead of interpolating ${BEFORE}.
- Block 2 (learn-digest): pass LOG_DIR and VIBEGUARD_DIR via env;
  fix output.split('\\n') → split('\n') which was only correct by
  accident inside a double-quoted -c string.
- Block 3 (reflection): pass LOG_DIR and REFLECTION_FILE via env.

Closes #56

Signed-off-by: majiayu000 <1835304752@qq.com>
…ator

docs/how/memory-files.md:9 references `project/.claude/CLAUDE.md` as an
example path (not a real repo file). Add it to the allowlist to fix CI.

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000
Copy link
Copy Markdown
Owner Author

/gemini review

…edoc Python blocks

Backslash escapes inside f-string {} expressions are a SyntaxError in Python.
In a <<'PYEOF' heredoc the shell performs no unescaping, so \" reached Python
as a literal backslash+quote and caused both the learn-digest and reflection
phases to abort silently.  Replace \"...\" with "..." inside the four affected
f-string expressions (valid because the outer f-strings use single quotes).
@majiayu000
Copy link
Copy Markdown
Owner Author

Superseded by PR #58 (already merged) which fixes the same SEC-01 issue using GC env var prefix approach.

@majiayu000 majiayu000 closed this Apr 12, 2026
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.

[P1] SEC-01: Shell-variable injection into Python -c strings in gc-scheduled.sh

1 participant