Arbitrary shell code execution via unsanitized .env sourcing #3
Labels
No labels
shellcheck
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
bc1bb/claude-code-audit#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
audit.shsources the.envfile withsource "$SCRIPT_DIR/.env"inside aset -ablock without any validation of the file's contents.sourceexecutes the file as shell code, not as a simple key=value parser.Location
audit.sh, lines 54–57:Risk
If an attacker gains write access to the
.envfile (e.g., via misconfigured filesystem permissions, a compromised CI/CD pipeline writing to the workspace, or a path traversal in another part of the system), they can execute arbitrary shell commands as the user runningaudit.sh. Sinceset -ais active, all variables — including injected ones — are exported to every child process, including theclaudeCLI and all git commands. A malicious.envcould also redefineREPOS_DIR,LOG_DIR, orFORGEJO_URLto redirect the audit to an attacker-controlled endpoint.Suggested fix direction
Replace
sourcewith a dedicated key=value parser that only reads lines matching^[A-Z_]+=and rejects everything else. Example:while IFS='=' read -r key val; do export "$key=$val"; done < <(grep -E '^[A-Z_]+=' .env). This prevents shell metacharacters in the file from being interpreted.Severity
moderate
Found by
Automated audit by Claude Code