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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
00ca4902
Commit
00ca4902
authored
Feb 20, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use controllers to serve uploads, with XSS prevention and access control.
parent
4310431e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
0 deletions
+48
-0
app/controllers/projects/uploads_controller.rb
app/controllers/projects/uploads_controller.rb
+19
-0
app/controllers/uploads_controller.rb
app/controllers/uploads_controller.rb
+17
-0
config/routes.rb
config/routes.rb
+12
-0
No files found.
app/controllers/projects/uploads_controller.rb
0 → 100644
View file @
00ca4902
class
Projects::UploadsController
<
Projects
::
ApplicationController
layout
"project"
before_filter
:project
def
show
path
=
File
.
join
(
project
.
path_with_namespace
,
params
[
:secret
])
uploader
=
FileUploader
.
new
(
'uploads'
,
path
)
uploader
.
retrieve_from_store!
(
params
[
:filename
])
if
uploader
.
file
.
exists?
# Right now, these are always images, so we can safely render them inline.
send_file
uploader
.
file
.
path
,
disposition:
'inline'
else
not_found!
end
end
end
\ No newline at end of file
app/controllers/uploads_controller.rb
0 → 100644
View file @
00ca4902
class
UploadsController
<
ApplicationController
def
show
model
=
params
[
:model
].
camelize
.
constantize
.
find
(
params
[
:id
])
uploader
=
model
.
send
(
params
[
:mounted_as
])
if
uploader
.
file_storage?
if
!
model
.
respond_to?
(
:project
)
||
can?
(
current_user
,
:read_project
,
model
.
project
)
disposition
=
uploader
.
image?
?
'inline'
:
'attachment'
send_file
uploader
.
file
.
path
,
disposition:
disposition
else
not_found!
end
else
redirect_to
uploader
.
url
end
end
end
config/routes.rb
View file @
00ca4902
...
...
@@ -69,7 +69,19 @@ Gitlab::Application.routes.draw do
end
end
#
# Uploads
#
scope
path: :uploads
do
# Note attachments and User/Group/Project avatars
get
":model/:mounted_as/:id/:filename"
,
to:
"uploads#show"
,
constraints:
{
model:
/note|user|group|project/
,
mounted_as:
/avatar|attachment/
,
filename:
/.+/
}
# Project markdown uploads
get
":id/:secret/:filename"
,
to:
"projects/uploads#show"
,
constraints:
{
id:
/[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/
,
filename:
/.+/
}
end
#
# Explore area
...
...
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