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
93399075
Commit
93399075
authored
May 12, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix templates API endpoint when project name has dots
parent
13ee246a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
changelogs/unreleased/fj-fix-templates-endpoint-when-project-has-dots.yml
...eased/fj-fix-templates-endpoint-when-project-has-dots.yml
+5
-0
lib/api/project_templates.rb
lib/api/project_templates.rb
+6
-4
spec/requests/api/project_templates_spec.rb
spec/requests/api/project_templates_spec.rb
+23
-3
No files found.
changelogs/unreleased/fj-fix-templates-endpoint-when-project-has-dots.yml
0 → 100644
View file @
93399075
---
title
:
Fix templates API endpoint when project name has dots
merge_request
:
31758
author
:
type
:
fixed
lib/api/project_templates.rb
View file @
93399075
...
...
@@ -5,6 +5,10 @@ module API
include
PaginationParams
TEMPLATE_TYPES
=
%w[dockerfiles gitignores gitlab_ci_ymls licenses]
.
freeze
# The regex is needed to ensure a period (e.g. agpl-3.0)
# isn't confused with a format type. We also need to allow encoded
# values (e.g. C%2B%2B for C++), so allow % and + as well.
TEMPLATE_NAMES_ENDPOINT_REQUIREMENTS
=
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
.
merge
(
name:
/[\w%.+-]+/
)
before
{
authenticate_non_get!
}
...
...
@@ -36,10 +40,8 @@ module API
optional
:project
,
type:
String
,
desc:
'The project name to use when expanding placeholders in the template. Only affects licenses'
optional
:fullname
,
type:
String
,
desc:
'The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses'
end
# The regex is needed to ensure a period (e.g. agpl-3.0)
# isn't confused with a format type. We also need to allow encoded
# values (e.g. C%2B%2B for C++), so allow % and + as well.
get
':id/templates/:type/:name'
,
requirements:
{
name:
/[\w%.+-]+/
}
do
get
':id/templates/:type/:name'
,
requirements:
TEMPLATE_NAMES_ENDPOINT_REQUIREMENTS
do
template
=
TemplateFinder
.
build
(
params
[
:type
],
user_project
,
name:
params
[
:name
])
.
execute
...
...
spec/requests/api/project_templates_spec.rb
View file @
93399075
...
...
@@ -7,16 +7,24 @@ describe API::ProjectTemplates do
let_it_be
(
:private_project
)
{
create
(
:project
,
:private
)
}
let_it_be
(
:developer
)
{
create
(
:user
)
}
let
(
:url_encoded_path
)
{
"
#{
public_project
.
namespace
.
path
}
%2F
#{
public_project
.
path
}
"
}
before
do
private_project
.
add_developer
(
developer
)
end
describe
'GET /projects/:id/templates/:type
'
do
it
'accepts project paths with dots'
do
get
api
(
"/projects/
#{
public_project
.
namespace
.
path
}
%2F
#{
public_project
.
path
}
/templates/dockerfiles"
)
shared_examples
'accepts project paths with dots
'
do
it
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
describe
'GET /projects/:id/templates/:type'
do
it_behaves_like
'accepts project paths with dots'
do
subject
{
get
api
(
"/projects/
#{
url_encoded_path
}
/templates/dockerfiles"
)
}
end
it
'returns dockerfiles'
do
get
api
(
"/projects/
#{
public_project
.
id
}
/templates/dockerfiles"
)
...
...
@@ -81,6 +89,10 @@ describe API::ProjectTemplates do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/template_list'
)
end
it_behaves_like
'accepts project paths with dots'
do
subject
{
get
api
(
"/projects/
#{
url_encoded_path
}
/templates/licenses"
)
}
end
end
describe
'GET /projects/:id/templates/:type/:key'
do
...
...
@@ -150,6 +162,10 @@ describe API::ProjectTemplates do
expect
(
response
).
to
match_response_schema
(
'public_api/v4/license'
)
end
it_behaves_like
'accepts project paths with dots'
do
subject
{
get
api
(
"/projects/
#{
url_encoded_path
}
/templates/gitlab_ci_ymls/Android"
)
}
end
shared_examples
'path traversal attempt'
do
|
template_type
|
it
'rejects invalid filenames'
do
get
api
(
"/projects/
#{
public_project
.
id
}
/templates/
#{
template_type
}
/%2e%2e%2fPython%2ea"
)
...
...
@@ -179,5 +195,9 @@ describe API::ProjectTemplates do
expect
(
content
).
to
include
(
'Project Placeholder'
)
expect
(
content
).
to
include
(
"Copyright (C)
#{
Time
.
now
.
year
}
Fullname Placeholder"
)
end
it_behaves_like
'accepts project paths with dots'
do
subject
{
get
api
(
"/projects/
#{
url_encoded_path
}
/templates/licenses/mit"
)
}
end
end
end
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