Skip to content

Harden the git argument handling flagged by a security review - #1

Open
HugoHeneault wants to merge 2 commits into
mainfrom
fix/git-argument-hardening
Open

HugoHeneault wants to merge 2 commits into
mainfrom
fix/git-argument-hardening

Conversation

@HugoHeneault

Copy link
Copy Markdown
Contributor

Four findings from a review of src/, ordered by what they cost.

Push flags matched on a substring. answer.contains('n') meant answering none to
push flags? pushed with --no-verify, skipping every pre-push hook, including any secret
scanning, without a word in the output. lol enabled --force-with-lease the same way.
parse_push_options now takes the whole answer and rejects anything that is not l, n, ln,
nl or empty.

Paths came back quoted. core.quotepath=false only stops the quoting of bytes above 0x80: a
path holding ", \ or a control character is still C-quoted by git. we"ird.txt reached us as
"we\"ird.txt", a path that exists nowhere, so the file was reported as deleted and git add --
could never stage it. diff --numstat and ls-files now run with -z and are split on NUL.

The mtime fallback climbed out of the repo. For a deleted file whose parent directories are
gone too, path.ancestors() walked past the repo root, dating the repo from an unrelated
directory. The walk now stops at the repo.

The directory walk was unbounded. Depth capped at MAX_SCAN_DEPTH.

Two tests added, 16 pass. Checked end to end against a throwaway repo holding we"ird.txt and
new"file.txt: three files, counts exact, no longer reported as deleted.

- Push flags take a whole flag word: a substring match turned "none" into
  --no-verify, skipping the pre-push hooks with nothing said about it.
- Paths are read NUL terminated, the only git output that leaves a quote, a
  backslash or a control character unquoted. Such a file used to reach git as
  its quoted form, so it showed up as deleted and could not be staged.
- The mtime fallback walk stops at the repo instead of climbing above it.
- The directory walk is depth capped, so a deep tree cannot exhaust the stack.
The three comments marking a deliberate ceiling carried a prefix naming a local
editing mode, which means nothing to a reader of this repository. The ceilings
and the way to lift them stay, the prefix goes.
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.

1 participant