aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-uri.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2025-05-28 12:53:52 -0400
committerTaylor Blau <me@ttaylorr.com>2025-05-28 12:54:03 -0400
commitd2bc61fcabd6cfa582d286bed1ce20d5d7c58d52 (patch)
tree770b32cd1b46b20022f22fda2074967d0cb196da /bundle-uri.c
parentMerge branch 'js/gitk-git-gui-harden-exec-open' into maint-2.43 (diff)
parentbundle-uri: fix arbitrary file writes via parameter injection (diff)
downloadgit-d2bc61fcabd6cfa582d286bed1ce20d5d7c58d52.tar.gz
git-d2bc61fcabd6cfa582d286bed1ce20d5d7c58d52.zip
Merge branch 'ps/bundle-uri-arbitrary-writes' into maint-2.43
This merges in the fix for CVE-2025-48385. * ps/bundle-uri-arbitrary-writes: bundle-uri: fix arbitrary file writes via parameter injection Signed-off-by: Taylor Blau <me@ttaylorr.com>
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 ca32050a78..a6a3c1c4b3 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -292,6 +292,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;