Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Jube.Data/Reporting/Postgres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@
{
await connection.OpenAsync();

var command = new NpgsqlCommand(sql);
var command = new NpgsqlCommand();
command.Connection = connection;

for (var i = 0; i < parameters.Count; i++)
command.Parameters.AddWithValue("@" + (i + 1), parameters[i]);
{
var paramName = "@param" + (i + 1);
sql = sql.Replace("@" + (i + 1), paramName);
command.Parameters.AddWithValue(paramName, parameters[i]);
}

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.

await command.PrepareAsync();
}
catch
Expand Down
Loading