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
ca049d86
Commit
ca049d86
authored
Mar 30, 2020
by
Michelle Gill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check user permissions before find_file_path
parent
7ccd1d1b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+1
-0
changelogs/unreleased/security-branch-permissions.yml
changelogs/unreleased/security-branch-permissions.yml
+5
-0
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+18
-5
No files found.
app/helpers/projects_helper.rb
View file @
ca049d86
...
@@ -625,6 +625,7 @@ module ProjectsHelper
...
@@ -625,6 +625,7 @@ module ProjectsHelper
def
find_file_path
def
find_file_path
return
unless
@project
&&
!
@project
.
empty_repo?
return
unless
@project
&&
!
@project
.
empty_repo?
return
unless
can?
(
current_user
,
:download_code
,
@project
)
ref
=
@ref
||
@project
.
repository
.
root_ref
ref
=
@ref
||
@project
.
repository
.
root_ref
...
...
changelogs/unreleased/security-branch-permissions.yml
0 → 100644
View file @
ca049d86
---
title
:
Prevent unauthorized access to default branch
merge_request
:
author
:
type
:
security
spec/helpers/application_helper_spec.rb
View file @
ca049d86
...
@@ -277,11 +277,16 @@ describe ApplicationHelper do
...
@@ -277,11 +277,16 @@ describe ApplicationHelper do
end
end
context
'when @project is set'
do
context
'when @project is set'
do
it
'includes all possible body data elements and associates the project elements with project'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
project
=
create
(
:project
)
let_it_be
(
:user
)
{
create
(
:user
)
}
before
do
assign
(
:project
,
project
)
assign
(
:project
,
project
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
nil
)
end
it
'includes all possible body data elements and associates the project elements with project'
do
expect
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
)
expect
(
helper
.
body_data
).
to
eq
(
expect
(
helper
.
body_data
).
to
eq
(
{
{
page:
'application'
,
page:
'application'
,
...
@@ -302,12 +307,11 @@ describe ApplicationHelper do
...
@@ -302,12 +307,11 @@ describe ApplicationHelper do
context
'when params[:id] is present and the issue exsits and action_name is show'
do
context
'when params[:id] is present and the issue exsits and action_name is show'
do
it
'sets all project and id elements correctly related to the issue'
do
it
'sets all project and id elements correctly related to the issue'
do
issue
=
create
(
:issue
)
issue
=
create
(
:issue
,
project:
project
)
stub_controller_method
(
:action_name
,
'show'
)
stub_controller_method
(
:action_name
,
'show'
)
stub_controller_method
(
:params
,
{
id:
issue
.
id
})
stub_controller_method
(
:params
,
{
id:
issue
.
id
})
assign
(
:project
,
issue
.
project
)
expect
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
false
)
expect
(
helper
.
body_data
).
to
eq
(
expect
(
helper
.
body_data
).
to
eq
(
{
{
page:
'projects:issues:show'
,
page:
'projects:issues:show'
,
...
@@ -322,6 +326,15 @@ describe ApplicationHelper do
...
@@ -322,6 +326,15 @@ describe ApplicationHelper do
end
end
end
end
end
end
context
'when current_user has download_code permission'
do
it
'returns find_file with the default branch'
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
expect
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
true
)
expect
(
helper
.
body_data
[
:find_file
]).
to
end_with
(
project
.
default_branch
)
end
end
end
end
def
stub_controller_method
(
method_name
,
value
)
def
stub_controller_method
(
method_name
,
value
)
...
...
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