actionpack-page_caching 1.2.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92965e865a7dfa9dcb0c95f6ccbe2e6a67368eab493c5d6187ecf433cdade0d4
4
- data.tar.gz: 5ac29afdd687929ae4a4d1d22b7f58f60663e71c9a07df415ca16fc863c38a2d
3
+ metadata.gz: b3c84b38d08e6b8ec36bf104688be7f8a9a1de1c05bdf10796289cb27a8e9883
4
+ data.tar.gz: 9b05d100d1820f6a0b480b015d8123ce4d0bae52229ac16d6d5833d787e265c7
5
5
  SHA512:
6
- metadata.gz: 8d854ecd63f9ac358593acc46915e2615e8681408dee8c04ee97b34f21d692c9200a6b249cb02f2d4e59a1258c7f030ca73ee700ca7d5c5f6d9156749fe08d79
7
- data.tar.gz: b5c41eb6c92adb0ea3db3f1ac8b250b739e5119aa006a74dce7ab54ac9921be6d9437ed49ffec702c5fce8e78edb056f23f81b190b7d1bf36522549f1fbdc93b
6
+ metadata.gz: 9583f9359843f6fa8b86cf3db2d46a5597cc7bc9c96fef71d741e30c01d04efda3b7f78642bf7d4a67f7421b3c1630c17099897381139573bb0500c41a824fb5
7
+ data.tar.gz: cb7f51ee9ce237b63ea2a5e8ecd88b1d33cc83483660939608c62b8ea8d1804fdd854cbd11c914010963b0fa7f8b5f25d06926444ba10164819b8b3fe6f0ed14
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "actionpack-page_caching"
3
- gem.version = "1.2.0"
3
+ gem.version = "1.2.3"
4
4
  gem.author = "David Heinemeier Hansson"
5
5
  gem.email = "david@loudthinking.com"
6
6
  gem.description = "Static page caching for Action Pack (removed from core in Rails 4.0)"
@@ -93,6 +93,10 @@ module ActionController
93
93
  end
94
94
  end
95
95
 
96
+ def normalized_cache_directory
97
+ File.expand_path(cache_directory)
98
+ end
99
+
96
100
  def handle_proc_cache_directory
97
101
  if @controller
98
102
  @controller.instance_exec(&@cache_directory)
@@ -153,15 +157,22 @@ module ActionController
153
157
  end
154
158
 
155
159
  def cache_path(path, extension = nil)
156
- File.join(cache_directory, cache_file(path, extension))
160
+ unnormalized_path = File.join(normalized_cache_directory, cache_file(path, extension))
161
+ normalized_path = File.expand_path(unnormalized_path)
162
+
163
+ normalized_path if normalized_path.start_with?(normalized_cache_directory)
157
164
  end
158
165
 
159
166
  def delete(path)
167
+ return unless path
168
+
160
169
  File.delete(path) if File.exist?(path)
161
170
  File.delete(path + ".gz") if File.exist?(path + ".gz")
162
171
  end
163
172
 
164
173
  def write(content, path, gzip)
174
+ return unless path
175
+
165
176
  FileUtils.makedirs(File.dirname(path))
166
177
  File.open(path, "wb+") { |f| f.write(content) }
167
178
 
@@ -2,12 +2,8 @@ require "action_controller/caching/pages"
2
2
 
3
3
  module ActionController
4
4
  module Caching
5
- eager_autoload do
6
- autoload :Pages
7
- end
8
-
9
5
  include Pages
10
6
  end
11
7
  end
12
8
 
13
- ActionController::Base.send(:include, ActionController::Caching::Pages)
9
+ ActionController::Base.include(ActionController::Caching::Pages)
data/test/caching_test.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require "abstract_unit"
2
2
  require "mocha/setup"
3
+ require "find"
3
4
 
4
5
  CACHE_DIR = "test_cache"
5
6
  # Don't change "../tmp" cavalierly or you might hose something you don't want hosed
6
7
  TEST_TMP_DIR = File.expand_path("../tmp", __FILE__)
7
8
  FILE_STORE_PATH = File.join(TEST_TMP_DIR, CACHE_DIR)
8
9
 
10
+
9
11
  module PageCachingTestHelpers
10
12
  def setup
11
13
  super
@@ -175,6 +177,25 @@ class PageCachingTest < ActionController::TestCase
175
177
  include PageCachingTestHelpers
176
178
  tests PageCachingTestController
177
179
 
180
+ def test_cache_does_not_escape
181
+ draw do
182
+ get "/page_caching_test/ok/:id", to: "page_caching_test#ok"
183
+ end
184
+
185
+ project_root = File.expand_path("../../", __FILE__)
186
+
187
+
188
+ # Make a path that escapes the cache directory
189
+ get_to_root = "../../../"
190
+
191
+ # Make sure this relative path points at the project root
192
+ assert_equal project_root, File.expand_path(File.join(FILE_STORE_PATH, get_to_root))
193
+
194
+ get :ok, params: { id: "#{get_to_root}../pwnd" }
195
+
196
+ assert_predicate Find.find(File.join(project_root, "test")).grep(/pwnd/), :empty?
197
+ end
198
+
178
199
  def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
179
200
  draw do
180
201
  get "posts.:format", to: "posts#index", as: :formatted_posts
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack-page_caching
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.0.3
88
+ rubygems_version: 3.1.2
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Static page caching for Action Pack (removed from core in Rails 4.0)