CVE-2014-125033 (published 2023-01-02T08:15Z)

A vulnerability was found in rails-cv-app. It has been rated as problematic. Affected by this issue is some unknown functionality of the file app/controllers/uploaded_files_controller.rb. The manipulation with the input ../../../etc/passwd leads to path traversal: '../filedir'. The exploit has been disclosed to the public and may be used. The patch is identified as 0d20362af0a5f8a126f67c77833868908484a863. It is recommended to apply a patch to fix this issue. VDB-217178 is the identifier assigned to this vulnerability.

CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/bertrand-caron/rails-cv-app
commit_details: repo_url: https://github.com/bertrand-caron/rails-cv-app
author: Bertrand Caron
author_date: 2014-11-16 22:59:19+01:00
msg: HOTFIX : Another vulnerability picked up by Brakeman

- Potential Path Traversal attack (tested working !)
I could potentially explore the whole filesystem with root access
(Ex: filename: '../../../etc/passwd')
- Added (empty) specs to detect it
repository: repo_url: https://github.com/bertrand-caron/rails-cv-app
repo_name: bertrand-caron/rails-cv-app
description: A Rails App for a neat-looking, easily customisable Curriculum Vitae
repo_language: Ruby
owner: bertrand-caron
file_changes: filename: uploaded_files_controller.rb
change_type: ModificationType.MODIFY
diff: @@ -39,6 +39,11 @@ class UploadedFilesController < ApplicationController
     @uploaded_file.name.gsub!(/ /, '-')
 
     # Then write to file
+    # WARNING : File.open is definitely vulnerable to Path Traversal Attacks
+    # (https://www.owasp.org/index.php/Path_Traversal) 
+    # The following line should take care of it, by only taking the past part of the path (aka filename)
+    @uploaded_file.name = @uploaded_file.name.split(/\//)[-1]
+
     File.open(@uploaded_file.absolute_path, 'wb') do |file|
       file.write(uploaded_io.read)
     end

programming_language: Ruby
filename: helpers_controller_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -9,11 +9,11 @@ describe HelpersController, type: :controller do
         expect(response).to redirect_to(root_url)
       end
     end
-    context 'with session cookie' do
-      it 'corrects incorrect HTML' do
-        post 'html_renderer', content: '<div>Hello', format: :html
-        expect(response.body).to eq('<div>Hello</div>')
-      end
-    end
+#    context 'with session cookie' do
+#      it 'corrects incorrect HTML' do
+#        post 'html_renderer', content: '<div>Hello', format: :html
+#        expect(response.body).to eq('<div>Hello</div>')
+#      end
+#    end
   end
 end

programming_language: Ruby
filename: uploaded_file_spec.rb
change_type: ModificationType.ADD
diff: @@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe UploadedFilesController, type: :controller do
+  it 'has a valid factory' do
+    expect( FactoryGirl.create(:uploaded_file)).to be_valid
+  end
+
+  it 'does not accept relative paths in file name'
+end

programming_language: Ruby
filename: uploaded_file.rb
change_type: ModificationType.ADD
diff: @@ -0,0 +1,11 @@
+require 'faker'
+
+FactoryGirl.define do
+  factory :uploaded_file do |f|
+    f.name 'hello.png'
+  end
+
+  factory :dangerous_file, class: UploadedFile do |f|
+    f.name '../Hello.png'
+  end
+end

programming_language: Ruby