CVE-2014-125067: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability classified as critical was found in corincerami curiosity. Affected by this vulnerability is an unknown functionality of the file app/controllers/image_controller.rb. The manipulation of the argument sol leads to sql injection. The patch is named d64fddd74ca72714e73f4efe24259ca05c8190eb. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-217639.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 9.8
Published: 2023-01-08T10:15Z
Repository: https://github.com/corincerami/curiosity
Language: Other
Files changed: .gitignore, app/controllers/image_controller.rb, app/views/image/show.html.erb
Commit date: 2014-12-07 13:00:33 -0500
Commit message: Sanitized form input to protect against SQL injection.

Diff: diff --git a/.gitignore b/.gitignore
index f0b75a1..cdd02dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,5 +13,6 @@
 
 # Ignore all logfiles and tempfiles.
 /log/*.log
 /tmp
 .env
+images.rb
diff --git a/app/controllers/image_controller.rb b/app/controllers/image_controller.rb
index cb35712..1f0dc1c 100644
--- a/app/controllers/image_controller.rb
+++ b/app/controllers/image_controller.rb
@@ -1,12 +1,11 @@
 class ImageController < ApplicationController
   def show
-    @images = Image.where(sol: params[:sol])
+    @images = Image.where(:sol => params[:sol])
   end
 
   def index
-    # find the martial solar date of the most recent image taken
-    # @most_recent = Image.all.sort_by { |hash| -hash[:sol].to_i }.first[:sol]
+    # find the martian solar date of the most recent image taken
     @image_count = Image.count
     @most_recent = Image.maximum(:sol)
   end
 end
diff --git a/app/views/image/show.html.erb b/app/views/image/show.html.erb
index 67973c1..5900246 100644
--- a/app/views/image/show.html.erb
+++ b/app/views/image/show.html.erb
@@ -1,9 +1,9 @@
 <div class='row'>
   <div class='small 6'>
     <p>
-      These photos were captured by Curiosity on sol <%= params[:sol] %> of its mission on Mars. They come from its eight cameras: the front hazard avoidance camera (FHAZ), read hazard avoidance camera (RHAZ), left and right navigation cameras (NAVCAM), chemistry camera (CHEMCAM), Mars descent imager (MARDI), Mars hand lens imager (MAHLI), and mast camera (Mastcam).
+      These photos were captured by Curiosity on sol <%=h params[:sol] %> of its mission on Mars. They come from its eight cameras: the front hazard avoidance camera (FHAZ), read hazard avoidance camera (RHAZ), left and right navigation cameras (NAVCAM), chemistry camera (CHEMCAM), Mars descent imager (MARDI), Mars hand lens imager (MAHLI), and mast camera (Mastcam).
     </p>
   </div>
 </div>
 
 <% @images.each do |image| %>

Vulnerable code:     @images = Image.where(sol: params[:sol])
    # find the martial solar date of the most recent image taken
    # @most_recent = Image.all.sort_by { |hash| -hash[:sol].to_i }.first[:sol]
      These photos were captured by Curiosity on sol <%= params[:sol] %> of its mission on Mars. They come from its eight cameras: the front hazard avoidance camera (FHAZ), read hazard avoidance camera (RHAZ), left and right navigation cameras (NAVCAM), chemistry camera (CHEMCAM), Mars descent imager (MARDI), Mars hand lens imager (MAHLI), and mast camera (Mastcam).
Fixed code: images.rb
    @images = Image.where(:sol => params[:sol])
    # find the martian solar date of the most recent image taken
      These photos were captured by Curiosity on sol <%=h params[:sol] %> of its mission on Mars. They come from its eight cameras: the front hazard avoidance camera (FHAZ), read hazard avoidance camera (RHAZ), left and right navigation cameras (NAVCAM), chemistry camera (CHEMCAM), Mars descent imager (MARDI), Mars hand lens imager (MAHLI), and mast camera (Mastcam).