r/shittyprogramming • u/icefall5 • Mar 30 '17
This is how you properly sanitize user input
8
9
u/ShowMeYourTiddles Mar 30 '17
My god! For-loop with a switch statement ffs.
0
Mar 30 '17
[deleted]
7
u/jimmpony Mar 30 '17
weird cases like this make me appreciate how Visual Studio enforces a standard styling for c# that you can change parts of with editorconfig (now natively included) and you can fix a file with a short key combo
0
Mar 30 '17
[deleted]
4
Mar 31 '17
The eternal programmer paradox:
job is to make other people's lives easier
goes out of their way to make things as difficult as possible for themselves
0
2
1
u/shatteredarm1 Mar 31 '17
Maybe this would be better? Works in C#:
for(int i = 0; i < 10; (new Action<int>((int j) => { switch(j ){ case 1: ... }}))(i++));
4
u/jimmpony Mar 30 '17
even if they didn't want to use built in escaping functions, why didn't they just remove all <>'etc instead of trying to enumerate every tag possible to be malicious with?
2
1
3
u/LowB0b Mar 30 '17
is this from a coworker of yours? please tell him about regex, loops and arrays :(
2
Mar 30 '17
Just noticed the SanitizeInput function. If that doesn't 'sanitize' the input properly then I have no idea what it's supposed to do otherwise.
6
u/tomharto Mar 31 '17
It vaguely reminds me of how my step mum used to clean up the house before the cleaner they have comes around.
1
1
1
1
1
u/zhezow Apr 11 '17
Thanks! Very nice tip! Can you send me as a text, so I can copy and use on my project?
1
0
Mar 30 '17
[deleted]
11
0
Mar 30 '17
[deleted]
2
1
u/theavengedCguy Mar 31 '17
Can you explain this piece of code that you wrote please? I'm guessing that it embeds arbitrary code within an img tag, but how?
8
u/chrismbarr Mar 31 '17
The one source is set to a bad URL, so when the image fails to load it will run the script in the
onerrorattribute. That's just something built into HTML that is being exploited here.0
69
u/down_vote_magnet Mar 30 '17
I'm not sure if I opened and viewed the image or if I had a stroke.