geminabox 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cfce489e43841df96a314d9a85776328e77a48c3093fabbd9333f5ac0a83079
4
- data.tar.gz: d3b23957c2ac25f41aab48528e49f85d24fb6701aabec0ae5d8ef622ea189521
3
+ metadata.gz: 4da5997cf6f07bf5f5c18308b50ddabae4e3acad3c59b5e725555632c94338ec
4
+ data.tar.gz: 27a3b1392251204e9f210b9efd1b2dbb0e081e851381fce830385f1eb9db4c28
5
5
  SHA512:
6
- metadata.gz: '0985c4ba1960c2ef314f18a9a3a6209e76401ffd00ffed6ad79b5e75a3de169f47c315c87e25e930d8d72ecf3f41b94f2cd1d1d41f027ae0aa4c83796cd71cb8'
7
- data.tar.gz: 9a28c37de926675893b4d620c037531e44894d084025ffbd6deb77d2f55be4e76fbc0f866e8547d29e6454f996dd9b1f5aea43c21ed44f9fd463c011d5e92c5b
6
+ metadata.gz: 74b98e66ccc6112d37fb694189c216297cbdfedaeaf1570ce2c0682db24722cb59c1ea5f513f7068743beb7b607969c6eca404f47d72aac822d99a066e9c07be
7
+ data.tar.gz: 4c818745e2edf7e128e4c6849d07a01f54b29cc851eaa57d5ffb9f101076b28db02f2c45ec49cc8c2bb25500f8e0ad1c67930b54b851122b4041e0f42fac8591
@@ -9,7 +9,10 @@ module Geminabox
9
9
 
10
10
  def serve
11
11
  headers["Cache-Control"] = 'no-transform'
12
- send_file(File.expand_path(File.join(Geminabox.data, *request.path_info)), :type => response['Content-Type'])
12
+ path = File.expand_path(File.join(Geminabox.data, *request.path_info))
13
+ # Rack::Protection normally strips ".." first; this holds without it.
14
+ halt 404 unless path.start_with?(File.expand_path(Geminabox.data) + File::SEPARATOR)
15
+ send_file(path, :type => response['Content-Type'])
13
16
  end
14
17
 
15
18
  %w[/specs.4.8.gz
@@ -26,8 +26,12 @@ module Geminabox
26
26
  File.open(@tempfile.path, "rb")
27
27
  end
28
28
 
29
+ # spec comes from the uploaded archive and RubyGems does not validate it on
30
+ # read, so the name must be checked before it becomes part of a path.
29
31
  def valid?
30
- spec && spec.name && spec.version
32
+ spec && spec.name && spec.version &&
33
+ spec.name.match?(Gem::Specification::VALID_NAME_PATTERN) &&
34
+ File.basename(name) == name
31
35
  rescue Gem::Package::Error
32
36
  false
33
37
  end
@@ -8,6 +8,11 @@ module Geminabox
8
8
 
9
9
  def initialize(file_name)
10
10
  @file_name = file_name
11
+ # file_name comes from the request path; both paths get mkdir_p and writes.
12
+ root = File.expand_path(root_path) + File::SEPARATOR
13
+ unless local_path.start_with?(root) && proxy_path.start_with?(root)
14
+ raise ArgumentError, "#{file_name} resolves outside #{root_path}"
15
+ end
11
16
  ensure_destination_exists
12
17
  end
13
18
 
@@ -14,7 +14,7 @@ module Geminabox
14
14
  if file_handler
15
15
  send_file file_handler.proxy_path
16
16
  else
17
- send_file(File.expand_path(File.join(Geminabox.data, *request.path_info)), :type => response['Content-Type'])
17
+ send_file(data_path, :type => response['Content-Type'])
18
18
  end
19
19
  end
20
20
 
@@ -53,9 +53,7 @@ module Geminabox
53
53
  private
54
54
  def get_from_rubygems_if_not_local
55
55
 
56
- file = File.expand_path(File.join(Geminabox.data, *request.path_info))
57
-
58
- unless File.exist?(file)
56
+ unless File.exist?(data_path)
59
57
  ruby_gems_url = Geminabox.ruby_gems_url
60
58
  path = File.join(ruby_gems_url, *request.path_info)
61
59
  content = Geminabox.http_adapter.get_content(path)
@@ -70,6 +68,15 @@ module Geminabox
70
68
 
71
69
  def copy_file(file_name)
72
70
  self.file_handler = Copier.copy(file_name)
71
+ rescue ArgumentError
72
+ halt 404
73
+ end
74
+
75
+ # Rack::Protection normally strips ".." first; this holds without it.
76
+ def data_path
77
+ path = File.expand_path(File.join(Geminabox.data, *request.path_info))
78
+ halt 404 unless path.start_with?(File.expand_path(Geminabox.data) + File::SEPARATOR)
79
+ path
73
80
  end
74
81
 
75
82
 
@@ -144,8 +144,9 @@ module Geminabox
144
144
  error_response(403, 'Gem deletion is disabled - see https://github.com/geminabox/geminabox/issues/115')
145
145
  end
146
146
 
147
+ path = file_path
147
148
  serialize_update do
148
- File.delete file_path if File.exist? file_path
149
+ File.delete path if File.exist? path
149
150
  self.class.reindex(:force_rebuild)
150
151
  redirect url("/")
151
152
  end
@@ -255,7 +256,10 @@ HTML
255
256
  end
256
257
 
257
258
  def file_path
258
- File.expand_path(File.join(Geminabox.data, *request.path_info))
259
+ path = File.expand_path(File.join(Geminabox.data, *request.path_info))
260
+ # Rack::Protection normally strips ".." first; this holds without it.
261
+ halt 404 unless path.start_with?(File.expand_path(Geminabox.data) + File::SEPARATOR)
262
+ path
259
263
  end
260
264
 
261
265
  def dependency_cache
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Geminabox
4
- VERSION = '3.1.0' unless defined? VERSION
4
+ VERSION = '3.1.1' unless defined? VERSION
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geminabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lea