Webastor - Programming Tips and Tricks

Programming language => Sql => Topic started by: Steven on October 29, 2014, 06:21:02 PM

Title: What are the different ways to prevent SQL Injection?
Post by: Steven on October 29, 2014, 06:21:02 PM
Hi all, I would like to ask you if it is possible to know what are the different ways to prevent sql injection? Thank you please kindly help me !!! Cordially.
Title: Re: SQL Injection
Post by: Robin on October 30, 2017, 11:46:11 PM
1. Employ comprehensive data sanitization. Websites must filter all user input. Ideally, user data should be filtered for context. For example, email addresses should be filtered to allow only the characters allowed in an e-mail address, phone numbers should be filtered to allow only the characters allowed in a phone number, and so on.

2. Use a web application firewall. A popular example is the free, open source module ModSecurity which is available for Apache, Microsoft IIS, and nginx web servers. ModSecurity provides a sophisticated and ever-evolving set of rules to filter potentially dangerous web requests. Its SQL injection defenses can catch most attempts to sneak SQL through web channels.

3. Limit database privileges by context. Create multiple database user accounts with the minimum levels of privilege for their usage environment. For example, the code behind a login page should query the database using an account limited only to the relevent credentials table. This way, a breach through this channel cannot be leveraged to compromise the entire database.