sourcegraph/cmd
Erik Seliger 4932f0a4b1
gitserver: Use git-diff-tree to simplify validation and improve security (#62709)
At some point in the past, we noticed that passing /dev/passwd and /dev/null to `git diff` allows to view the file contents, even though it's not part of the repo itself.
That allows to read arbitrary files on disk, so we had to add in-app validation for file paths, including relative paths.
That makes the validation much more complex and harder to reason about, and requires that we didn't make a mistake.

Instead, we switch to `git diff-tree` which validates paths are part of the tree properly.
By that, we can remove a bunch of complexity around git diff argument validation.

See here for the difference:

```
➜  sourcegraph git:(main) git diff-tree --find-renames --full-index --inter-hunk-context=3 --no-prefix -- /etc/hosts /dev/null
fatal: /etc/hosts: '/etc/hosts' is outside repository at '/Users/erik/Code/sourcegraph/sourcegraph'
➜  sourcegraph git:(main) git --no-pager diff --find-renames --full-index --inter-hunk-context=3 --no-prefix -- /etc/hosts /dev/null
diff --git etc/hosts etc/hosts
deleted file mode 100644
index deadbeef..0000000000000000000000000000000000000000
--- etc/hosts
+++ /dev/null
@@ -1,16 +0,0 @@
-##
-# Host Database
-#
-# localhost is used to configure the loopback interface
-# when the system is booting.  Do not change this entry.
-##
-127.0.0.1	localhost
```

This PR also skips over arguments past the `--` boundary which in git means "everything after this will not be interpreted as an argument".
This previously caused `git cat-file HEAD -- -file.txt` to fail argument validation, although it's perfectly valid and not a risk.

Test plan:

Adjusted the tests for argument validation and existing tests for diff and integration and E2E tests are still passing.
2024-05-16 17:34:24 +02:00
..
appliance appliance: namespace scoping (#62663) 2024-05-15 17:32:53 +01:00
batcheshelper bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
blobstore bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
bundled-executor bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
cody-gateway bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
embeddings bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
enterprise-portal enterprise-portal: initialize service with dotcom DB connection (#62525) 2024-05-09 23:30:39 +00:00
executor bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
executor-kubernetes bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
frontend gitserver: Allow multiple ranges to be passed to Commits (#62705) 2024-05-16 17:34:09 +02:00
gitserver gitserver: Use git-diff-tree to simplify validation and improve security (#62709) 2024-05-16 17:34:24 +02:00
loadtest bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
migrator bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
msp-example bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
pings bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
precise-code-intel-worker bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
repo-updater bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
searcher bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
server gitserver: Simplify invocation of p4-fusion (#62070) 2024-05-02 01:44:53 +02:00
symbols gitserver: Allow multiple ranges to be passed to Commits (#62705) 2024-05-16 17:34:09 +02:00
syntactic-code-intel-worker bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
telemetry-gateway bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
worker bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
README.md Reminder to keep architecture diagram in-sync (#36869) 2022-06-08 19:40:36 -07:00

This directory contains Sourcegraph services and binaries.

When a services is added, removed, or when a service's dependencies change, update our architecture diagram.