view_component 4.7.0 → 4.9.0

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: cc884d47517a4f27d0159acd6e744d31a51b29217e3c5e38d9db9594bc25bc79
4
- data.tar.gz: 0ca9efab88b736c678177eab1edd7165365519724c9efe4b7071391f605707b8
3
+ metadata.gz: bd12f6e6a2acbb991781956cb7677076cc652b7f90519649d6d5503073feb364
4
+ data.tar.gz: bd5b8a5ef52c8f88c718c534f75626a208cba7a77f2bbced2cf22fcde70a226d
5
5
  SHA512:
6
- metadata.gz: 23fee96c0259c1a245132a138edf4233fdc228aafb4807ce62f746796295a870548420cb73f99e5ff6705d536e4cfeb6128fe87135c122741a54e8235cba9a31
7
- data.tar.gz: ca9c6a5d1af51e689d8ec17d91aa06f8cfb25781eb6b77702ecb74639778d0b7d0842f14aaed51243bc4a373329f17bf66beb2efa9d0bb7fb7ced7880d4d8878
6
+ metadata.gz: d580739f741633eb2db4f16a45a21ad0b23118021383395fb4435ff63a381b2fb08b800a1acb2b997f7d6e7f6d28f654e55d6a14cd261944b8820787b988751c
7
+ data.tar.gz: 40592ea9f341b2cd8c11971028825e6456bf5092799f69d7cfc753443c5c6672208c102522c3ec47cfbbdf282049251800f14a8dfc6a7895c3c4e8a4b275be75
@@ -8,18 +8,27 @@ class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
8
8
  @_tmpdir ||= FileUtils.mkdir_p("./tmp/view_components/").first
9
9
  end
10
10
 
11
+ rescue_from ViewComponent::SystemTestControllerNefariousPathError, with: :render_not_found
12
+
11
13
  def system_test_entrypoint
12
14
  render file: @path
13
15
  end
14
16
 
15
17
  private
16
18
 
19
+ def render_not_found
20
+ head :not_found
21
+ end
22
+
17
23
  # Ensure that the file path is valid and doesn't target files outside
18
24
  # the expected directory (e.g. via a path traversal or symlink attack)
19
25
  def validate_file_path
20
26
  base_path = ::File.realpath(self.class.temp_dir)
21
27
  @path = ::File.realpath(params.permit(:file)[:file], base_path)
22
- raise ViewComponent::SystemTestControllerNefariousPathError unless @path.start_with?(base_path)
28
+ allowed_prefix = "#{base_path}#{::File::SEPARATOR}"
29
+ unless @path == base_path || @path.start_with?(allowed_prefix)
30
+ raise ViewComponent::SystemTestControllerNefariousPathError
31
+ end
23
32
  end
24
33
  end
25
34
  end
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,26 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.9.0
14
+
15
+ * Fix path traversal vulnerability in `ViewComponentsSystemTestController` where sibling directories sharing a string prefix with the allowed temp directory could bypass the path containment check. The `start_with?` check has been replaced with a separator-aware prefix check, and nefarious path errors now return a 404 instead of an unhandled exception.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Fix preview route vulnerability where inherited methods on `ViewComponent::Preview` (such as `render_with_template`) could be invoked via the preview URL, allowing arbitrary internal Rails templates to be rendered with attacker-controlled locals and request parameters. `render_args` now raises `AbstractController::ActionNotFound` for any example not explicitly declared on the preview subclass.
20
+
21
+ *Joel Hawksley*
22
+
23
+ * Add `yard-lint` to CI.
24
+
25
+ *Joel Hawksley*
26
+
27
+ ## 4.8.0
28
+
29
+ * Add `compile.view_component` ActiveSupport::Notifications event for eager compilation at boot time.
30
+
31
+ *Joel Hawksley*, *GitHub Copilot*
32
+
13
33
  ## 4.7.0
14
34
 
15
35
  * Fix stale content cache when slots are accessed before `render_in`.
@@ -518,6 +518,7 @@ module ViewComponent
518
518
  # @param extensions [Array<String>] Extensions of which to return matching sidecar files.
519
519
  def sidecar_files(extensions)
520
520
  return [] unless identifier
521
+ return [] unless name
521
522
 
522
523
  extensions = extensions.join(",")
523
524
 
@@ -57,9 +57,8 @@ module ViewComponent
57
57
  end
58
58
  end
59
59
 
60
+ # @param requested_details [ActionView::TemplateDetails::Requested] i.e. locales, formats, variants
60
61
  # @return all matching compiled templates, in priority order based on the requested details from LookupContext
61
- #
62
- # @param [ActionView::TemplateDetails::Requested] requested_details i.e. locales, formats, variants
63
62
  def find_templates_for(requested_details)
64
63
  filtered_templates = @templates.select do |template|
65
64
  template.details.matches?(requested_details)
@@ -79,7 +79,15 @@ module ViewComponent
79
79
 
80
80
  initializer "view_component.eager_load_actions" do
81
81
  ActiveSupport.on_load(:after_initialize) do
82
- ViewComponent::Base.descendants.each(&:__vc_compile) if Rails.application.config.eager_load
82
+ if Rails.application.config.eager_load
83
+ ActiveSupport::Notifications.instrument("compile.view_component") do
84
+ ViewComponent::Base.descendants.each do |component|
85
+ next if component.anonymous?
86
+
87
+ component.__vc_compile
88
+ end
89
+ end
90
+ end
83
91
  end
84
92
  end
85
93
 
@@ -40,6 +40,8 @@ module ViewComponent # :nodoc:
40
40
 
41
41
  # Returns the arguments for rendering of the component in its layout
42
42
  def render_args(example, params: {})
43
+ raise AbstractController::ActionNotFound, "#{example} is not a valid preview example" unless examples.include?(example.to_s)
44
+
43
45
  example_params_names = instance_method(example).parameters.map(&:last)
44
46
  provided_params = params.slice(*example_params_names).to_h.symbolize_keys
45
47
  result = provided_params.empty? ? new.public_send(example) : new.public_send(example, **provided_params)
@@ -96,7 +96,6 @@ module ViewComponent
96
96
  # end
97
97
  # end
98
98
  # end
99
- #
100
99
  def method_missing(symbol, *args, **kwargs, &block)
101
100
  @__vc_component_instance.public_send(symbol, *args, **kwargs, &block)
102
101
  end
@@ -71,17 +71,16 @@ module ViewComponent
71
71
  # assert_text("Hello, World!")
72
72
  # ```
73
73
  #
74
- # Note: `#rendered_preview` expects a preview to be defined with the same class
75
- # name as the calling test, but with `Test` replaced with `Preview`:
76
- #
77
- # MyComponentTest -> MyComponentPreview etc.
78
- #
79
- # In RSpec, `Preview` is appended to `described_class`.
80
- #
81
74
  # @param name [String] The name of the preview to be rendered.
82
75
  # @param from [ViewComponent::Preview] The class of the preview to be rendered.
83
76
  # @param params [Hash] Parameters to be passed to the preview.
84
77
  # @return [Nokogiri::HTML5]
78
+ # @note `#rendered_preview` expects a preview to be defined with the same class
79
+ # name as the calling test, but with `Test` replaced with `Preview`:
80
+ #
81
+ # MyComponentTest -> MyComponentPreview etc.
82
+ #
83
+ # In RSpec, `Preview` is appended to `described_class`.
85
84
  def render_preview(name, from: __vc_test_helpers_preview_class, params: {})
86
85
  previews_controller = __vc_test_helpers_build_controller(Rails.application.config.view_component.previews.controller.constantize)
87
86
 
@@ -125,7 +124,7 @@ module ViewComponent
125
124
  # end
126
125
  # ```
127
126
  #
128
- # @param variants [Symbol[]] The variants to be set for the provided block.
127
+ # @param variants [Array<Symbol>] The variants to be set for the provided block.
129
128
  def with_variant(*variants)
130
129
  old_variants = vc_test_controller.view_context.lookup_context.variants
131
130
 
@@ -162,7 +161,7 @@ module ViewComponent
162
161
  # end
163
162
  # ```
164
163
  #
165
- # @param formats [Symbol[]] The format(s) to be set for the provided block.
164
+ # @param formats [Array<Symbol>] The format(s) to be set for the provided block.
166
165
  def with_format(*formats)
167
166
  old_formats = vc_test_controller.view_context.lookup_context.formats
168
167
 
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 4
6
- MINOR = 7
6
+ MINOR = 9
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team