Skip to content

Commit a425ab2

Browse files
jasnowRubySec CI
authored and
RubySec CI
committedOct 9, 2024·
Updated advisory posts against rubysec/ruby-advisory-db@a93d52d
1 parent 07765d7 commit a425ab2

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
layout: advisory
3+
title: 'CVE-2024-46986 (camaleon_cms): Camaleon CMS affected by arbitrary file write
4+
to RCE (GHSL-2024-182)'
5+
comments: false
6+
categories:
7+
- camaleon_cms
8+
advisory:
9+
gem: camaleon_cms
10+
cve: 2024-46986
11+
ghsa: wmjg-vqhv-q5p5
12+
url: https://github.com/owen2345/camaleon-cms/security/advisories/GHSA-wmjg-vqhv-q5p5
13+
title: Camaleon CMS affected by arbitrary file write to RCE (GHSL-2024-182)
14+
date: 2024-09-18
15+
description: |
16+
An arbitrary file write vulnerability accessible via the upload method
17+
of the `MediaController` allows authenticated users to write arbitrary
18+
files to any location on the web server Camaleon CMS is running on
19+
(depending on the permissions of the underlying filesystem).
20+
E.g. This can lead to a delayed remote code execution in case an
21+
attacker is able to write a Ruby file into the `config/initializers/`
22+
subfolder of the Ruby on Rails application.
23+
24+
Once a user upload is started via the [upload] method, the
25+
`file_upload` and the folder parameter.
26+
27+
[upload]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/controllers/camaleon_cms/admin/media_controller.rb#L86-L87
28+
29+
```ruby
30+
def upload(settings = {})
31+
params[:dimension] = nil if params[:skip_auto_crop].present?
32+
f = { error: 'File not found.' }
33+
if params[:file_upload].present?
34+
f = upload_file(params[:file_upload],
35+
{ folder: params[:folder], dimension: params['dimension'], formats: params[:formats], versions: params[:versions],
36+
thumb_size: params[:thumb_size] }.merge(settings))
37+
end
38+
[..]
39+
end
40+
```
41+
42+
are passed to the [upload_file] method. Inside that method the
43+
given settings are [merged] with some presets. The file format
44+
is [checked against] the formats settings we can override with
45+
the formats parameters.
46+
47+
[upload_file]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L23-L24
48+
[merged]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L41-L42
49+
[checked against]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L61-L62
50+
51+
```ruby
52+
# formats validations
53+
return { error: "#{ct('file_format_error')} (#{settings[:formats]})" } unless cama_uploader.class.validate_file_format(
54+
uploaded_io.path, settings[:formats]
55+
)
56+
```
57+
58+
Our given folder is then [passed unchecked] to the `Cama_uploader`:
59+
60+
[passed unchecked]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/helpers/camaleon_cms/uploader_helper.rb#L73-L74
61+
62+
```ruby
63+
key = File.join(settings[:folder], settings[:filename]).to_s.cama_fix_slash
64+
res = cama_uploader.add_file(settings[:uploaded_io], key, { same_name: settings[:same_name] })
65+
```
66+
67+
In the [add_file] method of `CamaleonCmsLocalUploader` this key argument containing the
68+
unchecked path is then used to write the file to the file system:
69+
70+
[add_file]: https://github.com/owen2345/camaleon-cms/blob/feccb96e542319ed608acd3a16fa5d92f13ede67/app/uploaders/camaleon_cms_local_uploader.rb#L77
71+
72+
```ruby
73+
def add_file(uploaded_io_or_file_path, key, args = {})
74+
[..]
75+
upload_io = uploaded_io_or_file_path.is_a?(String) ? File.open(uploaded_io_or_file_path) : uploaded_io_or_file_path
76+
File.open(File.join(@root_folder, key), 'wb') { |file| file.write(upload_io.read) }
77+
[..]
78+
end
79+
```
80+
81+
## Impact
82+
83+
This issue may lead up to Remote Code Execution (RCE) via arbitrary
84+
file write.
85+
86+
## Remediation
87+
88+
Normalize file paths constructed from untrusted user input before using
89+
them and check that the resulting path is inside the targeted directory.
90+
Additionally, do not allow character sequences such as `..` in untrusted
91+
input that is used to build paths.
92+
93+
## See Also
94+
95+
[CodeQL: Uncontrolled data used in path expression](https://codeql.github.com/codeql-query-help/ruby/rb-path-injection/)
96+
[OWASP: Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal)
97+
cvss_v3: 9.9
98+
unaffected_versions:
99+
- "< 2.8.0"
100+
patched_versions:
101+
- ">= 2.8.1"
102+
related:
103+
url:
104+
- https://nvd.nist.gov/vuln/detail/CVE-2024-46986
105+
- https://github.com/owen2345/camaleon-cms/security/advisories/GHSA-wmjg-vqhv-q5p5
106+
- https://github.com/owen2345/camaleon-cms/commit/b3b12b1e4a9e3fccaf5bb4330820fa7f8744e6bd
107+
- https://codeql.github.com/codeql-query-help/ruby/rb-path-injection
108+
- https://owasp.org/www-community/attacks/Path_Traversal
109+
- https://www.reddit.com/r/rails/comments/1exwtdm/camaleon_cms_281_has_been_released
110+
- https://github.com/advisories/GHSA-wmjg-vqhv-q5p5
111+
---

0 commit comments

Comments
 (0)
Please sign in to comment.