Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
d35a23da
Commit
d35a23da
authored
Jul 26, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check repository path before proceeding
The path must exist and not contain '/../' (traversal).
parent
643fe8c8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
main.go
main.go
+19
-1
No files found.
main.go
View file @
d35a23da
...
@@ -22,6 +22,7 @@ type gitHandler struct {
...
@@ -22,6 +22,7 @@ type gitHandler struct {
}
}
var
http_client
=
&
http
.
Client
{}
var
http_client
=
&
http
.
Client
{}
var
path_traversal
=
regexp
.
MustCompile
(
`/../`
)
// Command-line options
// Command-line options
var
repo_root
string
var
repo_root
string
...
@@ -52,6 +53,11 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
...
@@ -52,6 +53,11 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
for
_
,
g
:=
range
git_handlers
{
for
_
,
g
:=
range
git_handlers
{
path_match
:=
g
.
regexp
.
FindStringSubmatch
(
r
.
URL
.
Path
)
path_match
:=
g
.
regexp
.
FindStringSubmatch
(
r
.
URL
.
Path
)
if
r
.
Method
==
g
.
method
&&
path_match
!=
nil
{
if
r
.
Method
==
g
.
method
&&
path_match
!=
nil
{
found_path
:=
path_match
[
1
]
if
!
valid_path
(
found_path
)
{
http
.
Error
(
w
,
"Not found"
,
404
)
return
}
auth_response
,
err
:=
do_auth_request
(
r
)
auth_response
,
err
:=
do_auth_request
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
fail_500
(
w
,
err
)
fail_500
(
w
,
err
)
...
@@ -73,13 +79,25 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
...
@@ -73,13 +79,25 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
fail_500
(
w
,
err
)
fail_500
(
w
,
err
)
return
return
}
}
g
.
handle_func
(
user
,
g
.
rpc
,
path
.
Join
(
repo_root
,
path_match
[
1
]
),
w
,
r
)
g
.
handle_func
(
user
,
g
.
rpc
,
path
.
Join
(
repo_root
,
found_path
),
w
,
r
)
return
return
}
}
}
}
http
.
Error
(
w
,
"Not found"
,
404
)
http
.
Error
(
w
,
"Not found"
,
404
)
}
}
func
valid_path
(
p
string
)
bool
{
if
path_traversal
.
MatchString
(
p
)
{
log
.
Printf
(
"path traversal detected in %s"
,
p
)
return
false
}
if
_
,
err
:=
os
.
Stat
(
path
.
Join
(
repo_root
,
p
,
"objects"
));
err
!=
nil
{
log
.
Print
(
err
)
return
false
}
return
true
}
func
do_auth_request
(
r
*
http
.
Request
)
(
result
*
http
.
Response
,
err
error
)
{
func
do_auth_request
(
r
*
http
.
Request
)
(
result
*
http
.
Response
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s%s"
,
*
auth_backend
,
r
.
URL
.
RequestURI
())
url
:=
fmt
.
Sprintf
(
"%s%s"
,
*
auth_backend
,
r
.
URL
.
RequestURI
())
auth_req
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
auth_req
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment