I wrote some code for mysql, at first i had it all parameterized. Then later a someone told me that it wasn't safe any-more. Its an old program i try to fix, but the standard input queries where not safe against injections. Though there are a lot of 'other' mysql things happening in the code, there are not much areas where new data is generated, or open user queries. So then i thought (not to endup in a battle of whats the best injection proof method), lets reformat the input strings so we never can get in such situations. I wrote a regex to always have properly formated varchar input fields
I am now using this for that:
public string AllowedAsci(string input, string symbol="*")
{
return Regex.Replace(input, @"[^a-zA-Z0-9-+_@., ]", symbol);
}
That's basically a strict regex for basic Email and numbers, my question is can this regex be extended width other safe to use symbols.
Important update
The point of this question never was to raise a discussion about using mysql parameters, i knew that from the beginning, though politics are at work, here are branches of code who am i not allowed to touch. For the moment i have no intentions to get (again) into an argue at work nor to touch that code, i'l blame them in the end maybe but its political.
So please stay on topic what is a good regex to remove escape codes but on the other hand allow strings that dont allow for injection.
- the regex rule does protect against all injections that i know of unless you can can proof me wrong width a better regex.