▲ | nhumrich 9 days ago | |||||||||||||||||||||||||||||||
> You could achieve the same thing with a function returning an f-string no no. > just use a tag type and a sanitisation function that takes a string and returns the type Okay, so you have a `sqlstring(somestring)` function, and the dev has to call it. But... what if they pass in an f-string? `sqlstring(f'select from mytable where col = {value}')` You havent actually prevented/enforced anything. With template strings, its turtles all the way down. You can enforce they pass in a template and you can safely escape anything that is a variable because its impossible to have a variable type (possible injection) in the template literal. | ||||||||||||||||||||||||||||||||
▲ | ratorx 9 days ago | parent [-] | |||||||||||||||||||||||||||||||
Added example to parent comment. This example still works, the entire f-string is sanitised (including whatever the value of name was). Assuming sqlstring is the sanitisation function. The “template” would be a separate function that returns an f-string bound from function arguments. | ||||||||||||||||||||||||||||||||
|