Skip to content

Commit 359a9f2

Browse files
jasnowpostmodern
andauthored
GHSA SYNC: 1 brand new advisory (#767)
--------- Co-authored-by: Postmodern <postmodern.mod3@gmail.com>
1 parent 81353c4 commit 359a9f2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
gem: stimulus_reflex
3+
cve: 2024-28121
4+
ghsa: f78j-4w3g-4q65
5+
url: https://github.com/stimulusreflex/stimulus_reflex/security/advisories/GHSA-f78j-4w3g-4q65
6+
title: StimulusReflex arbitrary method call
7+
date: 2024-03-12
8+
description: |
9+
### Summary
10+
11+
More methods than expected can be called on reflex instances.
12+
Being able to call some of them has security implications.
13+
14+
### Details
15+
16+
To invoke a reflex a websocket message of the following shape is sent:
17+
18+
```json
19+
{
20+
"target": "[class_name]#[method_name]",
21+
"args": []
22+
}
23+
```
24+
25+
The server will proceed to instantiate `reflex` using the provided `class_name` as long as it extends `StimulusReflex::Reflex`. It then attempts to call `method_name` on the instance with the provided arguments [ref]:
26+
27+
[ref]: https://github.com/stimulusreflex/stimulus_reflex/blob/0211cad7d60fe96838587f159d657e44cee51b9b/app/channels/stimulus_reflex/channel.rb#L83
28+
29+
```ruby
30+
method = reflex.method method_name
31+
required_params = method.parameters.select { |(kind, _)| kind == :req }
32+
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
33+
34+
if arguments.size >= required_params.size && arguments.size <= required_params.size + optional_params.size
35+
reflex.public_send(method_name, *arguments)
36+
end
37+
```
38+
39+
This is problematic as `reflex.method(method_name)` can be more methods than those explicitly specified by the developer in their reflex class. A good example is the `instance_variable_set` method.
40+
41+
```json
42+
{
43+
"target": "StimulusReflex::Reflex#render_collection",
44+
"args": [
45+
{ "inline": "<% system('[command here]') %>" }
46+
]
47+
}
48+
```
49+
50+
### Patches
51+
52+
Patches are available on [RubyGems] and on [NPM].
53+
54+
[RubyGems]: https://rubygems.org/gems/stimulus_reflex
55+
[NPM]: https://npmjs.org/package/stimulus_reflex
56+
57+
The patched versions are:
58+
- [`3.4.2`](https://github.com/stimulusreflex/stimulus_reflex/releases/tag/v3.4.2)
59+
- [`3.5.0.rc4`](https://github.com/stimulusreflex/stimulus_reflex/releases/tag/v3.5.0.rc4)
60+
61+
### Workaround
62+
63+
You can add this guard to mitigate the issue if running an unpatched
64+
version of the library.
65+
1.) Make sure all your reflexes inherit from the `ApplicationReflex`
66+
class
67+
2.) Add this `before_reflex` callback to your `app/reflexes/application_reflex.rb` file:
68+
69+
```ruby
70+
class ApplicationReflex < StimulusReflex::Reflex
71+
before_reflex do
72+
ancestors = self.class.ancestors[0..self.class.ancestors.index(StimulusReflex::Reflex) - 1]
73+
allowed = ancestors.any? { |a| a.public_instance_methods(false).any?(method_name.to_sym) }
74+
75+
raise ArgumentError.new("Reflex method '#{method_name}' is not defined on class '#{self.class.name}' or on any of its ancestors") if !allowed
76+
end
77+
end
78+
```
79+
cvss_v3: 8.8
80+
patched_versions:
81+
- "~> 3.4.2"
82+
- ">= 3.5.0.rc4"
83+
related:
84+
url:
85+
- https://nvd.nist.gov/vuln/detail/CVE-2024-28121
86+
- http://seclists.org/fulldisclosure/2024/Mar/16
87+
- https://github.com/stimulusreflex/stimulus_reflex/releases/tag/v3.4.2
88+
- https://github.com/stimulusreflex/stimulus_reflex/releases/tag/v3.5.0.rc4
89+
- https://github.com/stimulusreflex/stimulus_reflex/security/advisories/GHSA-f78j-4w3g-4q65
90+
- https://github.com/stimulusreflex/stimulus_reflex/commit/538582d240439aab76066c72335ea92096cd0c7f
91+
- https://github.com/stimulusreflex/stimulus_reflex/commit/d823d7348f9ca42eb6df25574f11974e4f5bc88c
92+
- https://github.com/stimulusreflex/stimulus_reflex/blob/0211cad7d60fe96838587f159d657e44cee51b9b/app/channels/stimulus_reflex/channel.rb#L83
93+
- https://github.com/advisories/GHSA-f78j-4w3g-4q65

0 commit comments

Comments
 (0)