aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-uri.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-07 15:08:10 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-07 15:08:10 -0700
commit038143def708a65455172a87432aee27da2d80c4 (patch)
treea6271d7824fe36b364f6f19f2437de785820aab8 /bundle-uri.c
parentThe seventh batch (diff)
parentGit 2.50.1 (diff)
downloadgit-038143def708a65455172a87432aee27da2d80c4.tar.gz
git-038143def708a65455172a87432aee27da2d80c4.zip
Sync with Git 2.50.1
Diffstat (limited to 'bundle-uri.c')
-rw-r--r--bundle-uri.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/bundle-uri.c b/bundle-uri.c
index c9d65aa0ce..8708d189e3 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -297,6 +297,28 @@ static int download_https_uri_to_file(const char *file, const char *uri)
struct strbuf line = STRBUF_INIT;
int found_get = 0;
+ /*
+ * The protocol we speak with git-remote-https(1) uses a space to
+ * separate between URI and file, so the URI itself must not contain a
+ * space. If it did, an adversary could change the location where the
+ * downloaded file is being written to.
+ *
+ * Similarly, we use newlines to separate commands from one another.
+ * Consequently, neither the URI nor the file must contain a newline or
+ * otherwise an adversary could inject arbitrary commands.
+ *
+ * TODO: Restricting newlines in the target paths may break valid
+ * usecases, even if those are a bit more on the esoteric side.
+ * If this ever becomes a problem we should probably think about
+ * alternatives. One alternative could be to use NUL-delimited
+ * requests in git-remote-http(1). Another alternative could be
+ * to use URL quoting.
+ */
+ if (strpbrk(uri, " \n"))
+ return error("bundle-uri: URI is malformed: '%s'", file);
+ if (strchr(file, '\n'))
+ return error("bundle-uri: filename is malformed: '%s'", file);
+
strvec_pushl(&cp.args, "git-remote-https", uri, NULL);
cp.err = -1;
cp.in = -1;