BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3f3b202c
Unverified
Commit
3f3b202c
authored
Nov 20, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve files API. Relative path check added. Create dir for new file if missing
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
a1d88f0f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
3 deletions
+25
-3
delete_file_action.rb
lib/gitlab/satellite/files/delete_file_action.rb
+7
-0
edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+7
-0
file_action.rb
lib/gitlab/satellite/files/file_action.rb
+4
-0
new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+7
-3
No files found.
lib/gitlab/satellite/files/delete_file_action.rb
View file @
3f3b202c
...
...
@@ -17,6 +17,13 @@ module Gitlab
# update the file in the satellite's working dir
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
# Prevent relative links
unless
safe_path?
(
file_path_in_satellite
)
Gitlab
::
GitLogger
.
error
(
"FileAction: Relative path not allowed"
)
return
false
end
File
.
delete
(
file_path_in_satellite
)
# add removed file
...
...
lib/gitlab/satellite/files/edit_file_action.rb
View file @
3f3b202c
...
...
@@ -19,6 +19,13 @@ module Gitlab
# update the file in the satellite's working dir
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
# Prevent relative links
unless
safe_path?
(
file_path_in_satellite
)
Gitlab
::
GitLogger
.
error
(
"FileAction: Relative path not allowed"
)
return
false
end
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
# commit the changes
...
...
lib/gitlab/satellite/files/file_action.rb
View file @
3f3b202c
...
...
@@ -8,6 +8,10 @@ module Gitlab
@file_path
=
file_path
@ref
=
ref
end
def
safe_path?
(
path
)
File
.
absolute_path
(
path
)
==
path
end
end
end
end
lib/gitlab/satellite/files/new_file_action.rb
View file @
3f3b202c
...
...
@@ -16,15 +16,19 @@ module Gitlab
# create target branch in satellite at the corresponding commit from bare repo
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
# update the file in the satellite's working dir
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
dir_name_in_satellite
=
File
.
dirname
(
file_path_in_satellite
)
# Prevent relative links
unless
File
.
absolute_path
(
file_path_in_satellite
)
==
file_path_in_satellite
Gitlab
::
GitLogger
.
error
(
"
New
FileAction: Relative path not allowed"
)
unless
safe_path?
(
file_path_in_satellite
)
Gitlab
::
GitLogger
.
error
(
"FileAction: Relative path not allowed"
)
return
false
end
# Create dir if not exists
FileUtils
.
mkdir_p
(
dir_name_in_satellite
)
# Write file
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
# add new file
...
...
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