CVE-2016-15019 (published 2023-01-15T19:15Z)

A vulnerability was found in tombh jekbox. It has been rated as problematic. This issue affects some unknown processing of the file lib/server.rb. The manipulation leads to exposure of information through directory listing. The attack may be initiated remotely. The patch is named 64eb2677671018fc08b96718b81e3dbc83693190. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-218375.

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/tombh/jekbox
commit_details: repo_url: https://github.com/tombh/jekbox
author: Thomas Buckley-Houston
author_date: 2016-02-01 13:08:18+01:00
msg: Ensure that requests ending with a slash and without try looking for an index.html file. And prevent malicious directory traversing
repository: repo_url: https://github.com/tombh/jekbox
repo_name: tombh/jekbox
description: Automatically deploy Jekyll sites by creating a site folder in your Dropbox
repo_language: Ruby
owner: tombh
file_changes: filename: file_handler.rb
change_type: ModificationType.MODIFY
diff: @@ -1,16 +1,15 @@
+# Useful file methods
 class FileHandler
   def self.media_type(filename)
     extension = ::File.extname(filename)
-
     Rack::Mime.mime_type(extension)
   end
 
   def self.file_info(path)
     info = {
-      :body => ::File.read(path),
-      :time => ::File.mtime(path).httpdate
+      body: ::File.read(path),
+      time: ::File.mtime(path).httpdate
     }
-
     info
   end
 end

programming_language: Ruby
filename: server.rb
change_type: ModificationType.MODIFY
diff: @@ -10,18 +10,19 @@ class Server
   end
 
   def file_path
-    if @request.path_info.end_with?('/')
-      normalized = @request.path_info + 'index.html'
-    else
-      normalized = @request.path_info
-    end
     @root = File.join Jekbox::DROPBOX_PATH, @request.host
-    File.join @root, '_site', normalized
+    path = File.expand_path File.join @root, '_site', @request.path_info
+    with_index = File.join path, 'index.html'
+    if File.file? path
+      path
+    elsif File.file? with_index
+      with_index
+    end
   end
 
   def build_response
     @file = file_path
-    if File.exist? @file
+    if @file
       build_file_response
     else
       build_404
@@ -30,6 +31,7 @@ class Server
   end
 
   def build_file_response
+    fail unless @file.include? @root # Prevent malicious path requests
     file_info = FileHandler.file_info @file
     body = file_info[:body]
     time = file_info[:time]

programming_language: Ruby
filename: index.html
change_type: ModificationType.ADD
diff: @@ -0,0 +1 @@
+Deep page

programming_language: SQL
filename: server_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -11,14 +11,32 @@ describe Server do
   end
 
   describe 'Find paths' do
-    it 'should find the index.html file when a URL without a file is requested' do
-      get 'http://jekbox.example.com'
-      expect(last_response.body).to eq "The index page\n"
+    context 'Finding the index.html file when a URL without a file is requested' do
+      it 'should use index.html when root is requested' do
+        get 'http://jekbox.example.com'
+        expect(last_response.body).to eq "The index page\n"
+      end
+
+      it 'should use index.html when a / is present' do
+        get 'http://jekbox.example.com/deep/'
+        expect(last_response.body).to eq "Deep page\n"
+      end
+
+      it 'should use index.html when a / is not present' do
+        get 'http://jekbox.example.com/deep'
+        expect(last_response.body).to eq "Deep page\n"
+      end
     end
 
     it 'should find a normal file' do
-      get 'http://jekbox.example.com/foo.css'
+      get 'http://jekbox.example.com/assets/foo.css'
       expect(last_response.body).to eq "body {}\n"
     end
+
+    it 'should find a normal file' do
+      expect do
+        get 'http://jekbox.example.com/../../../spec_helper.rb'
+      end.to raise_error RuntimeError
+    end
   end
 end

programming_language: Ruby