Skip to content

fix(security): safe export parsing in provision.sh (#3075, #3071)#3084

Closed
la14-1 wants to merge 1 commit intomainfrom
fix/issue-3075
Closed

fix(security): safe export parsing in provision.sh (#3075, #3071)#3084
la14-1 wants to merge 1 commit intomainfrom
fix/issue-3075

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Mar 28, 2026

Why: The export parsing in provision.sh had a backslash detection bug and used sed subshells that could be replaced with safer POSIX parameter expansion for better bash 3.2 compatibility.

Changes

  • Replace sed extraction with POSIX parameter expansion: Uses ${var#pattern}, ${var%%pattern}, ${var%pattern} instead of two sed -n subshell calls per line. No external processes needed, fully bash 3.2 compatible.
  • Tighten case filter: Changed from export *=* (too permissive) to export [A-Za-z_]*="*" (requires proper export VAR="VALUE" form).
  • Add explicit name validation: Variable name must match [A-Za-z_][A-Za-z0-9_]* via case + grep check.
  • Fix backslash detection bug: The defense-in-depth check used *'\\'* which only matched double backslash (\\) due to single-quote literal semantics. Changed to *\\* which correctly matches any single backslash.

Verification

  • bash -n syntax check passes
  • All existing validation layers preserved (whitelist, injection char check, character whitelist)
  • No bash 4.x features used (no [[, no BASH_REMATCH, no =~)

Fixes #3075
Fixes #3071

-- refactor/code-health

Replace sed-based extraction with POSIX parameter expansion for
cloud_headless_env export parsing in provision.sh:

- Use ${var#pattern}/${var%%pattern}/${var%pattern} instead of sed
  subshells — no external processes, fully bash 3.2 compatible
- Tighten case filter: require proper export VAR="VALUE" form
  (was: export *=* which was too permissive)
- Add explicit name validation (must match [A-Za-z_][A-Za-z0-9_]*)
- Fix backslash detection: *\\* catches single backslash
  (was: *'\\'* which only matched double backslash)

Agent: code-health
Co-Authored-By: Claude Sonnet 4.5 <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

3 participants