More hardening
This commit is contained in:
@@ -228,7 +228,7 @@ namespace Swarmops.Database
|
||||
return d.ToString ("yyyyMMddHHmmss");
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("This should be replaced with parameterized queries everywhere, so making a compile error.", true)]
|
||||
private string SqlSanitize (string input) // TODO: Replace with parameterized queries everywhere.
|
||||
{
|
||||
string[] forbiddenArray =
|
||||
|
||||
@@ -77,6 +77,8 @@ namespace Swarmops.Database
|
||||
"SELECT" + currencyFieldSequence + "WHERE Code='" +
|
||||
currencyCode.Replace("'", "''").ToUpperInvariant() + "';", connection);
|
||||
|
||||
// TODO: NOTE THIS STRING QUERY, THOUGH IN COMMENTED OUT CODE, IS NOT PARAMETERIZED
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
|
||||
@@ -221,7 +221,9 @@ namespace Swarmops.Database
|
||||
DbCommand command =
|
||||
GetDbCommand (
|
||||
"SELECT " + financialTransactionFieldSequence + " WHERE OrganizationId=" +
|
||||
organizationId + " AND ImportHash='" + SqlSanitize(importKey) + "';", connection);
|
||||
organizationId + " AND ImportHash=@importKey';", connection);
|
||||
|
||||
AddParameterWithName(command, "importKey", importKey);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
@@ -1135,17 +1137,21 @@ namespace Swarmops.Database
|
||||
|
||||
using (DbCommand command =
|
||||
GetDbCommand(
|
||||
"Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" + (int)foreignIdType +
|
||||
" AND ForeignId='" + SqlSanitize(foreignId) + "';", connection))
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
"Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" +
|
||||
(int) foreignIdType + " AND ForeignId=@foreignId;", connection))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return reader.GetInt32(0);
|
||||
}
|
||||
|
||||
return 0; // none found. Todo: throw exception instead? This behavior is inconsistent
|
||||
AddParameterWithName(command, "foreignId", foreignId);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return reader.GetInt32(0);
|
||||
}
|
||||
|
||||
return 0; // none found. Todo: throw exception instead? This behavior is inconsistent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace Swarmops.Database
|
||||
"AND ObjectOptionalDataTypes.Name='" + dataType.ToString() + "' " +
|
||||
"AND ObjectOptionalData.Data='" + data.Replace("'", "''") + "';", connection);
|
||||
|
||||
// NOTE: THIS STRING QUERY IS NOT PARAMETERIZED, EVEN THOUGH IT'S IN COMMENTED OUT CODE
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
|
||||
@@ -66,6 +66,9 @@ namespace Swarmops.Database
|
||||
|
||||
public void DeleteOrganization (int OrganizationId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*
|
||||
int deletedOrganizationsID = 98;
|
||||
BasicOrganization org = GetOrganization (OrganizationId);
|
||||
//Delete is done by setting parent ID to deletedOrganizationsID
|
||||
@@ -80,7 +83,7 @@ namespace Swarmops.Database
|
||||
org.AcceptsMembers,
|
||||
org.AutoAssignNewMembers,
|
||||
org.DefaultCountryId,
|
||||
OrganizationId);
|
||||
OrganizationId);*/
|
||||
}
|
||||
|
||||
public void UpdateOrganization (int ParentOrganizationId, string NameInternational, string Name,
|
||||
|
||||
@@ -66,9 +66,9 @@ namespace Swarmops.Database
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand (
|
||||
"SELECT " + personFieldSequence + " WHERE Name like '" +
|
||||
GetSqlPatternFromNamePattern (namePattern).Replace ("'", "''") + "'",
|
||||
"SELECT " + personFieldSequence + " WHERE Name like @namePattern",
|
||||
connection);
|
||||
AddParameterWithName(command, "namePattern", namePattern);
|
||||
command.CommandTimeout = 120;
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
@@ -86,7 +86,7 @@ namespace Swarmops.Database
|
||||
private string GetSqlPatternFromNamePattern (string namePattern)
|
||||
{
|
||||
// Remove any injection codes
|
||||
namePattern = SqlSanitize (namePattern).Replace ("%", String.Empty).Trim();
|
||||
namePattern = namePattern.Replace ("%", String.Empty).Trim();
|
||||
|
||||
while (namePattern.Contains (" "))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user