Skip to content

Conversation

@MartinHinz
Copy link
Collaborator

lots of speed improvements and some opening up json endpoints

end

def apply_selects
@xrons = @xrons.select(*@selects).distinct

Check failure

Code scanning / CodeQL

SQL query built from user-controlled sources High

This SQL query depends on a
user-provided value
.

Copilot Autofix

AI about 1 month ago

To prevent SQL injection, untrusted data from the user must be validated/sanitized before being used in the .select(*@selects) call. The best fix is to implement a whitelist of allowed column names, and reject or ignore anything outside this list.

  • In app/controllers/xronos_data_controller.rb, define a constant (for example, ALLOWED_SELECT_COLUMNS) that lists permitted column names.
  • Change the select_params method to filter incoming parameters and only permit keys/values within that whitelist.
  • This will ensure that only safe, known columns are ever sent to the model and splatted into the SQL SELECT.
  • Changes are required in the select_params method in XronosDataController, only on the code shown.

Suggested changeset 1
app/controllers/xronos_data_controller.rb
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/controllers/xronos_data_controller.rb b/app/controllers/xronos_data_controller.rb
--- a/app/controllers/xronos_data_controller.rb
+++ b/app/controllers/xronos_data_controller.rb
@@ -141,9 +141,12 @@
 
   private
 
+  # Only allow known, safe columns through 'select' param
+  ALLOWED_SELECT_COLUMNS = %w[
+    id name lng lat
+    # Add whatever other columns you wish to permit
+  ].freeze
   # ---------------------------
-  # Helpers for caching
-  # ---------------------------
 
   def unfiltered_request?
     filter_params.blank? && select_params.blank?
@@ -249,8 +251,11 @@
     )
   end
 
-  # TODO: is this safe???
+  # Filter select params: only allow whitelisted columns
   def select_params
-    params.fetch(:select, {})
+    select = params.fetch(:select, {})
+    # if select param is hash (e.g., from checkboxes), get values; if array, use directly
+    select_values = select.is_a?(Array) ? select : select.values
+    select_values.select { |col| ALLOWED_SELECT_COLUMNS.include?(col.to_s) }
   end
 end
EOF
@@ -141,9 +141,12 @@

private

# Only allow known, safe columns through 'select' param
ALLOWED_SELECT_COLUMNS = %w[
id name lng lat
# Add whatever other columns you wish to permit
].freeze
# ---------------------------
# Helpers for caching
# ---------------------------

def unfiltered_request?
filter_params.blank? && select_params.blank?
@@ -249,8 +251,11 @@
)
end

# TODO: is this safe???
# Filter select params: only allow whitelisted columns
def select_params
params.fetch(:select, {})
select = params.fetch(:select, {})
# if select param is hash (e.g., from checkboxes), get values; if array, use directly
select_values = select.is_a?(Array) ? select : select.values
select_values.select { |col| ALLOWED_SELECT_COLUMNS.include?(col.to_s) }
end
end
Copilot is powered by AI and may make mistakes. Always verify output.
@MartinHinz MartinHinz merged commit dd13cd7 into master Dec 11, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants