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
2671a975
Commit
2671a975
authored
Jul 22, 2021
by
Chad Woolley
Committed by
Tetiana Chupryna
Jul 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent project snippets from being accessed from non-canonical URLs
parent
c83cf1f8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
app/controllers/concerns/find_snippet.rb
app/controllers/concerns/find_snippet.rb
+5
-1
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+6
-0
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+18
-0
No files found.
app/controllers/concerns/find_snippet.rb
View file @
2671a975
...
...
@@ -9,7 +9,7 @@ module FindSnippet
# rubocop:disable CodeReuse/ActiveRecord
def
snippet
strong_memoize
(
:snippet
)
do
snippet_klass
.
inc_relations_for_view
.
find_by
(
id:
snippet_id
)
snippet_klass
.
inc_relations_for_view
.
find_by
(
snippet_find_params
)
end
end
# rubocop:enable CodeReuse/ActiveRecord
...
...
@@ -21,4 +21,8 @@ module FindSnippet
def
snippet_id
params
[
:id
]
end
def
snippet_find_params
{
id:
snippet_id
}
end
end
app/controllers/projects/snippets_controller.rb
View file @
2671a975
# frozen_string_literal: true
class
Projects::SnippetsController
<
Projects
::
Snippets
::
ApplicationController
extend
::
Gitlab
::
Utils
::
Override
include
SnippetsActions
include
ToggleAwardEmoji
include
SpammableActions
...
...
@@ -45,4 +46,9 @@ class Projects::SnippetsController < Projects::Snippets::ApplicationController
def
spammable_path
project_snippet_path
(
@project
,
@snippet
)
end
override
:snippet_find_params
def
snippet_find_params
super
.
merge
(
project_id:
project
.
id
)
end
end
spec/controllers/projects/snippets_controller_spec.rb
View file @
2671a975
...
...
@@ -181,6 +181,24 @@ RSpec.describe Projects::SnippetsController do
end
end
end
context
'when the project snippet is public'
do
let_it_be
(
:project_snippet_public
)
{
create
(
:project_snippet
,
:public
,
:repository
,
project:
project
,
author:
user
)
}
context
'when attempting to access from a different project route'
do
subject
{
get
action
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
42
,
id:
project_snippet_public
.
to_param
}
}
before
do
sign_in
(
user
)
end
it
'responds with status 404'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
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