|
|
647f52 |
From cfa4e13f09d07f679ffacdddfbe0ef44d1de32d9 Mon Sep 17 00:00:00 2001
|
|
|
647f52 |
From: Petr Stodulka <pstodulk@redhat.com>
|
|
|
647f52 |
Date: Wed, 28 Oct 2015 15:21:08 +0100
|
|
|
647f52 |
Subject: [PATCH 2/5] transport: add a protocol-whitelist environment variable
|
|
|
647f52 |
|
|
|
647f52 |
If we are cloning an untrusted remote repository into a
|
|
|
647f52 |
sandbox, we may also want to fetch remote submodules in
|
|
|
647f52 |
order to get the complete view as intended by the other
|
|
|
647f52 |
side. However, that opens us up to attacks where a malicious
|
|
|
647f52 |
user gets us to clone something they would not otherwise
|
|
|
647f52 |
have access to (this is not necessarily a problem by itself,
|
|
|
647f52 |
but we may then act on the cloned contents in a way that
|
|
|
647f52 |
exposes them to the attacker).
|
|
|
647f52 |
|
|
|
647f52 |
Ideally such a setup would sandbox git entirely away from
|
|
|
647f52 |
high-value items, but this is not always practical or easy
|
|
|
647f52 |
to set up (e.g., OS network controls may block multiple
|
|
|
647f52 |
protocols, and we would want to enable some but not others).
|
|
|
647f52 |
|
|
|
647f52 |
We can help this case by providing a way to restrict
|
|
|
647f52 |
particular protocols. We use a whitelist in the environment.
|
|
|
647f52 |
This is more annoying to set up than a blacklist, but
|
|
|
647f52 |
defaults to safety if the set of protocols git supports
|
|
|
647f52 |
grows). If no whitelist is specified, we continue to default
|
|
|
647f52 |
to allowing all protocols (this is an "unsafe" default, but
|
|
|
647f52 |
since the minority of users will want this sandboxing
|
|
|
647f52 |
effect, it is the only sensible one).
|
|
|
647f52 |
|
|
|
647f52 |
A note on the tests: ideally these would all be in a single
|
|
|
647f52 |
test file, but the git-daemon and httpd test infrastructure
|
|
|
647f52 |
is an all-or-nothing proposition rather than a test-by-test
|
|
|
647f52 |
prerequisite. By putting them all together, we would be
|
|
|
647f52 |
unable to test the file-local code on machines without
|
|
|
647f52 |
apache.
|
|
|
647f52 |
---
|
|
|
647f52 |
Documentation/git.txt | 32 ++++++++++++++++++++++++++++++++
|
|
|
647f52 |
connect.c | 4 ++++
|
|
|
647f52 |
transport-helper.c | 2 ++
|
|
|
647f52 |
transport.c | 21 ++++++++++++++++++++-
|
|
|
647f52 |
transport.h | 7 +++++++
|
|
|
647f52 |
5 files changed, 65 insertions(+), 1 deletion(-)
|
|
|
647f52 |
|
|
|
647f52 |
diff --git a/Documentation/git.txt b/Documentation/git.txt
|
|
|
647f52 |
index 443d88f..179a0e8 100644
|
|
|
647f52 |
--- a/Documentation/git.txt
|
|
|
647f52 |
+++ b/Documentation/git.txt
|
|
|
647f52 |
@@ -847,6 +847,38 @@ GIT_LITERAL_PATHSPECS::
|
|
|
647f52 |
literal paths to Git (e.g., paths previously given to you by
|
|
|
647f52 |
`git ls-tree`, `--raw` diff output, etc).
|
|
|
647f52 |
|
|
|
647f52 |
+`GIT_ALLOW_PROTOCOL`::
|
|
|
647f52 |
+ If set, provide a colon-separated list of protocols which are
|
|
|
647f52 |
+ allowed to be used with fetch/push/clone. This is useful to
|
|
|
647f52 |
+ restrict recursive submodule initialization from an untrusted
|
|
|
647f52 |
+ repository. Any protocol not mentioned will be disallowed (i.e.,
|
|
|
647f52 |
+ this is a whitelist, not a blacklist). If the variable is not
|
|
|
647f52 |
+ set at all, all protocols are enabled. The protocol names
|
|
|
647f52 |
+ currently used by git are:
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - `file`: any local file-based path (including `file://` URLs,
|
|
|
647f52 |
+ or local paths)
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - `git`: the anonymous git protocol over a direct TCP
|
|
|
647f52 |
+ connection (or proxy, if configured)
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - `ssh`: git over ssh (including `host:path` syntax,
|
|
|
647f52 |
+ `git+ssh://`, etc).
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - `rsync`: git over rsync
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - `http`: git over http, both "smart http" and "dumb http".
|
|
|
647f52 |
+ Note that this does _not_ include `https`; if you want both,
|
|
|
647f52 |
+ you should specify both as `http:https`.
|
|
|
647f52 |
+
|
|
|
647f52 |
+ - any external helpers are named by their protocol (e.g., use
|
|
|
647f52 |
+ `hg` to allow the `git-remote-hg` helper)
|
|
|
647f52 |
++
|
|
|
647f52 |
+Note that this controls only git's internal protocol selection.
|
|
|
647f52 |
+If libcurl is used (e.g., by the `http` transport), it may
|
|
|
647f52 |
+redirect to other protocols. There is not currently any way to
|
|
|
647f52 |
+restrict this.
|
|
|
647f52 |
+
|
|
|
647f52 |
|
|
|
647f52 |
Discussion[[Discussion]]
|
|
|
647f52 |
------------------------
|
|
|
647f52 |
diff --git a/connect.c b/connect.c
|
|
|
647f52 |
index f57efd0..6d4ea13 100644
|
|
|
647f52 |
--- a/connect.c
|
|
|
647f52 |
+++ b/connect.c
|
|
|
647f52 |
@@ -6,6 +6,7 @@
|
|
|
647f52 |
#include "run-command.h"
|
|
|
647f52 |
#include "remote.h"
|
|
|
647f52 |
#include "url.h"
|
|
|
647f52 |
+#include "transport.h"
|
|
|
647f52 |
|
|
|
647f52 |
static char *server_capabilities;
|
|
|
647f52 |
|
|
|
647f52 |
@@ -587,6 +588,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
|
|
|
647f52 |
* cannot connect.
|
|
|
647f52 |
*/
|
|
|
647f52 |
char *target_host = xstrdup(host);
|
|
|
647f52 |
+ transport_check_allowed("git");
|
|
|
647f52 |
if (git_use_proxy(host))
|
|
|
647f52 |
conn = git_proxy_connect(fd, host);
|
|
|
647f52 |
else
|
|
|
647f52 |
@@ -623,6 +625,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
|
|
|
647f52 |
if (protocol == PROTO_SSH) {
|
|
|
647f52 |
const char *ssh = getenv("GIT_SSH");
|
|
|
647f52 |
int putty = ssh && strcasestr(ssh, "plink");
|
|
|
647f52 |
+ transport_check_allowed("ssh");
|
|
|
647f52 |
if (!ssh) ssh = "ssh";
|
|
|
647f52 |
|
|
|
647f52 |
*arg++ = ssh;
|
|
|
647f52 |
@@ -639,6 +642,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
|
|
|
647f52 |
/* remove repo-local variables from the environment */
|
|
|
647f52 |
conn->env = local_repo_env;
|
|
|
647f52 |
conn->use_shell = 1;
|
|
|
647f52 |
+ transport_check_allowed("file");
|
|
|
647f52 |
}
|
|
|
647f52 |
*arg++ = cmd.buf;
|
|
|
647f52 |
*arg = NULL;
|
|
|
647f52 |
diff --git a/transport-helper.c b/transport-helper.c
|
|
|
647f52 |
index 522d791..be8402a 100644
|
|
|
647f52 |
--- a/transport-helper.c
|
|
|
647f52 |
+++ b/transport-helper.c
|
|
|
647f52 |
@@ -932,6 +932,8 @@ int transport_helper_init(struct transport *transport, const char *name)
|
|
|
647f52 |
struct helper_data *data = xcalloc(sizeof(*data), 1);
|
|
|
647f52 |
data->name = name;
|
|
|
647f52 |
|
|
|
647f52 |
+ transport_check_allowed(name);
|
|
|
647f52 |
+
|
|
|
647f52 |
if (getenv("GIT_TRANSPORT_HELPER_DEBUG"))
|
|
|
647f52 |
debug = 1;
|
|
|
647f52 |
|
|
|
647f52 |
diff --git a/transport.c b/transport.c
|
|
|
647f52 |
index ba5d8af..733717d 100644
|
|
|
647f52 |
--- a/transport.c
|
|
|
647f52 |
+++ b/transport.c
|
|
|
647f52 |
@@ -894,6 +894,20 @@ static int external_specification_len(const char *url)
|
|
|
647f52 |
return strchr(url, ':') - url;
|
|
|
647f52 |
}
|
|
|
647f52 |
|
|
|
647f52 |
+void transport_check_allowed(const char *type)
|
|
|
647f52 |
+{
|
|
|
647f52 |
+ struct string_list allowed = STRING_LIST_INIT_DUP;
|
|
|
647f52 |
+ const char *v = getenv("GIT_ALLOW_PROTOCOL");
|
|
|
647f52 |
+
|
|
|
647f52 |
+ if (!v)
|
|
|
647f52 |
+ return;
|
|
|
647f52 |
+
|
|
|
647f52 |
+ string_list_split(&allowed, v, ':', -1);
|
|
|
647f52 |
+ if (!unsorted_string_list_has_string(&allowed, type))
|
|
|
647f52 |
+ die("transport '%s' not allowed", type);
|
|
|
647f52 |
+ string_list_clear(&allowed, 0);
|
|
|
647f52 |
+}
|
|
|
647f52 |
+
|
|
|
647f52 |
struct transport *transport_get(struct remote *remote, const char *url)
|
|
|
647f52 |
{
|
|
|
647f52 |
const char *helper;
|
|
|
647f52 |
@@ -925,12 +939,14 @@ struct transport *transport_get(struct remote *remote, const char *url)
|
|
|
647f52 |
if (helper) {
|
|
|
647f52 |
transport_helper_init(ret, helper);
|
|
|
647f52 |
} else if (!prefixcmp(url, "rsync:")) {
|
|
|
647f52 |
+ transport_check_allowed("rsync");
|
|
|
647f52 |
ret->get_refs_list = get_refs_via_rsync;
|
|
|
647f52 |
ret->fetch = fetch_objs_via_rsync;
|
|
|
647f52 |
ret->push = rsync_transport_push;
|
|
|
647f52 |
ret->smart_options = NULL;
|
|
|
647f52 |
} else if (is_local(url) && is_file(url) && is_bundle(url, 1)) {
|
|
|
647f52 |
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
|
|
|
647f52 |
+ transport_check_allowed("file");
|
|
|
647f52 |
ret->data = data;
|
|
|
647f52 |
ret->get_refs_list = get_refs_from_bundle;
|
|
|
647f52 |
ret->fetch = fetch_refs_from_bundle;
|
|
|
647f52 |
@@ -942,7 +958,10 @@ struct transport *transport_get(struct remote *remote, const char *url)
|
|
|
647f52 |
|| !prefixcmp(url, "ssh://")
|
|
|
647f52 |
|| !prefixcmp(url, "git+ssh://")
|
|
|
647f52 |
|| !prefixcmp(url, "ssh+git://")) {
|
|
|
647f52 |
- /* These are builtin smart transports. */
|
|
|
647f52 |
+ /*
|
|
|
647f52 |
+ * These are builtin smart transports; "allowed" transports
|
|
|
647f52 |
+ * will be checked individually in git_connect.
|
|
|
647f52 |
+ */
|
|
|
647f52 |
struct git_transport_data *data = xcalloc(1, sizeof(*data));
|
|
|
647f52 |
ret->data = data;
|
|
|
647f52 |
ret->set_option = NULL;
|
|
|
647f52 |
diff --git a/transport.h b/transport.h
|
|
|
647f52 |
index fcb1d25..2beda7d 100644
|
|
|
647f52 |
--- a/transport.h
|
|
|
647f52 |
+++ b/transport.h
|
|
|
647f52 |
@@ -113,6 +113,13 @@ struct transport {
|
|
|
647f52 |
/* Returns a transport suitable for the url */
|
|
|
647f52 |
struct transport *transport_get(struct remote *, const char *);
|
|
|
647f52 |
|
|
|
647f52 |
+/*
|
|
|
647f52 |
+ * Check whether a transport is allowed by the environment,
|
|
|
647f52 |
+ * and die otherwise. type should generally be the URL scheme,
|
|
|
647f52 |
+ * as described in Documentation/git.txt
|
|
|
647f52 |
+ */
|
|
|
647f52 |
+void transport_check_allowed(const char *type);
|
|
|
647f52 |
+
|
|
|
647f52 |
/* Transport options which apply to git:// and scp-style URLs */
|
|
|
647f52 |
|
|
|
647f52 |
/* The program to use on the remote side to send a pack */
|
|
|
647f52 |
--
|
|
|
647f52 |
2.1.0
|
|
|
647f52 |
|