-
Notifications
You must be signed in to change notification settings - Fork 0
Hotfixes json #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfixes json #400
Conversation
| end | ||
|
|
||
| def apply_selects | ||
| @xrons = @xrons.select(*@selects).distinct |
Check failure
Code scanning / CodeQL
SQL query built from user-controlled sources High
user-provided value
Show autofix suggestion
Hide autofix suggestion
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_paramsmethod 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_paramsmethod inXronosDataController, only on the code shown.
-
Copy modified lines R144-R148 -
Copy modified line R254 -
Copy modified lines R256-R259
| @@ -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 |
lots of speed improvements and some opening up json endpoints