Harden git_gate.py shell rendering #166

Merged
didericis merged 1 commits from fix/shell-injection-git-gate into main 2026-06-03 00:47:34 -04:00
Collaborator

Closes #155.

Summary

  • bot_bottle/git_gate.pygit_gate_render_entrypoint() now calls shlex.quote() on both name and upstream_url before embedding them in the generated sh script, so values containing single quotes, spaces, semicolons, or other shell metacharacters cannot break or inject into the entrypoint.
  • bot_bottle/manifest_git.pyGitEntry.from_repos_entry() now rejects repo names that do not match [A-Za-z0-9._-]+, making the manifest the first line of defence and shlex.quote() the belt-and-suspenders backstop.
  • tests/unit/test_git_gate.py — regression tests for a single-quoted URL and a URL with spaces/semicolons; the existing test_one_init_repo_call_per_upstream assertion is updated to parse the call via shlex.split rather than string-matching the raw quoted form.
  • tests/unit/test_manifest_git.py — four name-validation tests (', , ;, $ all rejected; my.repo-name_1 accepted).

Changes (1 commit)

  • cc0c952 fix(security): harden git_gate.py shell rendering with shlex.quote and name validation
Closes #155. ## Summary - **`bot_bottle/git_gate.py`** — `git_gate_render_entrypoint()` now calls `shlex.quote()` on both `name` and `upstream_url` before embedding them in the generated sh script, so values containing single quotes, spaces, semicolons, or other shell metacharacters cannot break or inject into the entrypoint. - **`bot_bottle/manifest_git.py`** — `GitEntry.from_repos_entry()` now rejects repo names that do not match `[A-Za-z0-9._-]+`, making the manifest the first line of defence and `shlex.quote()` the belt-and-suspenders backstop. - **`tests/unit/test_git_gate.py`** — regression tests for a single-quoted URL and a URL with spaces/semicolons; the existing `test_one_init_repo_call_per_upstream` assertion is updated to parse the call via `shlex.split` rather than string-matching the raw quoted form. - **`tests/unit/test_manifest_git.py`** — four name-validation tests (`'`, ` `, `;`, `$` all rejected; `my.repo-name_1` accepted). ## Changes (1 commit) - [`cc0c952`](https://gitea.dideric.is/didericis/bot-bottle/src/commit/cc0c952d0b1b1471ee6c43a09dcdf5228d7d0986/bot_bottle/git_gate.py) fix(security): harden git_gate.py shell rendering with shlex.quote and name validation
didericis-claude added 1 commit 2026-06-03 00:41:47 -04:00
fix(security): harden git_gate.py shell rendering with shlex.quote and name validation
test / unit (pull_request) Successful in 35s
test / integration (pull_request) Successful in 44s
test / unit (push) Successful in 32s
test / integration (push) Successful in 41s
cc0c952d0b
Use shlex.quote() on name and upstream_url in git_gate_render_entrypoint()
so special characters (single quotes, spaces, semicolons) cannot break or
inject into the generated sh script.

Add _GIT_NAME_RE validation in GitEntry.from_repos_entry() to restrict
repo names to [A-Za-z0-9._-]+, making the manifest the first line of
defence and shlex.quote() the belt-and-suspenders backstop.

Closes #155
didericis approved these changes 2026-06-03 00:47:27 -04:00
didericis merged commit cc0c952d0b into main 2026-06-03 00:47:34 -04:00
didericis deleted branch fix/shell-injection-git-gate 2026-06-03 00:47:35 -04:00
Sign in to join this conversation.