fredit 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ class FreditController < ::ApplicationController
6
6
  JS_DIR = Rails.root + 'public/javascripts/**/*.js'
7
7
 
8
8
  def index
9
- @path ||= params[:file] || params[:new_path] || Fredit.editables[:views].first
9
+ @path ||= secure_path(params[:file] || params[:new_path] || Fredit.editables[:views].first)
10
10
  if !File.size?(@path)
11
11
  File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")}
12
12
  end
@@ -14,7 +14,7 @@ class FreditController < ::ApplicationController
14
14
  end
15
15
 
16
16
  def update
17
- @path = params[:file_path]
17
+ @path = secure_path params[:file_path]
18
18
 
19
19
  edit_msg = !params[:edit_message].blank? ? params[:edit_message] : "unspecified edit"
20
20
 
@@ -44,9 +44,19 @@ class FreditController < ::ApplicationController
44
44
  end
45
45
 
46
46
  def create
47
- @path = params[:file]
47
+ @path = secure_path params[:file]
48
48
  FileUtils::mkdir_p File.dirname(@path)
49
49
  File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")}
50
50
  end
51
51
 
52
+ private
53
+
54
+ def secure_path(path)
55
+ path2 = File.expand_path(path.to_s)
56
+ if path2.index(Rails.root.to_s) != 0
57
+ raise "Unauthorized path: #{path2} (Raw: #{path})"
58
+ end
59
+ path
60
+ end
61
+
52
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  segments:
45
45
  - 0
46
- hash: -143000303
46
+ hash: -722474993
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  none: false
49
49
  requirements:
@@ -52,11 +52,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  segments:
54
54
  - 0
55
- hash: -143000303
55
+ hash: -722474993
56
56
  requirements: []
57
57
  rubyforge_project:
58
58
  rubygems_version: 1.8.11
59
59
  signing_key:
60
60
  specification_version: 3
61
- summary: fredit 0.0.3
61
+ summary: fredit 0.0.4
62
62
  test_files: []