Skip to content

security: stop sourcing .env as shell code in ops scripts #87

@devswha

Description

@devswha

Problem

Several ops scripts execute .env with shell source semantics.

Evidence:

  • ops/runtime-cli.sh:5-10
  • ops/runtime-bootstrap.sh:9-14
  • ops/bot.sh:10-15
  • ops/harness.sh:7-12
  • ops/marketing-runtime-bootstrap.sh:10-15
  • ops/marketing-runtime-cli.sh:5-10

All use set -a; . "$ENV_FILE"; set +a.

Impact

If .env or PATINA_ENV_FILE is writable or attacker-controlled, running these scripts executes arbitrary shell code before validation. These scripts can configure runtime, access Discord tokens, and launch autonomous agents.

Suggested fix

  • Replace shell sourcing with a strict key=value parser
  • Reuse the safer parsing style from ops/component-bridge.mjs:11-34
  • Reject unsupported syntax such as command substitution, semicolons, and multiline shell
  • Check .env ownership and reject group/world-writable files where practical

Validation

  • .env values still load for normal KEY=value and quoted values
  • A malicious .env line like X=$(touch /tmp/pwned) is not executed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions