|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS .NET Security
Top Three Security Mistakes .NET Developers Make
By: Caleb Sima
Digg This!
Industry analysts have estimated that over 70% of today's security breaches occur at the application level. Many are due to the exploitation of security defects within the code. Microsoft's renewed commitment to security has focused the development community on the need to develop secure Web applications. With this in mind, Microsoft has added a tremendous number of features to the .NET environment to aid developers in creating secure applications. For example, authentication has become an integrated part of the development environment and debug messages are now disabled by default. With these improvements, developers are now realizing the need to integrate security into their Web application development process. Web applications can take many forms - including an informal Web site, an online e-commerce application, an extranet, an intranet, an exchange, a search engine, or a transaction engine. Regardless of the type of Web application, it is critical that developers remember that a Web application includes not only the code that creates the Web site, but also the underlying components necessary to make the site available and useful to the public. Often these architectural components create an open door for attack that many developers do not consider until an attack occurs. By then, of course, it is too late. Attacks Focused on the Application Level Prevention of security attacks should start in the development stage of Web applications. .NET developers and programmers must realize that not only is it their responsibility to build workable, usable code, but also to develop attack-proof, secure code. In this article developers will learn common coding security mistakes and how to resolve them - ensuring the proper levels of security in their Web applications. Here are the top three security mistakes that developers make during Web application creation in the .NET environment. Mistake 1: SQL Injection For example, problems can arise when a developer does not protect against potentially malicious input such as a " ' ", which could close the SQL string and give the user unintended system and application access. An example of SQL injection would be for the user to enter the following string for the e-mail address and password: ' OR '1' = '1 The SQL statement passed to the database now reads like this: SELECT CustomerID FROM Customers WHERE EmailAddress = '' OR '1' = '1' Since the WHERE clause of the SQL statement will be satisfied by the always-true condition '1' = '1', the SQL statement will return the complete list of CustomerIDs in the database and the login will succeed. Here is another example of a more destructive SQL injection: Email: '; DELETE FROM Customers; -- The SQL now reads: SELECT CustomerID FROM Customers WHERE EmailAddress = ''; DELETE FROM The double-dash (--) sequence marks the beginning of a comment, and any text after that is ignored. So, this statement first executes a SELECT statement (which returns no rows) and then proceeds to delete every row in the Customers table. The following example function is a login that is vulnerable to SQL injection. By passing the login name and password directly into a SQL query, the attacker now has the ability to easily modify the SQL query itself. The result: the attacker can bypass the login and possibly execute commands on the system and grab all the other users' data. In order to eliminate this vulnerability, developers need to pass the name and password to the database in such a way that special characters aren't interpreted as part of the SQL command. The best way to do this is to avoid constructing ad hoc SQL statements, and instead pass the e-mail address and password as parameters to a stored procedure. This will have the added benefit of improved performance. If a stored procedure cannot be created on the database server, then a good second option is to declare the SQL statement as a parameterized query. For example: SELECT CustomerID FROM Customers WHERE EmailAddress = @EmailAddress The application will not have the performance benefit that comes from stored procedures, but it will be protected from SQL injection attacks. Listing 1 is an example of SQL injection. SQL code is accidentally passed into the application. Listing 2 shows how to use stored procedures to avoid building the SQL Query. The code sample is from the IBuySpy Store Sample (www.asp.net/ibuyspy/downloads.aspx?tabindex=5). Mistake 2: Cross-Site Scripting <script>alert('Vulnerable')</script> If, when the page posts back, you see a pop-up message box with the message "Vulnerable", then that page is vulnerable to cross-site scripting. An attacker who uses cross-site scripting might successfully compromise confidential information, manipulate or steal cookies, create requests that can be mistaken for those of a valid user, or execute malicious code on end-user systems. Cross-site scripting occurs on many search engine Web sites. It is simply a glaring hole that allows an attacker to embed HTML and JavaScript tags into his search in order to get the browser to execute it. Solving cross-site scripting attacks in .NET is simple. By passing all user input through the Server.HTMLEncode() function, the cross-site scripting hole is automatically fixed. Listing 3 is an example of cross-site scripting source code for a vulnerable Web site. Listing 4 shows how to prevent cross-site scripting by passing all user input through the Server.HTMLEncode() function. Mistake 3: Enabling Debug Options in the Web.Config File Attackers gain a tremendous amount of information from error messages. Enabling detailed error messages in an ASP.NET application is a major security concern. Table 1 shows the possible settings for <CustomErrors>. Always check your <CustomErrors> and ensure that the right level of information - remember, no detail - is returned to the user.
![]() Avoiding the Top Three Mistakes With a clear understanding of the risks and threats involved in Web application development, SPI Dynamics has created a powerful security tool for developers - WebInspect. WebInspect is a stand-alone software package that can analyze any Web application, identify potential security flaws, and supply the developer with the latest information necessary to resolve security issues before attackers are able to penetrate the system. To avoid the most common .NET security mistakes, remember: MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||