Skip to content

Commit d060507

Browse files
committed
Merge branch 'tc/smart-http-restrict'
* tc/smart-http-restrict: Test t5560: Fix test when run with dash Smart-http tests: Test http-backend without curl or a webserver Smart-http tests: Break test t5560-http-backend into pieces Smart-http tests: Improve coverage in test t5560 Smart-http: check if repository is OK to export before serving it
2 parents 4fa0882 + e8189ee commit d060507

File tree

7 files changed

+362
-260
lines changed

7 files changed

+362
-260
lines changed

Documentation/git-http-backend.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ The program supports clients fetching using both the smart HTTP protcol
1818
and the backwards-compatible dumb HTTP protocol, as well as clients
1919
pushing using the smart HTTP protocol.
2020

21+
It verifies that the directory has the magic file
22+
"git-daemon-export-ok", and it will refuse to export any git directory
23+
that hasn't explicitly been marked for export this way (unless the
24+
GIT_HTTP_EXPORT_ALL environmental variable is set).
25+
2126
By default, only the `upload-pack` service is enabled, which serves
2227
'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
2328
'git-fetch', 'git-pull', and 'git-clone'. If the client is authenticated,
@@ -70,6 +75,7 @@ Apache 2.x::
7075
+
7176
----------------------------------------------------------------
7277
SetEnv GIT_PROJECT_ROOT /var/www/git
78+
SetEnv GIT_HTTP_EXPORT_ALL
7379
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
7480
----------------------------------------------------------------
7581
+
@@ -157,6 +163,10 @@ by the invoking web server, including:
157163
* QUERY_STRING
158164
* REQUEST_METHOD
159165

166+
The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
167+
'git-http-backend' to bypass the check for the "git-daemon-export-ok"
168+
file in each repository before allowing export of that repository.
169+
160170
The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
161171
GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
162172
ensuring that any reflogs created by 'git-receive-pack' contain some

http-backend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ int main(int argc, char **argv)
648648
setup_path();
649649
if (!enter_repo(dir, 0))
650650
not_found("Not a git repository: '%s'", dir);
651+
if (!getenv("GIT_HTTP_EXPORT_ALL") &&
652+
access("git-daemon-export-ok", F_OK) )
653+
not_found("Repository not exported: '%s'", dir);
651654

652655
git_config(http_config, NULL);
653656
cmd->imp(cmd_arg);

t/lib-httpd/apache.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ Alias /dumb/ www/
2222

2323
<Location /smart/>
2424
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
25+
SetEnv GIT_HTTP_EXPORT_ALL
26+
</Location>
27+
<Location /smart_noexport/>
28+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
2529
</Location>
2630
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
31+
ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
2732
<Directory ${GIT_EXEC_PATH}>
2833
Options None
2934
</Directory>

t/t5560-http-backend-noserver.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
test_description='test git-http-backend-noserver'
4+
. ./test-lib.sh
5+
6+
HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
7+
8+
run_backend() {
9+
echo "$2" |
10+
QUERY_STRING="${1#*\?}" \
11+
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
12+
PATH_INFO="${1%%\?*}" \
13+
git http-backend >act.out 2>act.err
14+
}
15+
16+
GET() {
17+
export REQUEST_METHOD="GET" &&
18+
run_backend "/repo.git/$1" &&
19+
unset REQUEST_METHOD &&
20+
if ! grep "Status" act.out >act
21+
then
22+
printf "Status: 200 OK\r\n" >act
23+
fi
24+
printf "Status: $2\r\n" >exp &&
25+
test_cmp exp act
26+
}
27+
28+
POST() {
29+
export REQUEST_METHOD="POST" &&
30+
export CONTENT_TYPE="application/x-$1-request" &&
31+
run_backend "/repo.git/$1" "$2" &&
32+
unset REQUEST_METHOD &&
33+
unset CONTENT_TYPE &&
34+
if ! grep "Status" act.out >act
35+
then
36+
printf "Status: 200 OK\r\n" >act
37+
fi
38+
printf "Status: $3\r\n" >exp &&
39+
test_cmp exp act
40+
}
41+
42+
log_div() {
43+
return 0
44+
}
45+
46+
. "$TEST_DIRECTORY"/t556x_common
47+
48+
expect_aliased() {
49+
export REQUEST_METHOD="GET" &&
50+
if test $1 = 0; then
51+
run_backend "$2"
52+
else
53+
run_backend "$2" &&
54+
echo "fatal: '$2': aliased" >exp.err &&
55+
test_cmp exp.err act.err
56+
fi
57+
unset REQUEST_METHOD
58+
}
59+
60+
test_expect_success 'http-backend blocks bad PATH_INFO' '
61+
config http.getanyfile true &&
62+
63+
expect_aliased 0 /repo.git/HEAD &&
64+
65+
expect_aliased 1 /repo.git/../HEAD &&
66+
expect_aliased 1 /../etc/passwd &&
67+
expect_aliased 1 ../etc/passwd &&
68+
expect_aliased 1 /etc//passwd &&
69+
expect_aliased 1 /etc/./passwd &&
70+
expect_aliased 1 //domain/data.txt
71+
'
72+
73+
test_done

t/t5560-http-backend.sh

Lines changed: 0 additions & 260 deletions
This file was deleted.

0 commit comments

Comments
 (0)