Skip to content

fix(settings): deny inline Python fed via heredoc and stdin pipelines (#2797) - #2803

Open
isihussain wants to merge 1 commit into
danielmiessler:mainfrom
isihussain:fix/deny-python-stdin-heredoc-pipeline
Open

isihussain wants to merge 1 commit into
danielmiessler:mainfrom
isihussain:fix/deny-python-stdin-heredoc-pipeline

Conversation

@isihussain

Copy link
Copy Markdown

Summary

Fixes #2797.

The shipped deny rules for inline Python in settings.system.json covered program strings passed via -c (python -c *, python3 -c *) and stdin invocations with trailing argument globs (python - *, python3 - *). However, they did not match:

  1. Heredocs feeding code to stdin without -c or dash: python3 <<'PY' ... PY.
  2. Pipeline commands where a bare interpreter reads from stdin: ... | python3 or ... | python.
  3. Bare dash invocations without trailing characters: python - or python3 -.

Because Python reads from stdin when invoked without a script argument, these forms bypassed the deny rules and permitted inline authoring contrary to the system prompt's language rule.

Solution

  1. Added deny rules in LifeOS/install/settings.system.json and LifeOS/install/skills/LifeOS/install/settings.system.json:
    • Bash(python -) and Bash(python3 -)
    • Bash(python <<) and Bash(python3 <<)
    • Bash(python) and Bash(python3)
  2. Added unit tests in LifeOS/install/settings.permissions.test.ts verifying that:
    • -c and stdin dash forms are denied.
    • Heredoc programs on stdin are denied.
    • Piped programs on stdin are denied.
    • Running existing script files (python3 tool.py --input data.csv, python3 -u tool.py) stays allowed.

Signed-off-by: isihussain isihussain@users.noreply.github.com

…danielmiessler#2797)

The native deny rules in settings.system.json previously covered
program strings passed on the command line ('python -c *', 'python3 -c *')
and stdin flags with trailing arguments ('python - *', 'python3 - *'),
but missed stdin programs fed via heredoc (e.g. python3 <<'PY' ... PY)
or via pipes (e.g. ... | python3), as well as bare interpreter invocations
('python -', 'python3 -').

Add deny rules for:
- 'Bash(python -)' and 'Bash(python3 -)'
- 'Bash(python <<*)' and 'Bash(python3 <<*)'
- 'Bash(python)' and 'Bash(python3)'

Keep script execution ('python3 tool.py --input data.csv') allowed.
Add settings.permissions.test.ts verifying rejection of -c, -, heredocs,
and pipeline stdin while preserving script execution.

Closes danielmiessler#2797

Signed-off-by: isihussain <isihussain@users.noreply.github.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.

Inline-Python deny rules miss a program fed on stdin (heredoc or pipe); follow-up to #2475

1 participant