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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
ed0d691e
Commit
ed0d691e
authored
Dec 11, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block private snippets from being embeddable
parent
30c6db8f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
7 deletions
+82
-7
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+8
-1
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+7
-1
app/models/snippet.rb
app/models/snippet.rb
+3
-5
changelogs/unreleased/security-48259-private-snippet.yml
changelogs/unreleased/security-48259-private-snippet.yml
+5
-0
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+40
-0
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+19
-0
No files found.
app/controllers/projects/snippets_controller.rb
View file @
ed0d691e
...
@@ -75,7 +75,14 @@ class Projects::SnippetsController < Projects::ApplicationController
...
@@ -75,7 +75,14 @@ class Projects::SnippetsController < Projects::ApplicationController
format
.
json
do
format
.
json
do
render_blob_json
(
blob
)
render_blob_json
(
blob
)
end
end
format
.
js
{
render
'shared/snippets/show'
}
format
.
js
do
if
@snippet
.
embeddable?
render
'shared/snippets/show'
else
head
:not_found
end
end
end
end
end
end
...
...
app/controllers/snippets_controller.rb
View file @
ed0d691e
...
@@ -80,7 +80,13 @@ class SnippetsController < ApplicationController
...
@@ -80,7 +80,13 @@ class SnippetsController < ApplicationController
render_blob_json
(
blob
)
render_blob_json
(
blob
)
end
end
format
.
js
{
render
'shared/snippets/show'
}
format
.
js
do
if
@snippet
.
embeddable?
render
'shared/snippets/show'
else
head
:not_found
end
end
end
end
end
end
...
...
app/models/snippet.rb
View file @
ed0d691e
...
@@ -176,11 +176,9 @@ class Snippet < ActiveRecord::Base
...
@@ -176,11 +176,9 @@ class Snippet < ActiveRecord::Base
end
end
def
embeddable?
def
embeddable?
if
project_id?
ability
=
project_id?
?
:read_project_snippet
:
:read_personal_snippet
Ability
.
allowed?
(
nil
,
:read_project_snippet
,
self
)
else
Ability
.
allowed?
(
nil
,
ability
,
self
)
Ability
.
allowed?
(
nil
,
:read_personal_snippet
,
self
)
end
end
end
def
notes_with_associations
def
notes_with_associations
...
...
changelogs/unreleased/security-48259-private-snippet.yml
0 → 100644
View file @
ed0d691e
---
title
:
Prevent private snippets from being embeddable
merge_request
:
author
:
type
:
security
spec/controllers/projects/snippets_controller_spec.rb
View file @
ed0d691e
...
@@ -379,6 +379,46 @@ describe Projects::SnippetsController do
...
@@ -379,6 +379,46 @@ describe Projects::SnippetsController do
end
end
end
end
describe
"GET #show for embeddable content"
do
let
(
:project_snippet
)
{
create
(
:project_snippet
,
snippet_permission
,
project:
project
,
author:
user
)
}
before
do
sign_in
(
user
)
get
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
project_snippet
.
to_param
,
format: :js
end
context
'when snippet is private'
do
let
(
:snippet_permission
)
{
:private
}
it
'responds with status 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'when snippet is public'
do
let
(
:snippet_permission
)
{
:public
}
it
'responds with status 200'
do
expect
(
assigns
(
:snippet
)).
to
eq
(
project_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'when the project is private'
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:private
)
}
context
'when snippet is public'
do
let
(
:project_snippet
)
{
create
(
:project_snippet
,
:public
,
project:
project
,
author:
user
)
}
it
'responds with status 404'
do
expect
(
assigns
(
:snippet
)).
to
eq
(
project_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
end
describe
'GET #raw'
do
describe
'GET #raw'
do
let
(
:project_snippet
)
do
let
(
:project_snippet
)
do
create
(
create
(
...
...
spec/controllers/snippets_controller_spec.rb
View file @
ed0d691e
...
@@ -80,6 +80,12 @@ describe SnippetsController do
...
@@ -80,6 +80,12 @@ describe SnippetsController do
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'responds with status 404 when embeddable content is requested'
do
get
:show
,
id:
personal_snippet
.
to_param
,
format: :js
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
end
end
...
@@ -106,6 +112,12 @@ describe SnippetsController do
...
@@ -106,6 +112,12 @@ describe SnippetsController do
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'responds with status 404 when embeddable content is requested'
do
get
:show
,
id:
personal_snippet
.
to_param
,
format: :js
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'when not signed in'
do
context
'when not signed in'
do
...
@@ -131,6 +143,13 @@ describe SnippetsController do
...
@@ -131,6 +143,13 @@ describe SnippetsController do
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'responds with status 200 when embeddable content is requested'
do
get
:show
,
id:
personal_snippet
.
to_param
,
format: :js
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
end
context
'when not signed in'
do
context
'when not signed in'
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