Skip to content
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

Potential fix for code scanning alert no. 75: SQL query built from user-controlled sources #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

richard-churchman
Copy link
Contributor

Potential fix for https://github.com/jube-home/jube/security/code-scanning/75

To fix the problem, we should use parameterized queries for the entire SQL statement, not just the values. This involves restructuring the code to avoid direct concatenation of user inputs into the SQL query. Instead, we should use placeholders for all parts of the query that are influenced by user input and then bind the actual values to these placeholders.

In the PrepareAsync method, we will modify the SQL query to use named parameters and bind the corresponding values from the parameters list. This will ensure that the SQL query is safe from injection attacks.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…er-controlled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@richard-churchman richard-churchman marked this pull request as ready for review February 22, 2025 17:02

command.CommandText = sql;

Check failure

Code scanning / CodeQL

SQL query built from user-controlled sources High

This query depends on
this ASP.NET Core MVC action method parameter
.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This automated suggestion is way off.

I will use this branch however to remove the direct path for string concatenation. I believe in the commit that was intended to address this, there is already some checking that the values passed are valid based on model configuration. Here I will go a step further and look the values up, and concatenate them the value returned from various dictionaries or lists (they should after all be the same value). In the absence of the values available, will error it out.

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.

None yet

1 participant