Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9c08f8f9
Commit
9c08f8f9
authored
Feb 07, 2022
by
dcouture
Committed by
Dominic Couture
Feb 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a check for path traversal in manifest_file_name
parent
a63cb9b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
app/controllers/groups/dependency_proxy_for_containers_controller.rb
...lers/groups/dependency_proxy_for_containers_controller.rb
+1
-1
spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb
...groups/dependency_proxy_for_containers_controller_spec.rb
+26
-3
No files found.
app/controllers/groups/dependency_proxy_for_containers_controller.rb
View file @
9c08f8f9
...
...
@@ -120,7 +120,7 @@ class Groups::DependencyProxyForContainersController < ::Groups::DependencyProxy
end
def
manifest_file_name
@manifest_file_name
||=
"
#{
image
}
:
#{
tag
}
.json"
@manifest_file_name
||=
Gitlab
::
Utils
.
check_path_traversal!
(
"
#{
image
}
:
#{
tag
}
.json"
)
end
def
group
...
...
spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb
View file @
9c08f8f9
...
...
@@ -47,6 +47,24 @@ RSpec.describe Groups::DependencyProxyForContainersController do
end
end
shared_examples
'with invalid path'
do
context
'with invalid image'
do
let
(
:image
)
{
'../path_traversal'
}
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Utils
::
PathTraversalAttackError
,
'Invalid path'
)
end
end
context
'with invalid tag'
do
let
(
:tag
)
{
'latest%2f..%2f..%2fpath_traversal'
}
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Utils
::
PathTraversalAttackError
,
'Invalid path'
)
end
end
end
shared_examples
'without permission'
do
context
'with invalid user'
do
before
do
...
...
@@ -164,8 +182,10 @@ RSpec.describe Groups::DependencyProxyForContainersController do
end
describe
'GET #manifest'
do
let_it_be
(
:image
)
{
'alpine'
}
let_it_be
(
:tag
)
{
'latest'
}
let_it_be
(
:manifest
)
{
create
(
:dependency_proxy_manifest
,
file_name:
"alpine:
#{
tag
}
.json"
,
group:
group
)
}
let_it_be
(
:file_name
)
{
"
#{
image
}
:
#{
tag
}
.json"
}
let_it_be
(
:manifest
)
{
create
(
:dependency_proxy_manifest
,
file_name:
file_name
,
group:
group
)
}
let
(
:pull_response
)
{
{
status: :success
,
manifest:
manifest
,
from_cache:
false
}
}
...
...
@@ -235,6 +255,8 @@ RSpec.describe Groups::DependencyProxyForContainersController do
context
'with workhorse response'
do
let
(
:pull_response
)
{
{
status: :success
,
manifest:
nil
,
from_cache:
false
}
}
it_behaves_like
'with invalid path'
it
'returns Workhorse send-dependency instructions'
,
:aggregate_failures
do
subject
...
...
@@ -246,7 +268,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do
"Authorization"
=>
[
"Bearer abcd1234"
],
"Accept"
=>
::
ContainerRegistry
::
Client
::
ACCEPTED_TYPES
)
expect
(
url
).
to
eq
(
DependencyProxy
::
Registry
.
manifest_url
(
'alpine'
,
tag
))
expect
(
url
).
to
eq
(
DependencyProxy
::
Registry
.
manifest_url
(
image
,
tag
))
expect
(
response
.
headers
[
'Content-Type'
]).
to
eq
(
'application/gzip'
)
expect
(
response
.
headers
[
'Content-Disposition'
]).
to
eq
(
ActionDispatch
::
Http
::
ContentDisposition
.
format
(
disposition:
'attachment'
,
filename:
manifest
.
file_name
)
...
...
@@ -277,7 +299,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do
it_behaves_like
'not found when disabled'
def
get_manifest
(
tag
)
get
:manifest
,
params:
{
group_id:
group
.
to_param
,
image:
'alpine'
,
tag:
tag
}
get
:manifest
,
params:
{
group_id:
group
.
to_param
,
image:
image
,
tag:
tag
}
end
end
...
...
@@ -440,6 +462,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do
end
it_behaves_like
'a package tracking event'
,
described_class
.
name
,
'pull_manifest'
it_behaves_like
'with invalid path'
context
'with no existing manifest'
do
it
'creates a manifest'
do
...
...
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