How to prevent code injection attacks in PHP?

mysql_real_escape_string used when insert into database htmlentities() used when outputting data into webpage htmlspecialchars() used when? strip_tags() used when? addslashes() used when? htmlspecialchars() used when? htmlspecialchars is roughly the same as htmlentities. The difference: character encodings. Both encode control characters like <, >, & and so on used for opening tags etc. htmlentities also encode … Read more

How to prevent Javascript injection attacks within user-generated HTML

You think that’s it? Check this out. Whatever approach you take, you definitely need to use a whitelist. It’s the only way to even come close to being safe about what you’re allowing on your site. EDIT: I’m not familiar with .NET, unfortunately, but you can check out stackoverflow’s own battle with XSS (https://blog.stackoverflow.com/2008/06/safe-html-and-xss/) and … Read more

Can parameterized statement stop all SQL injection?

When articles talk about parameterized queries stopping SQL attacks they don’t really explain why, it’s often a case of “It does, so don’t ask why” — possibly because they don’t know themselves. A sure sign of a bad educator is one that can’t admit they don’t know something. But I digress. When I say I … Read more

How does this site infecting script work?

Notice the replace call after the giant messy string: .replace(/#|\$|@|\^|&|\(|\)|\!/ig, ”). It removes most of the special characters, turning it into a normal URL: evil://dyndns-org.gamestop.com.mybestyouxi-cn.genuinehollywood.ru:8080/softonic.com/softonic.com/google.com/livejasmin.com/videosz.com/ (I manually changed http: to evil:) Note that the regex could have been simplified to .replace(/[#$@^&()!]/ig, ”) If you look at the script, you’ll see that it’s a very simple … Read more

Spring: How to inject a value to static field?

First of all, public static non-final fields are evil. Spring does not allow injecting to such fields for a reason. Your workaround is valid, you don’t even need getter/setter, private field is enough. On the other hand try this: @Value(“${my.name}”) public void setPrivateName(String privateName) { Sample.name = privateName; } (works with @Autowired/@Resource). But to give … Read more