I am sending a json array with filter parameters from ExtJs in the sql function parameter.
filters look like this:
[{"field":"product_type_id","data":{"type":"number","value":"43","comparison":"in"}},{"field":"code","data":{"type":"string","value":"RRR","comparison":"like"}}]
I would like to protect myself against possible SQL injection, but my sanitizeString function removes all characters such as {, ", : etc. This prevents me from sending json, so I cannot use it for parameters. Can you tell me how to best protect myself through sql injection and at the same time pass json in the parameter without any problems?
// this.DBModels?.execQuery
execQuery<T = any>(query: string, callback: (err: Error, data: T[]) => void) {
this.db.driver.execQuery(query, (err: Error, data: T[]): void => {
callback(err, data)
})
}
this.DBModels?.execQuery(
`SELECT * FROM ${sanitizeString(functionName)}('${
functionParameter
}')`,
ormlibrary, but as you can see in the part of the code, I provide aquerywhich I concatenate as a whole string. I guess it's not sanitized by the library?node-orm2you get fromnpm install orm? If you have control or influence over this, consider a switch. Not much point discussing security issues concerning a library that saw its last patch 9 years ago.