Skip to content

Commit 8b2bd7c

Browse files
Tarmigan Caseboltgitster
authored andcommitted
Smart-http: check if repository is OK to export before serving it
Similar to how git-daemon checks whether a repository is OK to be exported, smart-http should also check. This check can be satisfied in two different ways: the environmental variable GIT_HTTP_EXPORT_ALL may be set to export all repositories, or the individual repository may have the file git-daemon-export-ok. Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 902f235 commit 8b2bd7c

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
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.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ config() {
2323
}
2424

2525
GET() {
26-
curl --include "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
26+
curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out 2>/dev/null &&
2727
tr '\015' Q <out |
2828
sed '
2929
s/Q$//
@@ -91,6 +91,7 @@ get_static_files() {
9191
GET $IDX_URL "$1"
9292
}
9393

94+
SMART=smart
9495
test_expect_success 'direct refs/heads/master not found' '
9596
log_div "refs/heads/master"
9697
GET refs/heads/master "404 Not Found"
@@ -99,6 +100,19 @@ test_expect_success 'static file is ok' '
99100
log_div "getanyfile default"
100101
get_static_files "200 OK"
101102
'
103+
SMART=smart_noexport
104+
test_expect_success 'no export by default' '
105+
log_div "no git-daemon-export-ok"
106+
get_static_files "404 Not Found"
107+
'
108+
test_expect_success 'export if git-daemon-export-ok' '
109+
log_div "git-daemon-export-ok"
110+
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
111+
touch git-daemon-export-ok
112+
) &&
113+
get_static_files "200 OK"
114+
'
115+
SMART=smart
102116
test_expect_success 'static file if http.getanyfile true is ok' '
103117
log_div "getanyfile true"
104118
config http.getanyfile true &&
@@ -145,7 +159,6 @@ test_expect_success 'http.receivepack false' '
145159
GET info/refs?service=git-receive-pack "403 Forbidden" &&
146160
POST git-receive-pack 0000 "403 Forbidden"
147161
'
148-
149162
run_backend() {
150163
REQUEST_METHOD=GET \
151164
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
@@ -194,6 +207,28 @@ GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
194207
GET /smart/repo.git/$PACK_URL HTTP/1.1 200
195208
GET /smart/repo.git/$IDX_URL HTTP/1.1 200
196209
210+
### no git-daemon-export-ok
211+
###
212+
GET /smart_noexport/repo.git/HEAD HTTP/1.1 404 -
213+
GET /smart_noexport/repo.git/info/refs HTTP/1.1 404 -
214+
GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 404 -
215+
GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 404 -
216+
GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 404 -
217+
GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 404 -
218+
GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 404 -
219+
GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 404 -
220+
221+
### git-daemon-export-ok
222+
###
223+
GET /smart_noexport/repo.git/HEAD HTTP/1.1 200
224+
GET /smart_noexport/repo.git/info/refs HTTP/1.1 200
225+
GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 200
226+
GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 200 -
227+
GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 200 -
228+
GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 200
229+
GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 200
230+
GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 200
231+
197232
### getanyfile true
198233
###
199234
GET /smart/repo.git/HEAD HTTP/1.1 200

0 commit comments

Comments
 (0)