<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pawel+Krawczyk</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pawel+Krawczyk"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Pawel_Krawczyk"/>
		<updated>2026-05-06T15:17:14Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:SameSite&amp;diff=240433</id>
		<title>Talk:SameSite</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:SameSite&amp;diff=240433"/>
				<updated>2018-05-05T15:42:12Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: re&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I know browsers have implemented the SameSite attribute, but the only IETF document that defines it is draft-ietf-httpbis-rfc6265bis-02, which is expired. RFC6265 does not include the SameSite attribute. Do browsers choose to implement draft specs on their own?&lt;br /&gt;
* It's been always the case - such minor security controls are frequently proposed and then implemented based on industry consensus, and after they're verified in the field, a RFC is created to standardize them retroactively. [[User:Pawel Krawczyk|Pawel Krawczyk]] ([[User talk:Pawel Krawczyk|talk]]) 10:42, 5 May 2018 (CDT)&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=230677</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=230677"/>
				<updated>2017-06-15T11:24:33Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Whitelisting vs blacklisting */ Validating free-form Unicode text=&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goals of Input Validation ==&lt;br /&gt;
Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components. Input validation should happen as early as possible in the data flow, preferably as soon as the data is received from the external party. &lt;br /&gt;
&lt;br /&gt;
Data from all potentially untrusted sources should be subject to input validation, including not only Internet-facing web clients but also backend feeds over extranets, from suppliers, partners, vendors or regulators[https://badcyber.com/several-polish-banks-hacked-information-stolen-by-unknown-attackers/], each of which may be compromised on their own and start sending malformed data.&lt;br /&gt;
&lt;br /&gt;
Input Validation should not be used as the ''primary'' method of preventing [[XSS (Cross Site Scripting) Prevention Cheat Sheet|XSS]], [[SQL Injection Prevention Cheat Sheet|SQL Injection]] and other attacks which are covered in respective [[OWASP Cheat Sheet Series|cheat sheets]] but can significantly contribute to reducing their impact if implemented properly.&lt;br /&gt;
&lt;br /&gt;
== Input validation strategies==&lt;br /&gt;
Input validation should be applied on both '''syntactical''' and '''semantic''' level. Syntactic validation should enforce correct syntax of structured fields (e.g. SSN, date, currency symbol) while semantic validation should enforce correctness of their ''values'' in the specific business context (e.g. start date is before end date, price is within expected range).&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. &lt;br /&gt;
&lt;br /&gt;
== Implementing input validation==&lt;br /&gt;
Input validation can be implemented using any programming technique that allows effective enforcement of syntactic and semantic correctness, for example:&lt;br /&gt;
&lt;br /&gt;
* Data type validators available natively in web application frameworks (such as [https://docs.djangoproject.com/en/1.11/ref/validators/ Django Validators], [https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/package-summary.html#doc.Usage.validator Apache Commons Validators] etc)&lt;br /&gt;
* Validation against [http://json-schema.org/ JSON Schema] and [https://www.w3.org/standards/techs/xmlschema#w3c_all XML Schema (XSD)] for input in these formats&lt;br /&gt;
* Type conversion (e.g. &amp;lt;code&amp;gt;Integer.parseInt()&amp;lt;/code&amp;gt; in Java, &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; in Python) with strict exception handling&lt;br /&gt;
* Minimum and maximum value range check for numerical parameters and dates, minimum and maximum length check for strings&lt;br /&gt;
* Array of allowed values for small sets of string parameters (e.g. days of week)&lt;br /&gt;
* Regular expressions for any other structured data covering the whole input string (^...$) and '''not''' using &amp;quot;any character&amp;quot; wildcard (such as &amp;quot;.&amp;quot; or &amp;quot;\S&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
=== Whitelisting vs blacklisting ===&lt;br /&gt;
It is a common mistake black list validation in order to try to detect possibly dangerous characters and patterns like the apostrophe &amp;lt;code&amp;gt;'&amp;lt;/code&amp;gt; character, the string &amp;lt;code&amp;gt;1=1&amp;lt;/code&amp;gt;, or the &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; tag, but this is a massively flawed approach as it is trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like &amp;lt;code&amp;gt;O'Brian&amp;lt;/code&amp;gt;, where the ' character is fully legitimate. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. &lt;br /&gt;
&lt;br /&gt;
===Validating free-form Unicode text===&lt;br /&gt;
Free-form text, especially with Unicode characters, is perceived as difficult to validate due to a relatively large space of characters that need to be whitelisted. It's also free-form text input that highlights the importance of proper context-aware output encoding and quite clearly demonstrates that input validation is '''not''' the primary safeguards against Cross-Site Scripting — if your users want to type apostrophe (') or less-than sign (&amp;amp;lt;) in their comment field, they might have perfectly legitimate reason for that and the application's job is to properly handle it throughout the whole life cycle of the data.&lt;br /&gt;
&lt;br /&gt;
The primary means of input validation for free-form text input should be:&lt;br /&gt;
&lt;br /&gt;
* normalization — ensure canonical encoding is used across all the text and no invalid characters are present &lt;br /&gt;
* character category whitelisting  — Unicode allows whitelisting categories such as &amp;quot;decimal digits&amp;quot; or &amp;quot;letters&amp;quot; which not only covers the Latin alphabet but also various other scripts used globally (e.g. Arabic, Cyryllic, CJK ideographs etc)&lt;br /&gt;
* individual character whitelisting — if you allow letters and ideographs in names and also want to allow apostrophe (') for Irish names, but don't want to allow the whole punctuation category&lt;br /&gt;
&lt;br /&gt;
References: [https://ipsec.pl/python/2017/input-validation-free-form-unicode-text-python.html Input validation of free-form Unicode text in Python]&lt;br /&gt;
&lt;br /&gt;
===Regular expressions===&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Cryptographic_Storage_Cheat_Sheet&amp;diff=229756</id>
		<title>Talk:Cryptographic Storage Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Cryptographic_Storage_Cheat_Sheet&amp;diff=229756"/>
				<updated>2017-05-17T12:25:17Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: 3DES&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I take issue with these two rules:&lt;br /&gt;
&lt;br /&gt;
 Rule - Build support for changing keys periodically&lt;br /&gt;
 Key rotation is a must as all good keys do come to an end either through expiration or revocation. So a developer will have to deal with rotating keys at some point -- better to have a system in place now rather than scrambling later. (From Bil Cory as a starting point).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is definitely a good thing for a system to have a built-in method for key rotation, when needed.  What I take issue with is framing this as a &amp;quot;periodic&amp;quot; necessity.  Changing out well-chosen encryption keys used for data storage on a periodic basis is almost certainly a waste of time and effort.  Yes, if a key is compromised for whatever reason then we need to change it quickly when we find out about that, but blindly doing it on a monthly, quarterly, or whatever basis still exposes the data to attack 50% of the time.  See more below.&lt;br /&gt;
&lt;br /&gt;
 Rule - Rekey data at least every one to three years[edit]&lt;br /&gt;
 Rekeying refers to the process of decrypting data and then re-encrypting it with a new key. Periodically rekeying data helps protect it from undetected compromises of older keys. The appropriate rekeying &lt;br /&gt;
 period depends on the security of the keys. Data protected by keys secured in dedicated hardware security modules might only need rekeying every three years. Data protected by keys that are split and stored on two application servers might need rekeying every year.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Suppose a breach happens on the 10th of the month, but you normally rotate keys on the 25th.  If you didn't find out about the breach until the 30th, then that is 15 days for the attacker to export the whole encrypted database and begin cracking it offline.  What's more, after you automatically rotate the encryption keys for data at rest, the attacker *still has the data encrypted with the old key*.  So they can just continue cracking offline.  What did periodic key rotation buy you?  The more you analyze this problem with a real threat model, the more you realize it buys you nothing.&lt;br /&gt;
&lt;br /&gt;
Yes, sysadmins do need a way to rotate keys quickly after they discover they were compromised.  But blindly rotating on a periodic basis just to make you feel better is a waste of time, when it comes to encryption of data at rest.  (Encryption in transit can be a different story.)  &amp;quot;But it doesn't hurt, right?&amp;quot;  Well, actually it does.  People could spend that effort on useful things, rather than on building and testing periodic key rotation systems.&lt;br /&gt;
&lt;br /&gt;
==3DES==&lt;br /&gt;
Should we still even mention 3DES?  [[User:Pawel Krawczyk|Pawel Krawczyk]] ([[User talk:Pawel Krawczyk|talk]]) 07:25, 17 May 2017 (CDT)&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Cryptographic_Storage_Cheat_Sheet&amp;diff=229753</id>
		<title>Cryptographic Storage Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Cryptographic_Storage_Cheat_Sheet&amp;diff=229753"/>
				<updated>2017-05-17T10:44:34Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Rule - Use strong random numbers */ what to use instead for C and Java&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article provides a simple model to follow when implementing solutions to protect data at rest.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Architectural Decision  ==&lt;br /&gt;
&lt;br /&gt;
An architectural decision must be made to determine the appropriate method to protect data at rest.  There are such wide varieties of products, methods and mechanisms for cryptographic storage. This cheat sheet will only focus on low-level guidelines for developers and architects who are implementing cryptographic solutions. We will not address specific vendor solutions, nor will we address the design of cryptographic algorithms.&lt;br /&gt;
&lt;br /&gt;
The general practices and required minimum key length depending on the scenario listed below.&lt;br /&gt;
&lt;br /&gt;
* Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
* Message Integrity: HMAC-SHA2&lt;br /&gt;
* Message Hash: SHA2 256 bits&lt;br /&gt;
* Assymetric encryption: RSA 2048 bits&lt;br /&gt;
* Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
* Password Hashing: PBKDF2, Scrypt, Bcrypt.&lt;br /&gt;
&lt;br /&gt;
= Providing Cryptographic Functionality  =&lt;br /&gt;
&lt;br /&gt;
== Secure Cryptographic Storage Design  ==&lt;br /&gt;
&lt;br /&gt;
* All protocols and algorithms for authentication and secure communication should be well vetted by the cryptographic community.&lt;br /&gt;
&lt;br /&gt;
* Ensure certificates are properly validated against the hostnames/users ie whom they are meant for.&lt;br /&gt;
&lt;br /&gt;
* Avoid using wildcard certificates unless there is a business need for it &lt;br /&gt;
&lt;br /&gt;
* Maintain a cryptographic standard to ensure that the developer community knows about the approved ciphersuits for network security protocols, algorithms, permitted use, cryptoperiods and Key Management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only store sensitive data that you need ===&lt;br /&gt;
&lt;br /&gt;
Many eCommerce businesses utilize third party payment providers to store credit card information for recurring billing. This offloads the burden of keeping credit card numbers safe.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use strong approved Authenticated Encryption  ===&lt;br /&gt;
E.g. [http://en.wikipedia.org/wiki/CCM_mode CCM] or [http://en.wikipedia.org/wiki/GCM_mode GCM] are approved [http://en.wikipedia.org/wiki/Authenticated_encryption Authenticated Encryption] modes based on [http://en.wikipedia.org/wiki/Advanced_Encryption_Standard AES] algorithm.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Use strong approved cryptographic algorithms ====&lt;br /&gt;
Do not implement an existing cryptographic algorithm on your own, no matter how easy it appears. Instead, use widely accepted algorithms and widely accepted implementations. &lt;br /&gt;
&lt;br /&gt;
Only use approved public algorithms such as AES, RSA public key cryptography, and SHA-256 or better for hashing. Do not use weak algorithms, such as MD5 or SHA1. Avoid hashing for password storage, instead use PBKDF2, bcrypt or scrypt. Note that the classification of a &amp;quot;strong&amp;quot; cryptographic algorithm can change over time. See [http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf NIST approved algorithms] or ISO TR 14742 “Recommendations on Cryptographic Algorithms and their use” or [http://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/algorithms-key-size-and-parameters-report-2014/at_download/fullReport Algorithms, key size and parameters report – 2014] from European Union Agency for Network and Information Security. &lt;br /&gt;
E.g. [http://en.wikipedia.org/wiki/Advanced_Encryption_Standard AES] 128, [http://en.wikipedia.org/wiki/RSA_(cryptosystem) RSA] 3072, [http://en.wikipedia.org/wiki/Secure_Hash_Algorithm SHA] 256. &lt;br /&gt;
&lt;br /&gt;
Ensure that the implementation has (at minimum) had some cryptography experts involved in its creation. If possible, use an implementation that is FIPS 140-2 certified. &lt;br /&gt;
&lt;br /&gt;
See [http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf NIST approved algorithms] Table 2 “Comparable strengths” for the strength (“security bits”) of different algorithms and key lengths, and how they compare to each other. &lt;br /&gt;
&lt;br /&gt;
* In general, where different algorithms are used, they should have comparable strengths e.g. if an AES-128 key is to be encrypted, an AES-128 key or greater, or RSA-3072 or greater could be used to encrypt it. &lt;br /&gt;
* In general, hash lengths are twice as long as the security bits offered by the symmetric/asymmetric algorithm&amp;amp;nbsp; e.g. SHA-224 for 3TDEA (112 security bits) (due to the [http://en.wikipedia.org/wiki/Birthday_attack Birthday Attack])&lt;br /&gt;
&lt;br /&gt;
If a password is being used to protect keys then the [http://en.wikipedia.org/wiki/Password_strength password strength]should be sufficient for the strength of the keys it is protecting.&lt;br /&gt;
&lt;br /&gt;
When 3DES is used, ensure K1 != K2 != K3, and the minimum key length must be 192 bit.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Use approved cryptographic modes  ====&lt;br /&gt;
In general, you should not use AES, DES or other symmetric cipher primitives directly. [http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html NIST approved modes] should be used instead. &lt;br /&gt;
&lt;br /&gt;
NOTE: Do not use [http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29 ECB mode] for encrypting lots of data (the other modes are better because they chain the blocks of data together to improve the data security).&lt;br /&gt;
&lt;br /&gt;
==== Rule - Use strong random numbers  ====&lt;br /&gt;
Ensure that all random numbers, especially those used for cryptographic parameters (keys, IV’s, MAC tags), random file names, random GUIDs, and random strings are generated in a cryptographically strong fashion. &lt;br /&gt;
&lt;br /&gt;
Ensure that random algorithms are seeded with sufficient entropy.&lt;br /&gt;
&lt;br /&gt;
Tools like [http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html NIST RNG Test tool] (as used in PCI PTS Derived Test Requirements) can be used to comprehensively assess the quality of a Random Number Generator by reading e.g. 128MB of data from the RNG source and then assessing its randomness properties with the tool.&lt;br /&gt;
&lt;br /&gt;
The following libraries are considered '''weak''' random numbers generators and should not be used.&lt;br /&gt;
&lt;br /&gt;
* C library: &amp;lt;code&amp;gt;random()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rand()&amp;lt;/code&amp;gt;  — use [http://man7.org/linux/man-pages/man2/getrandom.2.html getrandom(2)] instead&lt;br /&gt;
* Java library: &amp;lt;code&amp;gt;java.util.Random()&amp;lt;/code&amp;gt;  — use &amp;lt;code&amp;gt;java.security.SecureRandom&amp;lt;/code&amp;gt; instead&lt;br /&gt;
&lt;br /&gt;
For secure random number generation, refer to NIST SP 800-90A. CTR-DRBG、HASH-DRBG、HMAC-DRBG are recommended.&lt;br /&gt;
Refer to NIST SP800-22 A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications, and the testing toolkit.&lt;br /&gt;
&lt;br /&gt;
http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-22r1a.pdf&lt;br /&gt;
http://csrc.nist.gov/groups/ST/toolkit/rng/documents/sts-2.1.2.zip&lt;br /&gt;
&lt;br /&gt;
==== Rule - Use Authenticated Encryption of data ====&lt;br /&gt;
Use ([http://en.wikipedia.org/wiki/Authenticated_encryption AE]) modes under a uniform API. Recommended modes include [http://en.wikipedia.org/wiki/CCM_mode CCM], and [http://en.wikipedia.org/wiki/Galois/Counter_Mode GCM] as these, and only these as of November 2014, are specified in [http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html NIST approved modes], ISO IEC 19772 (2009) &amp;quot;Information technology — Security techniques — Authenticated encryption&amp;quot;, and [http://en.wikipedia.org/wiki/IEEE_P1619 IEEE P1619 Standard for Cryptographic Protection of Data on Block-Oriented Storage Devices] &lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Authenticated_encryption Authenticated Encryption] gives [http://en.wikipedia.org/wiki/Confidentiality confidentiality],&amp;amp;nbsp;[http://en.wikipedia.org/wiki/Data_integrity integrity], and&amp;amp;nbsp;[http://en.wikipedia.org/wiki/Authentication authenticity] (CIA); encryption alone just gives confidentiality. Encryption must always be combined with message integrity and authenticity protection. Otherwise the ciphertext may be vulnerable to manipulation causing changes to the underlying plaintext data, especially if it's being passed over untrusted channels (e.g. in an URL or cookie). &lt;br /&gt;
* These modes require only one key. In general, the tag sizes and the IV sizes should be set to maximum values.&lt;br /&gt;
&lt;br /&gt;
If these recommended [http://en.wikipedia.org/wiki/Authenticated_encryption AE] modes are not available&lt;br /&gt;
&lt;br /&gt;
* combine encryption in [http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29 cipher-block chaining (CBC) mode] with post-encryption message authentication code, such as [http://en.wikipedia.org/wiki/HMAC HMAC] or [http://en.wikipedia.org/wiki/CMAC CMAC] i.e. Encrypt-then-MAC. &lt;br /&gt;
** Note that Integrity and Authenticity are preferable to Integrity alone i.e. a MAC such as HMAC-SHA256 or HMAC-SHA512 is a better choice than SHA-256 or SHA-512.&lt;br /&gt;
* Use 2 independent keys for these 2 independent operations. &lt;br /&gt;
* Do not use ECB mode. CDC is preferred.&lt;br /&gt;
* Do not use [http://en.wikipedia.org/wiki/CBC-MAC#Security_with_fixed_and_variable-length_messages CBC MAC for variable length data] &lt;br /&gt;
* The [http://csrc.nist.gov/groups/STM/cavp/index.html CAVP program] is a good default place to go for validation of cryptographic algorithms when one does not have AES or one of the authenticated encryption modes that provide confidentiality and authenticity (i.e., data origin authentication) such as CCM, EAX, CMAC, etc. For Java, if you are using SunJCE that will be the case. The cipher modes supported in JDK 1.5 and later are CBC, CFB, CFBx, CTR, CTS, ECB, OFB, OFBx, PCBC. None of these cipher modes are authenticated encryption modes. (That's why it is added explicitly.) If you are using an alternate JCE provider such as Bouncy Castle, RSA JSafe, IAIK, etc., then these authenticated encryption modes should be used.&lt;br /&gt;
&lt;br /&gt;
Note: [http://en.wikipedia.org/wiki/Disk_encryption_theory Disk encryption]&amp;amp;nbsp;is a special case of&amp;amp;nbsp;[http://en.wikipedia.org/wiki/Data_at_Rest data at rest]&amp;amp;nbsp;e.g. Encrypted File System on a Hard Disk Drive. [http://csrc.nist.gov/publications/nistpubs/800-38E/nist-sp-800-38E.pdf XTS-AES mode] is optimized for Disk encryption and is one of the [http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html NIST approved modes]&amp;lt;nowiki&amp;gt;; it provides confidentiality and some protection against data manipulation (but not as strong as the &amp;lt;/nowiki&amp;gt;[http://en.wikipedia.org/wiki/Authenticated_encryption AE] [http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html NIST approved modes]). It is also specified in [http://en.wikipedia.org/wiki/IEEE_P1619 IEEE P1619 Standard for Cryptographic Protection of Data on Block-Oriented Storage Devices]&lt;br /&gt;
&lt;br /&gt;
=== Rule - Store a one-way and salted value of passwords ===&lt;br /&gt;
&lt;br /&gt;
Use PBKDF2, bcrypt or scrypt for password storage. For more information on password storage, please see the [[Password Storage Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
=== Rule - Ensure that the cryptographic protection remains secure even if access controls fail ===&lt;br /&gt;
&lt;br /&gt;
This rule supports the principle of defense in depth. Access controls (usernames, passwords, privileges, etc.) are one layer of protection. Storage encryption should add an additional layer of protection that will continue protecting the data even if an attacker subverts the database access control layer.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Ensure that any secret key is protected from unauthorized access ===&lt;br /&gt;
&lt;br /&gt;
==== Rule - Define a key lifecycle ====&lt;br /&gt;
&lt;br /&gt;
The key lifecycle details the various states that a key will move through during its life. The lifecycle will specify when a key should no longer be used for encryption, when a key should no longer be used for decryption (these are not necessarily coincident), whether data must be rekeyed when a new key is introduced, and when a key should be removed from use all together.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Store unencrypted keys away from the encrypted data ====&lt;br /&gt;
&lt;br /&gt;
If the keys are stored with the data then any compromise of the data will easily compromise the keys as well. Unencrypted keys should never reside on the same machine or cluster as the data.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Use independent keys when multiple keys are required ====&lt;br /&gt;
&lt;br /&gt;
Ensure that key material is independent. That is, do not choose a second key which is easily related to the first (or any preceeding) keys.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Protect keys in a key vault ====&lt;br /&gt;
&lt;br /&gt;
Keys should remain in a protected key vault at all times. In particular, ensure that there is a gap between the threat vectors that have direct access to the data and the threat vectors that have direct access to the keys. This implies that keys should not be stored on the application or web server (assuming that application attackers are part of the relevant threat model).&lt;br /&gt;
&lt;br /&gt;
==== Rule - Document concrete procedures for managing keys through the lifecycle ====&lt;br /&gt;
&lt;br /&gt;
These procedures must be written down and the key custodians must be adequately trained.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Build support for changing algorithms and keys when needed ====&lt;br /&gt;
&lt;br /&gt;
If keys are compromised or an external authority expires them, key changes will be needed.  Application polices or emergency needs will force application administrators to rotate keys and potentially rekey data at some point. It's best to be prepared to rapidly handle this need when necessary.  Including a key version and encryption algorithm version with the encrypted data is a useful, proactive feature.  For instance, including a simple prefix string, such as &amp;quot;&amp;lt;code&amp;gt;{1,1}...&amp;lt;/code&amp;gt;&amp;quot;, prior to the encrypted data could indicate algorithm version 1, key version 1.  This allows for an &amp;quot;online&amp;quot; change to the encryption algorithm and key without re-encrypting all existing data all at once.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Document concrete procedures to handle a key compromise ====&lt;br /&gt;
&lt;br /&gt;
Ensure operations staff have the information they need, readily available, when rotation of encryption keys must be performed.  Rotating keys should not require changes to source code or other risky deployment measures, since doing this in the middle of an incident will already place a great deal of stress on these staff.&lt;br /&gt;
&lt;br /&gt;
==== Rule - Limit quantity of data encrypted with one key ====&lt;br /&gt;
&lt;br /&gt;
If the amount of data encrypted grows beyond a '''certain threshold''', a new key should be used.  This '''certain threshold''' varies depending on the encryption algorithm used, but is typically 2&amp;lt;sup&amp;gt;35&amp;lt;/sup&amp;gt; bytes (~34 gigabytes) for 64 bit block ciphers (DES, 3DES, Blowfish, RC5, ...) and 2&amp;lt;sup&amp;gt;68&amp;lt;/sup&amp;gt; bytes (~ 295,147,905 terabytes) for 128 bit block ciphers (AES, TwoFish, Serpent).  If encrypting with a modern cipher, this threshold is unlikely to be reached, but it should be considered when evaluating algorithms and rotation procedures.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Follow applicable regulations on use of cryptography ===&lt;br /&gt;
&lt;br /&gt;
==== Rule - Under PCI DSS requirement 3, you must protect cardholder data  ====&lt;br /&gt;
&lt;br /&gt;
The Payment Card Industry (PCI) Data Security Standard (DSS) was developed to encourage and enhance cardholder data security and facilitate the broad adoption of consistent data security measures globally. The standard was introduced in 2005 and replaced individual compliance standards from Visa, Mastercard, Amex, JCB and Diners. The current version of the standard is 3.1 and was published in April, 2015. &lt;br /&gt;
&lt;br /&gt;
PCI DSS requirement 3 covers secure storage of credit card data. This requirement covers several aspects of secure storage including the data you must never store but we are covering Cryptographic Storage which is covered in requirements 3.4, 3.5 and 3.6 as you can see below: &lt;br /&gt;
&lt;br /&gt;
'''3.4 Render PAN (Primary Account Number), at minimum, unreadable anywhere it is stored''' &lt;br /&gt;
&lt;br /&gt;
Compliance with requirement 3.4 can be met by implementing any of the four types of secure storage described in the standard which includes encrypting and hashing data. These two approaches will often be the most popular choices from the list of options. The standard doesn't refer to any specific algorithms but it mandates the use of '''Strong Cryptography'''. The glossary document from the PCI council defines '''Strong Cryptography''' as: &lt;br /&gt;
&lt;br /&gt;
''Cryptography based on industry-tested and accepted algorithms, along with strong key lengths and proper key-management practices. Cryptography is a method to protect data and includes both encryption (which is reversible) and hashing (which is not reversible, or “one way”). SHA-1 is an example of an industry-tested and accepted hashing algorithm. Examples of industry-tested and accepted standards and algorithms for encryption include AES (128 bits and higher), TDES (minimum double-length keys), RSA (1024 bits and higher), ECC (160 bits and higher), and ElGamal (1024 bits and higher).'' &lt;br /&gt;
&lt;br /&gt;
If you have implemented the second rule in this cheat sheet you will have implemented a strong cryptographic algorithm which is compliant with or stronger than the requirements of PCI DSS requirement 3.4. You need to ensure that you identify all locations that card data could be stored including logs and apply the appropriate level of protection. This could range from encrypting the data to replacing the card number in logs. &lt;br /&gt;
&lt;br /&gt;
This requirement can also be met by implementing disk encryption rather than file or column level encryption. The requirements for '''Strong Cryptography''' are the same for disk encryption and backup media. The card data should never be stored in the clear and by following the guidance in this cheat sheet you will be able to securely store your data in a manner which is compliant with PCI DSS requirement 3.4 &lt;br /&gt;
&lt;br /&gt;
'''3.5  Protect any keys used to secure cardholder data against disclosure and misuse''' &lt;br /&gt;
&lt;br /&gt;
As the requirement name above indicates, we are required to securely store the encryption keys themselves. This will mean implementing strong access control, auditing and logging for your keys. The keys must be stored in a location which is both secure and &amp;quot;away&amp;quot; from the encrypted data. This means key data shouldn't be stored on web servers, database servers etc &lt;br /&gt;
&lt;br /&gt;
Access to the keys must be restricted to the smallest amount of users possible. This group of users will ideally be users who are highly trusted and trained to perform Key Custodian duties. There will obviously be a requirement for system/service accounts to access the key data to perform encryption/decryption of data. &lt;br /&gt;
&lt;br /&gt;
The keys themselves shouldn't be stored in the clear but encrypted with a KEK (Key Encrypting Key). The KEK must not be stored in the same location as the encryption keys it is encrypting. &lt;br /&gt;
&lt;br /&gt;
'''3.6 Fully document and implement all key-management processes and procedures for cryptographic keys used for encryption of cardholder data''' &lt;br /&gt;
&lt;br /&gt;
Requirement 3.6 mandates that key management processes within a PCI compliant company cover 8 specific key lifecycle steps: &lt;br /&gt;
&lt;br /&gt;
'''3.6.1 Generation of strong cryptographic keys''' &lt;br /&gt;
&lt;br /&gt;
As we have previously described in this cheat sheet we need to use algorithms which offer high levels of data security. We must also generate strong keys so that the security of the data isn't undermined by weak cryptographic keys. A strong key is generated by using a key length which is sufficient for your data security requirements and compliant with the PCI DSS. The key size alone isn't a measure of the strength of a key. The data used to generate the key must be sufficiently random (&amp;quot;sufficient&amp;quot; often being determined by your data security requirements) and the entropy of the key data itself must be high.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''3.6.2 Secure cryptographic key distribution''' &lt;br /&gt;
&lt;br /&gt;
The method used to distribute keys must be secure to prevent the theft of keys in transit. The use of a protocol such as Diffie Hellman can help secure the distribution of keys, the use of secure transport such as TLS and SSHv2 can also secure the keys in transit. Older protocols like SSLv3 should not be used.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''3.6.3 Secure cryptographic key storage'''&lt;br /&gt;
&lt;br /&gt;
The secure storage of encryption keys including KEK's has been touched on in our description of requirement 3.5 (see above).&lt;br /&gt;
&lt;br /&gt;
'''3.6.4 Periodic cryptographic key changes'''&lt;br /&gt;
&lt;br /&gt;
The PCI DSS standard mandates that keys used for encryption must be rotated at least annually. The key rotation process must remove an old key from the encryption/decryption process and replace it with a new key. All new data entering the system must encrypted with the new key. While it is recommended that existing data be rekeyed with the new key, as per the Rekey data at least every one to three years rule above, it is not clear that the PCI DSS requires this.&lt;br /&gt;
&lt;br /&gt;
'''3.6.5 Retirement or replacement of keys as deemed necessary when the integrity of the key has been weakened or keys are suspected of being compromised'''&lt;br /&gt;
&lt;br /&gt;
The key management processes must cater for archived, retired or compromised keys. The process of securely storing and replacing these keys will more than likely be covered by your processes for requirements 3.6.2, 3.6.3 and 3.6.4&lt;br /&gt;
&lt;br /&gt;
'''3.6.6 Split knowledge and establishment of dual control of cryptographic keys'''&lt;br /&gt;
&lt;br /&gt;
The requirement for split knowledge and/or dual control for key management prevents an individual user performing key management tasks such as key rotation or deletion. The system should require two individual users to perform an action (i.e. entering a value from their own OTP) which creates to separate values which are concatenated to create the final key data.&lt;br /&gt;
&lt;br /&gt;
'''3.6.7 Prevention of unauthorized substitution of cryptographic keys'''&lt;br /&gt;
&lt;br /&gt;
The system put in place to comply with requirement 3.6.6 can go a long way to preventing unauthorised substitution of key data. In addition to the dual control process you should implement strong access control, auditing and logging for key data so that unauthorised access attempts are prevented and logged.&lt;br /&gt;
&lt;br /&gt;
'''3.6.8 Requirement for cryptographic key custodians to sign a form stating that they understand and accept their key-custodian responsibilities '''&lt;br /&gt;
&lt;br /&gt;
To perform the strong key management functions we have seen in requirement 3.6 we must have highly trusted and trained key custodians who understand how to perform key management duties. The key custodians must also sign a form stating they understand the responsibilities that come with this role.&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
OWASP - [[Testing for SSL-TLS (OWASP-CM-001)|Testing for SSL-TLS]], and OWASP [[Guide to Cryptography]] &lt;br /&gt;
&lt;br /&gt;
OWASP – [http://www.owasp.org/index.php/ASVS Application Security Verification Standard (ASVS) – Communication Security Verification Requirements (V10)]&lt;br /&gt;
ssllabs Wiki - https://github.com/ssllabs/research/wiki&lt;br /&gt;
&lt;br /&gt;
OWASP - https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Kevin Kenan - kevin[at]k2dd.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Rook - david.a.rook[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Kevin Wall - kevin.w.wall[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Fred Donovan - fred.donovan(at)owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=229751</id>
		<title>SAML Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=229751"/>
				<updated>2017-05-17T09:51:02Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Input Validation */ strong encryption&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;i&amp;gt;Security Assertion Markup Language&amp;lt;/i&amp;gt; (SAML) is an open standard for exchanging authorization and authentication information. The &amp;lt;i&amp;gt;Web Browser SAML/SSO Profile with Redirect/POST bindings&amp;lt;/i&amp;gt; is one of the most common SSO implementation. This cheatsheet will focus primarily on that profile.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Validate Message Confidentiality and Integrity =&lt;br /&gt;
&lt;br /&gt;
* [[Transport Layer Protection Cheat Sheet|TLS 1.2]] is the most common solution to guarantee message confidentiality and integrity. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
** Eavesdropping 7.1.1.1&lt;br /&gt;
** Theft of User Authentication Information 7.1.1.2&lt;br /&gt;
** Theft of the Bearer Token 7.1.1.3&lt;br /&gt;
** Message Deletion 7.1.1.6&lt;br /&gt;
** Message Modification 7.1.1.7&lt;br /&gt;
** Man-in-the-middle 7.1.1.8&lt;br /&gt;
*A digitally signed message with a certified key is the most common solution to guarantee message integrity and authentication. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
**Man-in-the-middle 6.4.2&lt;br /&gt;
**Forged Assertion 6.4.3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Usage=&lt;br /&gt;
&lt;br /&gt;
This is a common area for security gaps - see [http://www.ai-lab.it/armando/pub/fmse9-armando.pdf Google SSO vulnerability] (AVANTSSAR 2008)  for a real life example.  Their SSO profile was vulnerable to a Man-in-the-middle attack from a malicious SP (Service Provider). The SSO Web Browser Profile is most susceptible to attacks from trusted partners. This particular security flaw was exposed because the SAML Response did not contain all of the required data elements necessary for a secure message exchange. Following the [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profile] usage requirements for AuthnRequest (4.1.4.1) and Response (4.1.4.2) will help counter this attack. The AVANTSSAR team suggested the following data elements should be required:&lt;br /&gt;
&lt;br /&gt;
* '''AuthnRequest(ID, SP);''' An AuthnRequest must contain and ID and SP. Where ID is a string uniquely identifying the request and an SP identifies the Service Provider that initiated the request. Furthermore, the request ID attribute must be returned in the response (InResponseTo=&amp;quot;&amp;lt;requestId&amp;gt;&amp;quot;). InResponseTo helps guarantee authenticity of the response from the trusted IdP. This was one of the missing attributes that left Google's SSO vulnerable.&lt;br /&gt;
* '''Response(ID, SP, IdP, {AA} K -1/IdP);''' A Response must contain all these elements. Where ID is a string uniquely identifying the response. SP identifies the recipient of the response. IdP identifies the identity provider authorizing the response. {AA} K -1/IdP is the assertion digitally signed with the private key of the IdP.&lt;br /&gt;
* '''AuthAssert(ID, C, IdP, SP);''' An authentication assertion must exist within the Response. It must contain an ID, a client (C), an identity provider (IdP), and a service provider (SP) identifier.&lt;br /&gt;
&lt;br /&gt;
Further vulnerabilities in SAML implementations were described in 2012 ([https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91-8-23-12.pdf On Breaking SAML: Be Whoever You Want to Be]). The following recommendations were proposed in response ([http://arxiv.org/pdf/1401.7483v1.pdf Secure SAML validation to prevent XML signature wrapping attacks]):&lt;br /&gt;
&lt;br /&gt;
* Always perform schema validation on the XML document prior to using it for any security-­related purposes.&lt;br /&gt;
** Always use local, trusted copies of schemas for validation.&lt;br /&gt;
** Never allow automatic download of schemas from third party locations.&lt;br /&gt;
** If possible, inspect schemas and perform schema hardening, to disable possible wildcard ­type or relaxed processing statements.&lt;br /&gt;
* Securely validate the digital signature.&lt;br /&gt;
** If you expect only one signing key, use StaticKeySelector. Obtain the key directly from the identity provider, store it in local file and ignore any KeyInfo elements in the document.&lt;br /&gt;
** If you expect more than one signing key, use X509KeySelector (the JKS variant). Obtain these keys directly form the identity providers, store them in local JKS and ignore any KeyInfo elements in the document.&lt;br /&gt;
** If you expect a heterogenous signed documents (many certificates from many identity providers, multi­level validation paths), implement full trust establishment model based on PKIX and trusted root certificates.&lt;br /&gt;
* Avoid signature-wrapping attacks.&lt;br /&gt;
** Never use getElementsByTagName to select security related elements in an XML document without prior validation.&lt;br /&gt;
**Always use absolute XPath expressions to select elements, unless a hardened schema is used for validation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Processing Rules=&lt;br /&gt;
&lt;br /&gt;
This is another common area for security gaps simply because of the vast number of steps to assert. Processing a SAML response is an expensive operation but all steps must be validated.&lt;br /&gt;
*Validate AuthnRequest processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf SAML Core] (3.4.1.4) for all AuthnRequest processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
* Validate Response processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profiles] (4.1.4.3) for all Response processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Stolen Assertion (6.4.1)&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
** Forged Assertion (6.4.3)&lt;br /&gt;
** Browser State Exposure (6.4.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Validate Binding Implementation=&lt;br /&gt;
&lt;br /&gt;
*For an HTTP Redirect Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.4). To view an encoding example, you may want to reference RequestUtil.java found within [https://developers.google.com/google-apps/sso/saml_reference_implementation_web Google's reference implementation].&lt;br /&gt;
* For an HTTP POST Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.5). The caching considerations are also very important. If a SAML protocol message gets cached, it can subsequently be used as a Stolen Assertion (6.4.1) or Replay (6.4.5) attack.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Validate Security Countermeasures=&lt;br /&gt;
&lt;br /&gt;
Revisit each security threat that exists within the [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security] document and assert you have applied the appropriate countermeasures for threats that may exist for your particular implementation. Additional countermeasures considererd should include:&lt;br /&gt;
*Prefer IP Filtering when appropriate. For example, this countermeasure could have prevented Google's initial security flaw if Google provided each trusted partner with a separate endpoint and setup an IP filter for each endpoint. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Man-in-the-middle (6.4.2)&lt;br /&gt;
*Prefer short lifetimes on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
*Prefer OneTimeUse on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
**Replay (6.4.5)&lt;br /&gt;
&lt;br /&gt;
Need an architectural diagram? The [http://www.oasis-open.org/committees/download.php/11511/sstc-saml-tech-overview-2.0-draft-03.pdf SAML technical overview] contains the most complete diagrams. For the Web Browser SSO Profile with Redirect/POST bindings refer to the section 4.1.3. In fact, of all the SAML documentation, the technical overview is the most valuable from a high-level perspective.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= First and Last Mile Considerations = &lt;br /&gt;
&lt;br /&gt;
The SAML protocol is rarely the vector of choice, though it's important to have cheatsheets to make sure that this is robust. The various endpoints are more targeted, so how the SAML token is generated and how it is consumed are both important in practice. &lt;br /&gt;
&lt;br /&gt;
== First Mile Considerations ==&lt;br /&gt;
* Validate X.509 Certificate for algorithm compatibility, strength of encryption, export restrictions&lt;br /&gt;
* Validate Strong Authentication options for generating the SAML token&lt;br /&gt;
* IDP validation (which IDP mints the token)&lt;br /&gt;
* Use/Trust Root CAs whenever possible&lt;br /&gt;
* Synchronize to a common Internet timesource&lt;br /&gt;
* Define levels of assurance for identity verification&lt;br /&gt;
* Prefer asymmetric identifiers for identity assertions over personally identifiable information (e.g. SSNs, etc)&lt;br /&gt;
* Sign assertions whenever possible&lt;br /&gt;
&lt;br /&gt;
== Last Mile Considerations ==&lt;br /&gt;
* Validating session state for user&lt;br /&gt;
* Level of granularity in setting authZ context when consuming SAML token (do you use groups, roles, attributes)&lt;br /&gt;
* Validate authorized IDP&lt;br /&gt;
* Validate IDP certificates for expiry against CRL/OCSP&lt;br /&gt;
* Validate NotBefore and NotOnorAfter&lt;br /&gt;
* Define criteria for SAML logout&lt;br /&gt;
* Exchange assertions only over secure transports&lt;br /&gt;
* Define criteria for session management&lt;br /&gt;
* Validate signature whenever possible&lt;br /&gt;
* Verify user identities obtained from SAML ticket assertions whenever possible.&lt;br /&gt;
&lt;br /&gt;
= Input Validation =&lt;br /&gt;
 &lt;br /&gt;
Just because SAML is a security protocol does not mean that input validation goes away. &lt;br /&gt;
&lt;br /&gt;
* Ensure that all SAML providers/consumers do proper [[Input_Validation_Cheat_Sheet | input validation]].&lt;br /&gt;
&lt;br /&gt;
= Cryptography =&lt;br /&gt;
Solutions relying cryptographic algorithms need to follow the latest developments in cryptoanalysis.&lt;br /&gt;
&lt;br /&gt;
* Ensure all SAML elements in the chain use [[Cryptographic_Storage_Cheat_Sheet#Rule_-_Use_strong_approved_Authenticated_Encryption|strong encryption]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* [http://bradbroulik.blogspot.dk/2010/01/bulletproof-sso-with-saml-20.html Brad Broulik]&lt;br /&gt;
* [https://ipsec.pl/ Paweł Krawczyk]&lt;br /&gt;
* Gunnar Peterson&lt;br /&gt;
* James McGovern&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229696</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229696"/>
				<updated>2017-05-16T12:35:09Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: restructure a bit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goals of Input Validation ==&lt;br /&gt;
Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components. Input validation should happen as early as possible in the data flow, preferably as soon as the data is received from the external party. &lt;br /&gt;
&lt;br /&gt;
Data from all potentially untrusted sources should be subject to input validation, including not only Internet-facing web clients but also backend feeds over extranets, from suppliers, partners, vendors or regulators[https://badcyber.com/several-polish-banks-hacked-information-stolen-by-unknown-attackers/], each of which may be compromised on their own and start sending malformed data.&lt;br /&gt;
&lt;br /&gt;
Input Validation should not be used as the ''primary'' method of preventing [[XSS (Cross Site Scripting) Prevention Cheat Sheet|XSS]], [[SQL Injection Prevention Cheat Sheet|SQL Injection]] and other attacks which are covered in respective [[OWASP Cheat Sheet Series|cheat sheets]] but can significantly contribute to reducing their impact if implemented properly.&lt;br /&gt;
&lt;br /&gt;
== Input validation strategies==&lt;br /&gt;
Input validation should be applied on both '''syntactical''' and '''semantic''' level. Syntactic validation should enforce correct syntax of structured fields (e.g. SSN, date, currency symbol) while semantic validation should enforce correctness of their ''values'' in the specific business context (e.g. start date is before end date, price is within expected range).&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. &lt;br /&gt;
&lt;br /&gt;
== Implementing input validation==&lt;br /&gt;
Input validation can be implemented using any programming technique that allows effective enforcement of syntactic and semantic correctness, for example:&lt;br /&gt;
&lt;br /&gt;
* Data type validators available natively in web application frameworks (such as [https://docs.djangoproject.com/en/1.11/ref/validators/ Django Validators], [https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/package-summary.html#doc.Usage.validator Apache Commons Validators] etc)&lt;br /&gt;
* Validation against [http://json-schema.org/ JSON Schema] and [https://www.w3.org/standards/techs/xmlschema#w3c_all XML Schema (XSD)] for input in these formats&lt;br /&gt;
* Type conversion (e.g. &amp;lt;code&amp;gt;Integer.parseInt()&amp;lt;/code&amp;gt; in Java, &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; in Python) with strict exception handling&lt;br /&gt;
* Minimum and maximum value range check for numerical parameters and dates, minimum and maximum length check for strings&lt;br /&gt;
* Array of allowed values for small sets of string parameters (e.g. days of week)&lt;br /&gt;
* Regular expressions for any other structured data covering the whole input string (^...$) and '''not''' using &amp;quot;any character&amp;quot; wildcard (such as &amp;quot;.&amp;quot; or &amp;quot;\S&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
=== Whitelisting vs blacklisting ===&lt;br /&gt;
It is a common mistake black list validation in order to try to detect possibly dangerous characters and patterns like the apostrophe &amp;lt;code&amp;gt;'&amp;lt;/code&amp;gt; character, the string &amp;lt;code&amp;gt;1=1&amp;lt;/code&amp;gt;, or the &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; tag, but this is a massively flawed approach as it is trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like &amp;lt;code&amp;gt;O'Brian&amp;lt;/code&amp;gt;, where the ' character is fully legitimate. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. &lt;br /&gt;
&lt;br /&gt;
The most difficult fields to validate are so called 'free text' fields, like blog entries. However, even those types of fields can be validated to some degree. For example, you can at least exclude all non-printable characters (except acceptable white space, e.g., CR, LF, tab, space), and define a maximum length for the input field.&lt;br /&gt;
&lt;br /&gt;
===Regular expressions===&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229692</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229692"/>
				<updated>2017-05-16T10:19:47Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: Implementing input validation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goals of Input Validation ==&lt;br /&gt;
Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components.&lt;br /&gt;
&lt;br /&gt;
Input Validation is not the ''primary'' method of preventing [[XSS (Cross Site Scripting) Prevention Cheat Sheet|XSS]], [[SQL Injection Prevention Cheat Sheet|SQL Injection]] and other attacks which are covered in respective [[OWASP Cheat Sheet Series|cheat sheets]] but can significantly contribute to reducing their impact if implemented properly.&lt;br /&gt;
&lt;br /&gt;
== Input validation strategies==&lt;br /&gt;
Input validation should be applied on both '''syntactical''' and '''semantic''' level. Syntactic validation should enforce correct syntax of structured fields (e.g. SSN, date, currency symbol) while semantic validation should enforce correctness of their ''values'' in the specific business context (e.g. start date is before end date, price is within expected range).&lt;br /&gt;
&lt;br /&gt;
== Implementing input validation==&lt;br /&gt;
Input validation can be implemented using any programming technique that allows effective enforcement of syntactic and semantic correctness, for example:&lt;br /&gt;
&lt;br /&gt;
* Data type validators available natively in web application frameworks (such as [https://docs.djangoproject.com/en/1.11/ref/validators/ Django Validators], [https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/package-summary.html#doc.Usage.validator Apache Commons Validators] etc)&lt;br /&gt;
* Validation against [http://json-schema.org/ JSON Schema] and [https://www.w3.org/standards/techs/xmlschema#w3c_all XML Schema (XSD)] for input in these formats&lt;br /&gt;
* Type conversion (e.g. &amp;lt;code&amp;gt;Integer.parseInt()&amp;lt;/code&amp;gt; in Java, &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; in Python) with strict exception handling&lt;br /&gt;
* Minimum and maximum value range check for numerical parameters and dates, minimum and maximum length check for strings&lt;br /&gt;
* Array of allowed values for small sets of string parameters (e.g. days of week)&lt;br /&gt;
* Regular expressions for any other structured data covering the whole input string (^...$) and '''not''' using &amp;quot;any character&amp;quot; wildcard (such as &amp;quot;.&amp;quot; or &amp;quot;\S&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. Developers frequently perform black list validation in order to try to detect attack characters and patterns like the ' character, the string 1=1, or the &amp;amp;lt;script&amp;amp;gt; tag, but this is a massively flawed approach as it is typically trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like O'Brian, when the ' character is being filtered out. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. The most difficult fields to validate are so called 'free text' fields, like blog entries. However, even those types of fields can be validated to some degree. For example, you can at least exclude all non-printable characters (except acceptable white space, e.g., CR, LF, tab, space), and define a maximum length for the input field.&lt;br /&gt;
&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229628</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229628"/>
				<updated>2017-05-15T13:17:02Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Goal of Input Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goal of Input Validation ==&lt;br /&gt;
Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components.&lt;br /&gt;
&lt;br /&gt;
Input Validation is not the ''primary'' method of preventing [[XSS (Cross Site Scripting) Prevention Cheat Sheet|XSS]], [[SQL Injection Prevention Cheat Sheet|SQL Injection]] and other attacks which are covered in respective [[OWASP Cheat Sheet Series|cheat sheets]] but can significantly contribute to reducing their impact if implemented properly.&lt;br /&gt;
&lt;br /&gt;
== White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. Developers frequently perform black list validation in order to try to detect attack characters and patterns like the ' character, the string 1=1, or the &amp;amp;lt;script&amp;amp;gt; tag, but this is a massively flawed approach as it is typically trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like O'Brian, when the ' character is being filtered out. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. The most difficult fields to validate are so called 'free text' fields, like blog entries. However, even those types of fields can be validated to some degree. For example, you can at least exclude all non-printable characters (except acceptable white space, e.g., CR, LF, tab, space), and define a maximum length for the input field.&lt;br /&gt;
&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229627</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229627"/>
				<updated>2017-05-15T13:13:49Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Goal of Input Validation */ update, internal links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goal of Input Validation ==&lt;br /&gt;
Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components.&lt;br /&gt;
&lt;br /&gt;
Input Validation is not the *primary* method of preventing [[XSS (Cross Site Scripting) Prevention Cheat Sheet|XSS]], [[SQL Injection Prevention Cheat Sheet|SQL Injection]] and other attacks which are covered in respective [[OWASP Cheat Sheet Series|cheat sheets]] but can significantly contribute to reducing their impact if implemented properly.&lt;br /&gt;
&lt;br /&gt;
== White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. Developers frequently perform black list validation in order to try to detect attack characters and patterns like the ' character, the string 1=1, or the &amp;amp;lt;script&amp;amp;gt; tag, but this is a massively flawed approach as it is typically trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like O'Brian, when the ' character is being filtered out. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. The most difficult fields to validate are so called 'free text' fields, like blog entries. However, even those types of fields can be validated to some degree. For example, you can at least exclude all non-printable characters (except acceptable white space, e.g., CR, LF, tab, space), and define a maximum length for the input field.&lt;br /&gt;
&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229626</id>
		<title>Input Validation Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Input_Validation_Cheat_Sheet&amp;diff=229626"/>
				<updated>2017-05-15T12:54:09Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* White List Regular Expression Examples */ US zip code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for providing Input Validation security functionality in your applications. &lt;br /&gt;
&lt;br /&gt;
== Goal of Input Validation ==&lt;br /&gt;
Input validation is performed to minimize malformed data from entering the system. Input Validation is NOT the primary method of preventing XSS, SQL Injection. These are covered in output encoding and related cheat sheets.&lt;br /&gt;
&lt;br /&gt;
== White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
It is always recommended to prevent attacks as early as possible in the processing of the user’s (attacker's) request. Input validation can be used to detect unauthorized input before it is processed by the application. Developers frequently perform black list validation in order to try to detect attack characters and patterns like the ' character, the string 1=1, or the &amp;amp;lt;script&amp;amp;gt; tag, but this is a massively flawed approach as it is typically trivial for an attacker to avoid getting caught by such filters. Plus, such filters frequently prevent authorized input, like O'Brian, when the ' character is being filtered out. For more information on XSS filter evasion please see the [[XSS Filter Evasion Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
White list validation is appropriate for all input fields provided by the user. White list validation involves defining exactly what IS authorized, and by definition, everything else is not authorized. If it's well structured data, like dates, social security numbers, zip codes, e-mail addresses, etc. then the developer should be able to define a very strong validation pattern, usually based on regular expressions, for validating such input. If the input field comes from a fixed set of options, like a drop down list or radio buttons, then the input needs to match exactly one of the values offered to the user in the first place. The most difficult fields to validate are so called 'free text' fields, like blog entries. However, even those types of fields can be validated to some degree. For example, you can at least exclude all non-printable characters (except acceptable white space, e.g., CR, LF, tab, space), and define a maximum length for the input field.&lt;br /&gt;
&lt;br /&gt;
Developing regular expressions can be complicated, and is well beyond the scope of this cheat sheet. There are lots of resources on the internet about how to write regular expressions, including: http://www.regular-expressions.info/ and the [[OWASP Validation Regex Repository]]. &lt;br /&gt;
&lt;br /&gt;
In summary, input validation should:&lt;br /&gt;
* Be applied to all input data, at minimum&lt;br /&gt;
* Define the allowed set of characters to be accepted&lt;br /&gt;
* Defines a minimum and maximum length for the data (e.g. {1,25} )&lt;br /&gt;
&lt;br /&gt;
== White List Regular Expression Examples ==&lt;br /&gt;
&lt;br /&gt;
Validating an U.S. Zip Code (5 digits plus optional -4) &lt;br /&gt;
 ^\d{5}(-\d{4})?$&lt;br /&gt;
&lt;br /&gt;
Validating U.S. State Selection From a Drop-Down Menu&lt;br /&gt;
 ^(AA|AE|AP|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|&lt;br /&gt;
 HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE| &lt;br /&gt;
 NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|&lt;br /&gt;
 TX|UT|VT|VI|VA|WA|WV|WI|WY)$&lt;br /&gt;
&lt;br /&gt;
'''Java Regex Usage Example'''&lt;br /&gt;
&lt;br /&gt;
  Example validating the parameter “zip” using a regular expression.&lt;br /&gt;
  &lt;br /&gt;
  private static final Pattern zipPattern = Pattern.compile(&amp;quot;^\d{5}(-\d{4})?$&amp;quot;);&lt;br /&gt;
  public void doPost( HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;
  	try {&lt;br /&gt;
  		String zipCode = request.getParameter( &amp;quot;zip&amp;quot; );&lt;br /&gt;
  		if ( !zipPattern.matcher( zipCode ).matches()  {&lt;br /&gt;
  			throw new YourValidationException( &amp;quot;Improper zipcode format.&amp;quot; );&lt;br /&gt;
  		}&lt;br /&gt;
  		.. do what you want here, after its been validated ..&lt;br /&gt;
  	} catch(YourValidationException e ) {&lt;br /&gt;
  		response.sendError( response.SC_BAD_REQUEST, e.getMessage() );&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Some white list validators have also been predefined in various open source packages that you can leverage. For example:&lt;br /&gt;
* [http://jakarta.apache.org/commons/validator Apache Commons Validator]&lt;br /&gt;
&lt;br /&gt;
== Client Side vs Server Side Validation ==&lt;br /&gt;
Be aware that any JavaScript input validation performed on the client can be bypassed by an attacker that disables JavaScript or uses a Web Proxy. Ensure that any input validation performed on the client is also performed on the server.&lt;br /&gt;
&lt;br /&gt;
== Validating Rich User Content ==&lt;br /&gt;
It is very difficult to validate rich content submitted by a user. For more information, please see the cheatsheet on [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Sanitize_HTML_Markup_with_a_Library_Designed_for_the_Job Sanitizing HTML Markup with a Library Designed for the Job].&lt;br /&gt;
&lt;br /&gt;
== Preventing XSS and Content Security Policy ==&lt;br /&gt;
* All user data controlled must be encoded when returned in the html page to prevent the execution of malicious data (e.g. XSS). For example &amp;amp;lt;script&amp;amp;gt; would be returned as &amp;amp;amp;lt;script&amp;amp;amp;gt;&lt;br /&gt;
* The type of encoding is specific to the context of the page where the user controlled data is inserted. For example, HTML entity encoding is appropriate for data placed into the HTML body. However, user data placed into a script would need JavaScript specific output encoding. &lt;br /&gt;
&lt;br /&gt;
Detailed information on XSS prevention here: [http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet OWASP XSS Prevention Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
= File Upload Validation = &lt;br /&gt;
&lt;br /&gt;
Many websites allow users to upload files, such as a profile picture or more. This section helps provide that feature securely.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
&lt;br /&gt;
* Use input validation to ensure the uploaded filename uses an expected extension type &lt;br /&gt;
* Ensure the uploaded file is not larger than a defined maximum file size&lt;br /&gt;
* If the website supports ZIP file upload, do validation check before unzip the file. The check includes the target path, level of compress, estimated unzip size. &lt;br /&gt;
&lt;br /&gt;
==Upload Storage==&lt;br /&gt;
&lt;br /&gt;
* Use a new filename to store the file on the OS. Do not use any user controlled text for this filename or for the temporary filename. &lt;br /&gt;
* When the file is uploaded to web, it's suggested to rename the file on storage. For example, the uploaded filename is test.JPG, rename it to JAI1287uaisdjhf.JPG with a random file name. The purpose of doing it to prevent the risks of direct file access and ambigious filename to evalide the filter, such as test.jpg;.asp or /../../../../../test.jpg.&lt;br /&gt;
* Uploaded files should be analyzed for malicious content (anti-malware, static analysis, etc)&lt;br /&gt;
* The file path should not be able to specify by client side. It's decided by server side.&lt;br /&gt;
&lt;br /&gt;
==Public Serving of Uploaded Content==&lt;br /&gt;
*Ensure uploaded images are served with the correct content-type (e.g. image/jpeg, application/x-xpinstall)&lt;br /&gt;
&lt;br /&gt;
==Beware of &amp;quot;special&amp;quot; files==&lt;br /&gt;
* The upload feature should be using a whitelist approach to only allow specific file types and extensions. However, it is important to be aware of the following file types that, if allowed, could result in security vulnerabilities.&lt;br /&gt;
*&amp;quot;crossdomain.xml&amp;quot; allows cross-domain data loading in Flash, Java and Silverlight.  If permitted on sites with authentication this can permit cross-domain data theft and CSRF attacks.  Note this can get pretty complicated depending on the specific plugin version in question, so its best to just prohibit files named &amp;quot;crossdomain.xml&amp;quot; or &amp;quot;clientaccesspolicy.xml&amp;quot;.&lt;br /&gt;
*&amp;quot;.htaccess&amp;quot; and &amp;quot;.htpasswd&amp;quot; provides server configuration options on a per-directory basis, and should not be permitted.  See http://en.wikipedia.org/wiki/Htaccess&lt;br /&gt;
*Web executable script files are suggested not to be allowed such as aspx, css, swf, xhtml, rhtml, shtml, jsp, js, pl, php, cgi.&lt;br /&gt;
&lt;br /&gt;
==Upload Verification==&lt;br /&gt;
*Use image rewriting libraries to verify the image is valid and to strip away extraneous content. &lt;br /&gt;
*Set the extension of the stored image to be a valid image extension based on the detected content type of the image from image processing (e.g. do not just trust the header from the upload). &lt;br /&gt;
*Ensure the detected content type of the image is within a list of defined image types (jpg, png, etc)&lt;br /&gt;
&lt;br /&gt;
= Email Address Validation =&lt;br /&gt;
&lt;br /&gt;
== Email Validation Basics ==&lt;br /&gt;
&lt;br /&gt;
Many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address. Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local portion of the address (left of the rightmost @ character)&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and @)&lt;br /&gt;
* Has zero or more labels&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address. Please note, email addresses should be considered to be public data.&lt;br /&gt;
&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses. Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using + as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one @ symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt. Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorized to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
* Email verification links should only satisfy the requirement of verify email address ownership and should not provide the user with an authenticated session (e.g. the user must still authenticate as normal to access the application).&lt;br /&gt;
* Email verification codes must expire after the first use or expire after 8 hours if not used.&lt;br /&gt;
&lt;br /&gt;
== Address Normalization ==&lt;br /&gt;
&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly. To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent. It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by lowercase(provided)==lowercase(persisted)&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Dave Wichers - dave.wichers [at] aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Source_Code_Analysis_Tools&amp;diff=229375</id>
		<title>Source Code Analysis Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Source_Code_Analysis_Tools&amp;diff=229375"/>
				<updated>2017-05-03T16:33:31Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Open Source or Free Tools Of This Type */ Bandit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Source code analysis tools, also referred to as Static Application Security Testing (SAST) Tools, are designed to analyze source code and/or compiled versions of code to help find security flaws. Ideally, such tools would automatically find security flaws with such a high degree of confidence that what's found is indeed a flaw. However, this is beyond the state of the art for many types of application security flaws. Thus, such tools frequently serve as aids for an analyst to help them zero in on security relevant portions of code so they can find flaws more efficiently, rather than a tool that just automatically finds flaws. If you are interested in the effectiveness of SAST tools, check out the OWASP [[Benchmark]] project, which is scientifically measuring the effectiveness of all types of vulnerability detection tools, including SAST.&lt;br /&gt;
&lt;br /&gt;
Some tools are starting to move into the IDE. For the types of problems that can be detected during the software development phase itself, this is a powerful phase within the development life cycle to employ such tools, as it provides immediate feedback to the developer on issues they might be introducing into the code during code development itself. This immediate feedback is very useful, especially when compared to finding vulnerabilities much later in the development cycle.&lt;br /&gt;
&lt;br /&gt;
== Strengths and Weaknesses ==&lt;br /&gt;
&lt;br /&gt;
=== Strengths ===&lt;br /&gt;
&lt;br /&gt;
* Scales well -- can be run on lots of software, and can be run repeatedly (as with nightly builds or continuous integration)&lt;br /&gt;
* Useful for things that such tools can automatically find with high confidence, such as buffer overflows, SQL Injection Flaws, and so forth&lt;br /&gt;
* Output is good for developers -- highlights the precise source files, line numbers, and even subsections of lines that are affected&lt;br /&gt;
&lt;br /&gt;
=== Weaknesses ===&lt;br /&gt;
&lt;br /&gt;
* Many types of security vulnerabilities are very difficult to find automatically, such as authentication problems, access control issues, insecure use of cryptography, etc. The current state of the art only allows such tools to automatically find a relatively small percentage of application security flaws. However, tools of this type are getting better.&lt;br /&gt;
* High numbers of false positives.&lt;br /&gt;
* Frequently can't find configuration issues, since they are not represented in the code.&lt;br /&gt;
* Difficult to 'prove' that an identified security issue is an actual vulnerability.&lt;br /&gt;
* Many of these tools have difficulty analyzing code that can't be compiled. Analysts frequently can't compile code because they don't have the right libraries, all the compilation instructions, all the code, etc.&lt;br /&gt;
&lt;br /&gt;
==Important Selection Criteria==&lt;br /&gt;
&lt;br /&gt;
* Requirement: Must support your programming language, but not usually a key factor once it does.&lt;br /&gt;
* Types of vulnerabilities it can detect (out of the [[OWASP Top Ten]]?) (plus more?)&lt;br /&gt;
* How accurate is it? False Positive/False Negative rates?&lt;br /&gt;
** Does the tool have an OWASP [[Benchmark]] score?&lt;br /&gt;
* Does it understand the libraries/frameworks you use?&lt;br /&gt;
* Does it require a fully buildable set of source?&lt;br /&gt;
* Can it run against binaries instead of source?&lt;br /&gt;
* Can it be integrated into the developer's IDE?&lt;br /&gt;
* How hard is it to setup/use?&lt;br /&gt;
* Can it be run continuously and automatically?&lt;br /&gt;
* License cost for the tool. (Some are sold per user, per org, per app, per line of code analyzed. Consulting licenses are frequently different than end user licenses.)&lt;br /&gt;
&lt;br /&gt;
==OWASP Tools Of This Type==&lt;br /&gt;
&lt;br /&gt;
* [http://www.owasp.org/index.php/Category:OWASP_Orizon_Project OWASP Orizon Project]&lt;br /&gt;
* [[OWASP_LAPSE_Project | OWASP LAPSE Project]]&lt;br /&gt;
* [[OWASP O2 Platform]]&lt;br /&gt;
* [[OWASP WAP-Web Application Protection]]&lt;br /&gt;
&lt;br /&gt;
==Disclaimer==&lt;br /&gt;
&lt;br /&gt;
Disclaimer: &amp;lt;b&amp;gt;The tools listed in the tables below are presented in alphabetical order. &amp;lt;i&amp;gt;OWASP does not endorse any of the vendors or tools by listing them in the table below.&amp;lt;/i&amp;gt; We have made every effort to provide this information as accurately as possible. If you are the vendor of a tool below and think that this information is incomplete or incorrect, please send an e-mail to our mailing list and we will make every effort to correct this information.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Open Source or Free Tools Of This Type==&lt;br /&gt;
&lt;br /&gt;
* [https://wiki.openstack.org/wiki/Security/Projects/Bandit Bandit] - bandit is a comprehensive source vulnerability scanner for Python&lt;br /&gt;
* [http://brakemanscanner.org/ Brakeman] - Brakeman is an open source vulnerability scanner specifically designed for Ruby on Rails applications&lt;br /&gt;
* [http://rubygems.org/gems/codesake-dawn Codesake Dawn] - Codesake Dawn is an open source security source code analyzer designed for Sinatra, Padrino for Ruby on Rails applications. It also works on non-web applications written in Ruby&lt;br /&gt;
* [http://findbugs.sourceforge.net/ FindBugs] - Find Bugs (including a few security flaws) in Java programs&lt;br /&gt;
* [https://find-sec-bugs.github.io/ FindSecBugs] - A security specific plugin for FingBugs that significantly improves FindBug's ability to find security vulnerabilities in Java programs&lt;br /&gt;
* [http://www.dwheeler.com/flawfinder/ Flawfinder] Flawfinder - Scans C and C++&lt;br /&gt;
* [https://www.bishopfox.com/resources/tools/google-hacking-diggity/attack-tools/ Google CodeSearchDiggity] - Uses Google Code Search to identifies vulnerabilities in open source code projects hosted by Google Code, MS CodePlex, SourceForge, Github, and more. The tool comes with over 130 default searches that identify SQL injection, cross-site scripting (XSS), insecure remote and local file includes, hard-coded passwords, and much more.  ''Essentially, Google CodeSearchDiggity provides a source code security analysis of nearly every single open source code project in existence – simultaneously.'' &lt;br /&gt;
* [http://pmd.sourceforge.net/ PMD] - PMD scans Java source code and looks for potential code problems (this is a code quality tool that does not focus on security issues)&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms933794.aspx PreFast] (Microsoft) - PREfast is a static analysis tool that identifies defects in C/C++ programs. Last update 2006.&lt;br /&gt;
* [http://sourceforge.net/projects/rips-scanner/ RIPS] - RIPS is a static source code analyzer for vulnerabilities in PHP web applications. Please see notes on the sourceforge.net site.&lt;br /&gt;
* [http://www.sonarqube.org/ SonarQube] - Scans source code for more than 20 languages for Bugs, Vulnerabilities, and Code Smells. SonarQube IDE plugins for Eclipse, Visual Studio, and IntelliJ provided by [http://www.sonarlint.org/ SonarLint].&lt;br /&gt;
* [http://sourceforge.net/projects/visualcodegrepp/ VisualCodeGrepper (VCG)] - Scans C/C++, C#, VB, PHP, Java, and PL/SQL for security issues and for comments which may indicate defective code. The config files can be used to carry out additional checks for banned functions or functions which commonly cause security issues.&lt;br /&gt;
* [http://www.xanitizer.net Xanitizer] - Scans Java for security vulnerabilities, mainly via taint analysis. The tool comes with a number of predefined vulnerability detectors which can additionally be extended by the user.&lt;br /&gt;
&lt;br /&gt;
==Commercial Tools Of This Type==&lt;br /&gt;
&lt;br /&gt;
* [http://www-01.ibm.com/software/rational/products/appscan/source/ AppScan Source] (IBM)&lt;br /&gt;
* [http://www.blueclosure.com BlueClosure BC Detect] (BlueClosure)&lt;br /&gt;
* [https://buguroo.com/products/bugblast-next-gen-appsec-platform/bugscout-sca bugScout] (Buguroo Offensive Security) Latest generation source code analysis tool bugScout detects source code vulnerabilities and makes possible an accurate management of the life cycles due to its easy use.&lt;br /&gt;
* [https://www.codacy.com/ Codacy] is free for open source projects, and integrates with tools such as Brakeman, Bandit, FindBugs, and a number of others. It offers security patterns for languages such as Python, Ruby, Scala, Java, Javascript and more.&lt;br /&gt;
* [http://www.contrastsecurity.com/ Contrast from Contrast Security] Contrast performs code security without actually doing static analysis. Contrast does Interactive Application Security Testing (IAST), correlating runtime code &amp;amp; data analysis. It provides code level results without actually relying on static analysis.&lt;br /&gt;
* [http://www.coverity.com/products/code-advisor/ Coverity Code Advisor] (Synopsys)&lt;br /&gt;
* [https://www.checkmarx.com/technology/static-code-analysis-sca/ CxSAST] (Checkmarx)&lt;br /&gt;
* [http://www8.hp.com/us/en/software-solutions/static-code-analysis-sast/ Fortify] (HP)&lt;br /&gt;
* [http://www.juliasoft.com/solutions Julia] - SaaS Java static analysis (JuliaSoft)&lt;br /&gt;
* [http://www.klocwork.com/capabilities/static-code-analysis KlocWork] (KlocWork)&lt;br /&gt;
* [https://www.kiuwan.com/code-analysis/ Kiuwan] - SaaS Software Quality &amp;amp; Security Analysis (an [http://www.optimyth.com Optimyth] company)&lt;br /&gt;
* [http://www.parasoft.com/jsp/capabilities/static_analysis.jsp?itemId=547 Parasoft Test] (Parasoft)&lt;br /&gt;
* [http://www.viva64.com/en/ PVS-Studio] (PVS-Studio) For C/C++, C#&lt;br /&gt;
* [https://www.whitehatsec.com/products/static-application-security-testing/ Sentinel Source] (Whitehat)&lt;br /&gt;
* [https://www.synopsys.com/software-integrity/products/interactive-application-security-testing.html Seeker] (Synopsys) Seeker performs code security without actually doing static analysis. Seeker does Interactive Application Security Testing (IAST), correlating runtime code &amp;amp; data analysis with simulated attacks. It provides code level results without actually relying on static analysis.&lt;br /&gt;
* [http://www.sourcepatrol.co.uk/ Source Patrol] (Pentest)&lt;br /&gt;
* [http://www.veracode.com/products/binary-static-analysis-sast Veracode Static Analysis] (Veracode)&lt;br /&gt;
&lt;br /&gt;
==More info==&lt;br /&gt;
&lt;br /&gt;
* [[Appendix_A:_Testing_Tools | Appendix A: Testing Tools]]&lt;br /&gt;
* [http://samate.nist.gov/index.php/Source_Code_Security_Analyzers.html NIST's list of Source Code Security Analysis Tools]&lt;br /&gt;
* [[:Category:Vulnerability_Scanning_Tools | DAST Tools]] - Similar info on Dynamic Application Security Testing (DAST) Tools&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP .NET Project]]&lt;br /&gt;
[[Category:SAMM-CR-2]]&lt;br /&gt;
__NOTOC__&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229369</id>
		<title>Category:Vulnerability Scanning Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229369"/>
				<updated>2017-05-03T16:14:33Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: update the Beyond Security URL&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Description  ==&lt;br /&gt;
&lt;br /&gt;
Web Application Vulnerability Scanners are automated tools that scan web applications, normally from the outside, to look for security vulnerabilities such as [[Cross-site scripting]], [[SQL Injection]], [[Command Injection]], [[Path Traversal]] and insecure server configuration. This category of tools is frequently referred to as [https://www.techopedia.com/definition/30958/dynamic-application-security-testing-dast Dynamic Application Security Testing] (DAST) Tools. A large number of both commercial and open source tools of this type are available and all of these tools have their own strengths and weaknesses.  If you are interested in the effectiveness of DAST tools, check out the OWASP [[Benchmark]] project, which is scientifically measuring the effectiveness of all types of vulnerability detection tools, including DAST.&lt;br /&gt;
&lt;br /&gt;
Here we provide a list of vulnerability scanning tools currently available in the market.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below are presented in an alphabetical order. &amp;lt;b&amp;gt;OWASP does not endorse any of the Vendors or Scanning Tools by listing them in the table below. We have made every effort to provide this information as accurately as possible. If you are the vendor of a tool below and think this information is incomplete or incorrect, please send an e-mail to our [mailto:owasp_ha_vulnerability_scanner_project@lists.owasp.org mailing list] and we will make every effort to correct this information.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools Listing  ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.acunetix.com/ Acunetix WVS] || tool_owner = Acunetix || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www-03.ibm.com/software/products/en/appscan-standard AppScan] || tool_owner = IBM || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/Products/Application-Security/App-Scanner-Family/App-Scanner-Enterprise/ App Scanner] || tool_owner = Trustwave || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/appspider/ AppSpider] || tool_owner = Rapid7 || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.scanmyserver.com/ AVDS] || tool_owner = Beyond Security || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = SaaS }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.blueclosure.com BlueClosure BC Detect] || tool_owner = BlueClosure || tool_licence = Commercial, 2 weeks trial || tool_platforms = Most platforms supported}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.portswigger.net/ Burp Suite] || tool_owner = PortSwiger || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Most platforms supported }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://detectify.com/ Detectify] || tool_owner = Detectify || tool_licence = Commercial || tool_platforms = SaaS }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.gamasec.com/Gamascan.aspx GamaScan] || tool_owner = GamaSec || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://rgaucher.info/beta/grabber/ Grabber] || tool_owner = Romain Gaucher || tool_licence = Open Source || tool_platforms = Python 2.4, BeautifulSoup and PyXML}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://sourceforge.net/p/grendel/code/ci/c59780bfd41bdf34cc13b27bc3ce694fd3cb7456/tree/ Grendel-Scan] || tool_owner = David Byrne || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.golismero.com GoLismero] || tool_owner = GoLismero Team || tool_licence = GPLv2.0 || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ikare-monitoring.com/ IKare] || tool_owner = ITrust || tool_licence = Commercial || tool_platforms = N/A }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.indusface.com/index.php/products/web-application-scanning Indusface Web Application Scanning] || tool_owner = Indusface || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.nstalker.com/ N-Stealth] || tool_owner = N-Stalker || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.mavitunasecurity.com/ Netsparker] || tool_owner = MavitunaSecurity || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/nexpose-community-edition.jsp Nexpose] || tool_owner = Rapid7 || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Windows/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cirt.net/nikto2 Nikto] || tool_owner = CIRT || tool_licence = Open Source|| tool_platforms = Unix/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.milescan.com/ ParosPro] || tool_owner = MileSCAN || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/proxy.html Proxy.app] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.qualys.com/products/qg_suite/was/ QualysGuard] || tool_owner = Qualys || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondtrust.com/Products/RetinaNetworkSecurityScanner/ Retina] || tool_owner = BeyondTrust || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.orvant.com Securus] || tool_owner = Orvant, Inc || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.whitehatsec.com/home/services/services.html Sentinel] || tool_owner = WhiteHat Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.parasoft.com/products/article.jsp?articleId=3169&amp;amp;redname=webtesting&amp;amp;referred=webtesting SOATest] || tool_owner = Parasoft || tool_licence = Commercial || tool_platforms = Windows / Linux / Solaris}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.tinfoilsecurity.com Tinfoil Security] || tool_owner = Tinfoil Security, Inc. || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/external-vulnerability-scanning.php Trustkeeper Scanner] || tool_owner = Trustwave SpiderLabs || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://subgraph.com/vega/ Vega] || tool_owner = Subgraph || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://wapiti.sourceforge.net/ Wapiti] || tool_owner = Informática Gesfor || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.tripwire.com/it-security-software/enterprise-vulnerability-management/web-application-vulnerability-scanning/ WebApp360] || tool_owner = TripWire || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://webcookies.org WebCookies] || tool_owner = WebCookies || tool_licence = Free|| tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www8.hp.com/us/en/software-solutions/software.html?compURI=1341991#.Uuf0KBAo4iw WebInspect] || tool_owner = HP || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/webreaver.html WebReaver] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.german-websecurity.com/en/products/webscanservice/product-details/overview/ WebScanService] || tool_owner = German Web Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://suite.websecurify.com/ Websecurify Suite] || tool_owner = Websecurify || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows, Linux, Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.sensepost.com/research/wikto/ Wikto] || tool_owner = Sensepost || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.w3af.org/ w3af] || tool_owner = w3af.org || tool_licence = GPLv2.0 || tool_platforms = Linux and Mac}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Xenotix_XSS_Exploit_Framework Xenotix XSS Exploit Framework] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project Zed Attack Proxy] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&lt;br /&gt;
*[[Source_Code_Analysis_Tools | SAST Tools]] - Similar Information on Static Application Security Testing (SAST) Tools&lt;br /&gt;
*http://projects.webappsec.org/Web-Application-Security-Scanner-Evaluation-Criteria&lt;br /&gt;
*http://www.slideshare.net/lbsuto/accuracy-and-timecostsofwebappscanners&lt;br /&gt;
*http://samate.nist.gov/index.php/Web_Application_Vulnerability_Scanners.html&lt;br /&gt;
*http://www.tssci-security.com/archives/2007/11/24/2007-security-testing-tools-in-review/&lt;br /&gt;
*http://www.softwareqatest.com/qatweb1.html#SECURITY&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Tools_Project]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229368</id>
		<title>Category:Vulnerability Scanning Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229368"/>
				<updated>2017-05-03T16:08:51Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: +Detectify&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Description  ==&lt;br /&gt;
&lt;br /&gt;
Web Application Vulnerability Scanners are automated tools that scan web applications, normally from the outside, to look for security vulnerabilities such as [[Cross-site scripting]], [[SQL Injection]], [[Command Injection]], [[Path Traversal]] and insecure server configuration. This category of tools is frequently referred to as [https://www.techopedia.com/definition/30958/dynamic-application-security-testing-dast Dynamic Application Security Testing] (DAST) Tools. A large number of both commercial and open source tools of this type are available and all of these tools have their own strengths and weaknesses.  If you are interested in the effectiveness of DAST tools, check out the OWASP [[Benchmark]] project, which is scientifically measuring the effectiveness of all types of vulnerability detection tools, including DAST.&lt;br /&gt;
&lt;br /&gt;
Here we provide a list of vulnerability scanning tools currently available in the market.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below are presented in an alphabetical order. &amp;lt;b&amp;gt;OWASP does not endorse any of the Vendors or Scanning Tools by listing them in the table below. We have made every effort to provide this information as accurately as possible. If you are the vendor of a tool below and think this information is incomplete or incorrect, please send an e-mail to our [mailto:owasp_ha_vulnerability_scanner_project@lists.owasp.org mailing list] and we will make every effort to correct this information.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools Listing  ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.acunetix.com/ Acunetix WVS] || tool_owner = Acunetix || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www-03.ibm.com/software/products/en/appscan-standard AppScan] || tool_owner = IBM || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/Products/Application-Security/App-Scanner-Family/App-Scanner-Enterprise/ App Scanner] || tool_owner = Trustwave || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/appspider/ AppSpider] || tool_owner = Rapid7 || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondsecurity.com/avds AVDS] || tool_owner = Beyond Security || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = N/A }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.blueclosure.com BlueClosure BC Detect] || tool_owner = BlueClosure || tool_licence = Commercial, 2 weeks trial || tool_platforms = Most platforms supported}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.portswigger.net/ Burp Suite] || tool_owner = PortSwiger || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Most platforms supported }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://detectify.com/ Detectify] || tool_owner = Detectify || tool_licence = Commercial || tool_platforms = SaaS }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.gamasec.com/Gamascan.aspx GamaScan] || tool_owner = GamaSec || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://rgaucher.info/beta/grabber/ Grabber] || tool_owner = Romain Gaucher || tool_licence = Open Source || tool_platforms = Python 2.4, BeautifulSoup and PyXML}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://sourceforge.net/p/grendel/code/ci/c59780bfd41bdf34cc13b27bc3ce694fd3cb7456/tree/ Grendel-Scan] || tool_owner = David Byrne || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.golismero.com GoLismero] || tool_owner = GoLismero Team || tool_licence = GPLv2.0 || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ikare-monitoring.com/ IKare] || tool_owner = ITrust || tool_licence = Commercial || tool_platforms = N/A }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.indusface.com/index.php/products/web-application-scanning Indusface Web Application Scanning] || tool_owner = Indusface || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.nstalker.com/ N-Stealth] || tool_owner = N-Stalker || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.mavitunasecurity.com/ Netsparker] || tool_owner = MavitunaSecurity || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/nexpose-community-edition.jsp Nexpose] || tool_owner = Rapid7 || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Windows/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cirt.net/nikto2 Nikto] || tool_owner = CIRT || tool_licence = Open Source|| tool_platforms = Unix/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.milescan.com/ ParosPro] || tool_owner = MileSCAN || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/proxy.html Proxy.app] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.qualys.com/products/qg_suite/was/ QualysGuard] || tool_owner = Qualys || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondtrust.com/Products/RetinaNetworkSecurityScanner/ Retina] || tool_owner = BeyondTrust || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.orvant.com Securus] || tool_owner = Orvant, Inc || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.whitehatsec.com/home/services/services.html Sentinel] || tool_owner = WhiteHat Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.parasoft.com/products/article.jsp?articleId=3169&amp;amp;redname=webtesting&amp;amp;referred=webtesting SOATest] || tool_owner = Parasoft || tool_licence = Commercial || tool_platforms = Windows / Linux / Solaris}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.tinfoilsecurity.com Tinfoil Security] || tool_owner = Tinfoil Security, Inc. || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/external-vulnerability-scanning.php Trustkeeper Scanner] || tool_owner = Trustwave SpiderLabs || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://subgraph.com/vega/ Vega] || tool_owner = Subgraph || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://wapiti.sourceforge.net/ Wapiti] || tool_owner = Informática Gesfor || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.tripwire.com/it-security-software/enterprise-vulnerability-management/web-application-vulnerability-scanning/ WebApp360] || tool_owner = TripWire || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://webcookies.org WebCookies] || tool_owner = WebCookies || tool_licence = Free|| tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www8.hp.com/us/en/software-solutions/software.html?compURI=1341991#.Uuf0KBAo4iw WebInspect] || tool_owner = HP || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/webreaver.html WebReaver] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.german-websecurity.com/en/products/webscanservice/product-details/overview/ WebScanService] || tool_owner = German Web Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://suite.websecurify.com/ Websecurify Suite] || tool_owner = Websecurify || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows, Linux, Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.sensepost.com/research/wikto/ Wikto] || tool_owner = Sensepost || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.w3af.org/ w3af] || tool_owner = w3af.org || tool_licence = GPLv2.0 || tool_platforms = Linux and Mac}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Xenotix_XSS_Exploit_Framework Xenotix XSS Exploit Framework] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project Zed Attack Proxy] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&lt;br /&gt;
*[[Source_Code_Analysis_Tools | SAST Tools]] - Similar Information on Static Application Security Testing (SAST) Tools&lt;br /&gt;
*http://projects.webappsec.org/Web-Application-Security-Scanner-Evaluation-Criteria&lt;br /&gt;
*http://www.slideshare.net/lbsuto/accuracy-and-timecostsofwebappscanners&lt;br /&gt;
*http://samate.nist.gov/index.php/Web_Application_Vulnerability_Scanners.html&lt;br /&gt;
*http://www.tssci-security.com/archives/2007/11/24/2007-security-testing-tools-in-review/&lt;br /&gt;
*http://www.softwareqatest.com/qatweb1.html#SECURITY&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Tools_Project]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229367</id>
		<title>Category:Vulnerability Scanning Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=229367"/>
				<updated>2017-05-03T16:06:02Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: +WebCookies&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Description  ==&lt;br /&gt;
&lt;br /&gt;
Web Application Vulnerability Scanners are automated tools that scan web applications, normally from the outside, to look for security vulnerabilities such as [[Cross-site scripting]], [[SQL Injection]], [[Command Injection]], [[Path Traversal]] and insecure server configuration. This category of tools is frequently referred to as [https://www.techopedia.com/definition/30958/dynamic-application-security-testing-dast Dynamic Application Security Testing] (DAST) Tools. A large number of both commercial and open source tools of this type are available and all of these tools have their own strengths and weaknesses.  If you are interested in the effectiveness of DAST tools, check out the OWASP [[Benchmark]] project, which is scientifically measuring the effectiveness of all types of vulnerability detection tools, including DAST.&lt;br /&gt;
&lt;br /&gt;
Here we provide a list of vulnerability scanning tools currently available in the market.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below are presented in an alphabetical order. &amp;lt;b&amp;gt;OWASP does not endorse any of the Vendors or Scanning Tools by listing them in the table below. We have made every effort to provide this information as accurately as possible. If you are the vendor of a tool below and think this information is incomplete or incorrect, please send an e-mail to our [mailto:owasp_ha_vulnerability_scanner_project@lists.owasp.org mailing list] and we will make every effort to correct this information.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools Listing  ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.acunetix.com/ Acunetix WVS] || tool_owner = Acunetix || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www-03.ibm.com/software/products/en/appscan-standard AppScan] || tool_owner = IBM || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/Products/Application-Security/App-Scanner-Family/App-Scanner-Enterprise/ App Scanner] || tool_owner = Trustwave || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/appspider/ AppSpider] || tool_owner = Rapid7 || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondsecurity.com/avds AVDS] || tool_owner = Beyond Security || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = N/A }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.blueclosure.com BlueClosure BC Detect] || tool_owner = BlueClosure || tool_licence = Commercial, 2 weeks trial || tool_platforms = Most platforms supported}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.portswigger.net/ Burp Suite] || tool_owner = PortSwiger || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Most platforms supported }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.gamasec.com/Gamascan.aspx GamaScan] || tool_owner = GamaSec || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://rgaucher.info/beta/grabber/ Grabber] || tool_owner = Romain Gaucher || tool_licence = Open Source || tool_platforms = Python 2.4, BeautifulSoup and PyXML}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://sourceforge.net/p/grendel/code/ci/c59780bfd41bdf34cc13b27bc3ce694fd3cb7456/tree/ Grendel-Scan] || tool_owner = David Byrne || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.golismero.com GoLismero] || tool_owner = GoLismero Team || tool_licence = GPLv2.0 || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ikare-monitoring.com/ IKare] || tool_owner = ITrust || tool_licence = Commercial || tool_platforms = N/A }}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.indusface.com/index.php/products/web-application-scanning Indusface Web Application Scanning] || tool_owner = Indusface || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.nstalker.com/ N-Stealth] || tool_owner = N-Stalker || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.mavitunasecurity.com/ Netsparker] || tool_owner = MavitunaSecurity || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/nexpose-community-edition.jsp Nexpose] || tool_owner = Rapid7 || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Windows/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cirt.net/nikto2 Nikto] || tool_owner = CIRT || tool_licence = Open Source|| tool_platforms = Unix/Linux}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.milescan.com/ ParosPro] || tool_owner = MileSCAN || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/proxy.html Proxy.app] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.qualys.com/products/qg_suite/was/ QualysGuard] || tool_owner = Qualys || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondtrust.com/Products/RetinaNetworkSecurityScanner/ Retina] || tool_owner = BeyondTrust || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.orvant.com Securus] || tool_owner = Orvant, Inc || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.whitehatsec.com/home/services/services.html Sentinel] || tool_owner = WhiteHat Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.parasoft.com/products/article.jsp?articleId=3169&amp;amp;redname=webtesting&amp;amp;referred=webtesting SOATest] || tool_owner = Parasoft || tool_licence = Commercial || tool_platforms = Windows / Linux / Solaris}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.tinfoilsecurity.com Tinfoil Security] || tool_owner = Tinfoil Security, Inc. || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = SaaS or On-Premises}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/external-vulnerability-scanning.php Trustkeeper Scanner] || tool_owner = Trustwave SpiderLabs || tool_licence = Commercial || tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://subgraph.com/vega/ Vega] || tool_owner = Subgraph || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://wapiti.sourceforge.net/ Wapiti] || tool_owner = Informática Gesfor || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.tripwire.com/it-security-software/enterprise-vulnerability-management/web-application-vulnerability-scanning/ WebApp360] || tool_owner = TripWire || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://webcookies.org WebCookies] || tool_owner = WebCookies || tool_licence = Free|| tool_platforms = SaaS}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www8.hp.com/us/en/software-solutions/software.html?compURI=1341991#.Uuf0KBAo4iw WebInspect] || tool_owner = HP || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com/desktop/webreaver.html WebReaver] || tool_owner = Websecurify || tool_licence = Commercial || tool_platforms = Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.german-websecurity.com/en/products/webscanservice/product-details/overview/ WebScanService] || tool_owner = German Web Security || tool_licence = Commercial || tool_platforms = N/A}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://suite.websecurify.com/ Websecurify Suite] || tool_owner = Websecurify || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows, Linux, Macintosh}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.sensepost.com/research/wikto/ Wikto] || tool_owner = Sensepost || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.w3af.org/ w3af] || tool_owner = w3af.org || tool_licence = GPLv2.0 || tool_platforms = Linux and Mac}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Xenotix_XSS_Exploit_Framework Xenotix XSS Exploit Framework] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project Zed Attack Proxy] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&lt;br /&gt;
*[[Source_Code_Analysis_Tools | SAST Tools]] - Similar Information on Static Application Security Testing (SAST) Tools&lt;br /&gt;
*http://projects.webappsec.org/Web-Application-Security-Scanner-Evaluation-Criteria&lt;br /&gt;
*http://www.slideshare.net/lbsuto/accuracy-and-timecostsofwebappscanners&lt;br /&gt;
*http://samate.nist.gov/index.php/Web_Application_Vulnerability_Scanners.html&lt;br /&gt;
*http://www.tssci-security.com/archives/2007/11/24/2007-security-testing-tools-in-review/&lt;br /&gt;
*http://www.softwareqatest.com/qatweb1.html#SECURITY&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Tools_Project]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=229317</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=229317"/>
				<updated>2017-05-02T10:43:59Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Tools */ no longer active&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{taggedDocument&lt;br /&gt;
| type=pls_review&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or deactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instruct the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting is commonly used (can be disabled if target site does not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tags,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229194</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229194"/>
				<updated>2017-04-27T13:45:24Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: REGEXP_LIKE + DBMS_ASSERT&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. See [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping output data to prevent Cross-Site Scripting==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. See [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications should use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username)); -- outputs &amp;amp;lt;H1&amp;amp;gt;...&amp;amp;lt;/H1&amp;amp;gt;&lt;br /&gt;
    htp.print('Username: '); -- just a string literal, no need to escape&lt;br /&gt;
    htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.para();&lt;br /&gt;
    htp.prints(address); -- escapes dangerous chars in address string&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents and not context-aware.&lt;br /&gt;
&lt;br /&gt;
==Input validation and sanitization==&lt;br /&gt;
===Regular expression functions===&lt;br /&gt;
    IF REGEXP_LIKE('untrusted input', '^[0-9a-zA-z]{2,6}$') THEN /* Match */ ELSE /* No match */ END IF;&lt;br /&gt;
    select REGEXP_REPLACE('subject&amp;lt;&amp;lt;&amp;gt;&amp;gt;', '[&amp;lt;&amp;gt;]') from dual; -- returns: &amp;quot;subject&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===DBMS_ASSERT===&lt;br /&gt;
* ENQUOTE_LITERAL — Enquotes a string literal&lt;br /&gt;
* ENQUOTE_NAME — Encloses a name in double quotes&lt;br /&gt;
* NOOP — Returns the unmodified value&lt;br /&gt;
* QUALIFIED_SQL_NAME — Verifies that the input string is a qualified SQL name&lt;br /&gt;
* SCHEMA_NAME — Verifies that the input string is an existing schema name&lt;br /&gt;
* SIMPLE_SQL_NAME — Verifies that the input string is a simple SQL name&lt;br /&gt;
* SQL_OBJECT_NAME — Verifies that the input parameter string is a qualified SQL identifier of an existing SQL object&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    SELECT SYS.DBMS_ASSERT.SIMPLE_SQL_NAME  ('Data with &amp;lt;invalid&amp;gt; characters') FROM dual;&lt;br /&gt;
    ORA-44003: invalid SQL name&lt;br /&gt;
&lt;br /&gt;
See [https://docs.oracle.com/database/121/ARPLS/d_assert.htm#ARPLS231 Oracle: DBMS_ASSERT]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [http://www.oracle.com/technetwork/database/features/plsql/overview/how-to-write-injection-proof-plsql-1-129572.pdf Oracle &amp;quot;How to write SQL injection proof PL/SQL&amp;quot;]&lt;br /&gt;
* [http://www.oracle.com/technetwork/developer-tools/adf/adfowasptop10-final-2348304.pdf Security in Oracle ADF: Addressing the OWASP Top 10 Security Vulnerabilities]&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229189</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229189"/>
				<updated>2017-04-27T13:03:02Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. See [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping output data to prevent Cross-Site Scripting==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. See [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications should use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username)); -- outputs &amp;amp;lt;H1&amp;amp;gt;...&amp;amp;lt;/H1&amp;amp;gt;&lt;br /&gt;
    htp.print('Username: '); -- just a string literal, no need to escape&lt;br /&gt;
    htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.para();&lt;br /&gt;
    htp.prints(address); -- escapes dangerous chars in address string&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents and not context-aware.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229186</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229186"/>
				<updated>2017-04-27T10:48:45Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. See [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. See [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications should use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username)); -- outputs &amp;amp;lt;H1&amp;amp;gt;...&amp;amp;lt;/H1&amp;amp;gt;&lt;br /&gt;
    htp.print('Username: '); -- just a string literal, no need to escape&lt;br /&gt;
    htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.para();&lt;br /&gt;
    htp.prints(address); -- escapes dangerous chars in address string&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents and not context-aware.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229185</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229185"/>
				<updated>2017-04-27T10:48:26Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. See [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. See [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications should use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username)); -- outputs &amp;amp;lt;H1&amp;amp;gt;...&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;&lt;br /&gt;
    htp.print('Username: '); -- just a string literal, no need to escape&lt;br /&gt;
    htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.para();&lt;br /&gt;
    htp.prints(address); -- escapes dangerous chars in address string&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents and not context-aware.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229184</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229184"/>
				<updated>2017-04-27T10:46:11Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications running on older versions of Oracle may use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username));&lt;br /&gt;
    htp.print('Username: '); -- just a string literal, no need to escape&lt;br /&gt;
    htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.para();&lt;br /&gt;
    htp.prints(address); -- escapes dangerous chars in address string&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents and not context-aware.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229183</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229183"/>
				<updated>2017-04-27T10:43:18Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: more samples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications running on older versions of Oracle may use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.header(1, 'Details for user ' || apex_escape.html(username));&lt;br /&gt;
    htp.print('&amp;lt;li&amp;gt;Username: ' || htp.italic(apex_escape.html(username), 'class=' || apex_escape.html_attribute(userclass) );&lt;br /&gt;
    htp.prints(address);&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escape.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229182</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229182"/>
				<updated>2017-04-27T10:38:22Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications running on older versions of Oracle may use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.print('Username: ' || apex_escape.html(username));&lt;br /&gt;
    htp.prints(address)&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escap.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229181</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229181"/>
				<updated>2017-04-27T10:37:51Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: code sample&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; (hypertext procedures) and &amp;lt;code&amp;gt;htf&amp;lt;/code&amp;gt; (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; for contextual escaping of output data in a manner similar to [[ESAPI]] validators. [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications running on older versions of Oracle may use &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; to output text blocks rather than &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; as the former escapes potentially dangerous characters (&amp;lt;code&amp;gt;&amp;lt;&amp;gt;&amp;quot;'&amp;lt;/code&amp;gt;). Note that the &amp;lt;code&amp;gt;htp.prints&amp;lt;/code&amp;gt; cannot be used as a simple drop-in replacement for &amp;lt;code&amp;gt;htp.print&amp;lt;/code&amp;gt; because it will also escape legitimate HTML but by &amp;lt;code&amp;gt;htp&amp;lt;/code&amp;gt; usage model raw HTML shouldn't be generally entered in strings but rather generated with appropriate HTML functions (e.g. &amp;lt;code&amp;gt;htp.header(1, 'Hello');&amp;lt;/code&amp;gt; will output &amp;lt;code&amp;gt;&amp;amp;lt;H1&amp;amp;gt;Hello&amp;amp;lt;/H1&amp;amp;gt;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Sample usage in typical PL/SQL code:&lt;br /&gt;
&lt;br /&gt;
    htp.print('&amp;lt;b&amp;gt;User' || apex_escape.html(username) || '&amp;lt;/b&amp;gt;');&lt;br /&gt;
    htp.prints(address)&lt;br /&gt;
    htp.script ('var username=&amp;quot;' || apex_escap.js_literal(username) || '&amp;quot;;');&lt;br /&gt;
&lt;br /&gt;
On older Oracle platforms &amp;lt;code&amp;gt;htf.escape_sc&amp;lt;/code&amp;gt; for output in HTML context can be used and the &amp;lt;code&amp;gt;utl_url.escape&amp;lt;/code&amp;gt; function is available to escape URL characters (&amp;lt;code&amp;gt;&amp;amp;&amp;quot;&amp;lt;&amp;gt;%&amp;lt;/code&amp;gt;). URL escaping functionality is also provided by legacy &amp;lt;code&amp;gt;htf.escape_url&amp;lt;/code&amp;gt; function. These functions are generally less robust than their &amp;lt;code&amp;gt;apex_escape&amp;lt;/code&amp;gt; equivalents.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229180</id>
		<title>PL/SQL Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PL/SQL_Security_Cheat_Sheet&amp;diff=229180"/>
				<updated>2017-04-27T09:53:32Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: initial version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PL/SQL is a powerful procedural language built on top of Oracle SQL syntax. Extensive library of business-related and data-processing functions it incorporates makes it an attractive environment for building business-critical applications operating fully within the Oracle database. Introduction of PL/SQL Web Toolkit enabled Oracle developers to generate HTML straight from the PL/SQL code and build web applications fully residing from within the Oracle database.&lt;br /&gt;
&lt;br /&gt;
Just as any other web stack, PL/SQL web applications require careful input validation and other standard safeguards to prevent exploitable [[OWASP Top 10]] vulnerabilities.  Oracle `htp` (hypertext procedures) and `htf` (hypertext functions) packages contain the primary functions for generating output in PL/SQL web applications as well as output escaping functions. [https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm Oracle: The htp and htf Packages]&lt;br /&gt;
&lt;br /&gt;
==Escaping==&lt;br /&gt;
Applications running on newer Oracle versions where APEX packages are available should use `apex_escape` for contextual escaping of output data in a manner similar to [[ESAPI]] validators. [https://docs.oracle.com/database/121/AEAPI/apex_escape.htm Oracle: apex_escape]&lt;br /&gt;
&lt;br /&gt;
* APEX_ESCAPE.HTML&lt;br /&gt;
* APEX_ESCAPE.HTML_ATTRIBUTE &lt;br /&gt;
* APEX_ESCAPE.HTML_TRUNC&lt;br /&gt;
* APEX_ESCAPE.HTML_WHITELIST&lt;br /&gt;
* APEX_ESCAPE.JS_LITERAL&lt;br /&gt;
* APEX_ESCAPE.LDAP_DN&lt;br /&gt;
* APEX_ESCAPE.LDAP_SEARCH_FILTER&lt;br /&gt;
* APEX_ESCAPE.NOOP&lt;br /&gt;
&lt;br /&gt;
Applications running on older versions of Oracle may use '''htp.prints''' to output text blocks rather than '''htp.print''' as the former escapes potentially dangerous characters (`&amp;lt;&amp;gt;&amp;quot;'`). &lt;br /&gt;
&lt;br /&gt;
For escaping individual data fields `htf.escape_sc` for output in HTML context should be used. The `utl_url.escape` function is available to escape URL characters (`&amp;amp;&amp;quot;&amp;lt;&amp;gt;%`). URL escaping functionality is also provided by legacy `htf.escape_url` function but it's less robust.&lt;br /&gt;
&lt;br /&gt;
==Authors==&lt;br /&gt;
* Pawel Krawczyk&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SQL_Injection_Prevention_Cheat_Sheet&amp;diff=229179</id>
		<title>SQL Injection Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SQL_Injection_Prevention_Cheat_Sheet&amp;diff=229179"/>
				<updated>2017-04-27T08:45:42Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Escaping SQLi in PhP */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, simple, actionable guidance for preventing SQL Injection flaws in your applications. [[SQL Injection]] attacks are unfortunately very common, and this is due to two factors:&lt;br /&gt;
&lt;br /&gt;
# the significant prevalence of SQL Injection vulnerabilities, and &lt;br /&gt;
# the attractiveness of the target (i.e., the database typically contains all the interesting/critical data for your application).&lt;br /&gt;
&lt;br /&gt;
It’s somewhat shameful that there are so many successful SQL Injection attacks occurring, because it is EXTREMELY simple to avoid SQL Injection vulnerabilities in your code.&lt;br /&gt;
&lt;br /&gt;
SQL Injection flaws are introduced when software developers create dynamic database queries that include user supplied input. To avoid SQL injection flaws is simple. Developers need to either:&lt;br /&gt;
a) stop writing dynamic queries; and/or&lt;br /&gt;
b) prevent user supplied input which contains malicious SQL from affecting the logic of the executed query.&lt;br /&gt;
&lt;br /&gt;
This article provides a set of simple techniques for preventing SQL Injection vulnerabilities by avoiding these two problems. These techniques can be used with practically any kind of programming language with any type of database. There are other types of databases, like XML databases, which can have similar problems (e.g., XPath and XQuery injection) and these techniques can be used to protect them as well.&lt;br /&gt;
&lt;br /&gt;
Primary Defenses:&lt;br /&gt;
* '''Option #1: Use of Prepared Statements (Parameterized Queries)'''&lt;br /&gt;
* '''Option #2: Use of Stored Procedures'''&lt;br /&gt;
* '''Option #3: Escaping all User Supplied Input'''&lt;br /&gt;
&lt;br /&gt;
Additional Defenses:&lt;br /&gt;
* '''Also Enforce: Least Privilege'''&lt;br /&gt;
* '''Also Perform: White List Input Validation'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
;Unsafe Example&lt;br /&gt;
&lt;br /&gt;
SQL injection flaws typically look like this:&lt;br /&gt;
&lt;br /&gt;
The following (Java) example is UNSAFE, and would allow an attacker to inject code into the query that would be executed by the database. The unvalidated “customerName” parameter that is simply appended to the query allows an attacker to inject any SQL code they want. Unfortunately, this method for accessing databases is all too common.&lt;br /&gt;
&lt;br /&gt;
  String query = &amp;quot;SELECT account_balance FROM user_data WHERE user_name = &amp;quot;&lt;br /&gt;
    + request.getParameter(&amp;quot;customerName&amp;quot;);&lt;br /&gt;
  &lt;br /&gt;
  try {&lt;br /&gt;
  	Statement statement = connection.createStatement( … );&lt;br /&gt;
  	ResultSet results = statement.executeQuery( query );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=Primary Defenses=&lt;br /&gt;
&lt;br /&gt;
==Defense Option 1: Prepared Statements (with Parameterized Queries)==&lt;br /&gt;
&lt;br /&gt;
The use of prepared statements with variable binding (aka parameterized queries) is how all developers should first be taught how to write database queries. They are simple to write, and easier to understand than dynamic queries. Parameterized queries force the developer to first define all the SQL code, and then pass in each parameter to the query later. This coding style allows the database to distinguish between code and data, regardless of what user input is supplied.&lt;br /&gt;
&lt;br /&gt;
Prepared statements ensure that an attacker is not able to change the intent of a query, even if SQL commands are inserted by an attacker. In the safe example below, if an attacker were to enter the userID of tom' or '1'='1, the parameterized query would not be vulnerable and would instead look for a username which literally matched the entire string tom' or '1'='1.&lt;br /&gt;
&lt;br /&gt;
Language specific recommendations:&lt;br /&gt;
* Java EE – use PreparedStatement() with bind variables&lt;br /&gt;
* .NET – use parameterized queries like SqlCommand() or OleDbCommand() with bind variables&lt;br /&gt;
* PHP – use PDO with strongly typed parameterized queries (using bindParam())&lt;br /&gt;
* Hibernate - use createQuery() with bind variables (called named parameters in Hibernate)&lt;br /&gt;
* SQLite - use sqlite3_prepare() to create a [http://www.sqlite.org/c3ref/stmt.html statement object]&lt;br /&gt;
&lt;br /&gt;
In rare circumstances, prepared statements can harm performance. When confronted with this situation, it is best to either a) strongly validate all data or b) escape all user supplied input using an escaping routine specific to your database vendor as described below, rather than using a prepared statement.&lt;br /&gt;
&lt;br /&gt;
;Safe Java Prepared Statement Example	&lt;br /&gt;
&lt;br /&gt;
The following code example uses a PreparedStatement, Java's implementation of a parameterized query, to execute the same database query.&lt;br /&gt;
&lt;br /&gt;
  String custname = request.getParameter(&amp;quot;customerName&amp;quot;); // This should REALLY be validated too&lt;br /&gt;
  // perform input validation to detect attacks&lt;br /&gt;
  String query = &amp;quot;SELECT account_balance FROM user_data WHERE user_name = ? &amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  '''PreparedStatement pstmt = connection.prepareStatement( query );'''&lt;br /&gt;
  '''pstmt.setString( 1, custname); '''&lt;br /&gt;
  ResultSet results = pstmt.executeQuery( );&lt;br /&gt;
&lt;br /&gt;
;Safe C# .NET Prepared Statement Example	&lt;br /&gt;
&lt;br /&gt;
With .NET, it's even more straightforward. The creation and execution of the query doesn't change. All you have to do is simply pass the parameters to the query using the Parameters.Add() call as shown here.&lt;br /&gt;
 &lt;br /&gt;
  String query = &lt;br /&gt;
  	 &amp;quot;SELECT account_balance FROM user_data WHERE user_name = ?&amp;quot;;&lt;br /&gt;
  try {&lt;br /&gt;
  	OleDbCommand command = new OleDbCommand(query, connection);&lt;br /&gt;
  	'''command.Parameters.Add(new OleDbParameter(&amp;quot;customerName&amp;quot;, CustomerName Name.Text));'''&lt;br /&gt;
  	OleDbDataReader reader = command.ExecuteReader();&lt;br /&gt;
  	// …&lt;br /&gt;
  } catch (OleDbException se) {&lt;br /&gt;
  	// error handling&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
We have shown examples in Java and .NET but practically all other languages, including Cold Fusion, and Classic ASP, support parameterized query interfaces. Even SQL abstraction layers, like the [http://www.hibernate.org/ Hibernate Query Language] (HQL) have the same type of injection problems (which we call [http://cwe.mitre.org/data/definitions/564.html HQL Injection]). HQL supports parameterized queries as well, so we can avoid this problem:&lt;br /&gt;
&lt;br /&gt;
;Hibernate Query Language (HQL) Prepared Statement (Named Parameters) Examples	&lt;br /&gt;
&lt;br /&gt;
  First is an unsafe HQL Statement&lt;br /&gt;
  &lt;br /&gt;
  Query unsafeHQLQuery = session.createQuery(&amp;quot;from Inventory where productID='&amp;quot;+userSuppliedParameter+&amp;quot;'&amp;quot;);&lt;br /&gt;
  &lt;br /&gt;
  Here is a safe version of the same query using named parameters&lt;br /&gt;
  &lt;br /&gt;
  Query safeHQLQuery = session.createQuery(&amp;quot;from Inventory where productID=:productid&amp;quot;);&lt;br /&gt;
  safeHQLQuery.setParameter(&amp;quot;productid&amp;quot;, userSuppliedParameter);&lt;br /&gt;
&lt;br /&gt;
For examples of parameterized queries in other languages, including Ruby, PHP, Cold Fusion, and Perl, see the [[Query Parameterization Cheat Sheet]] or [http://bobby-tables.com/ http://bobby-tables.com/].&lt;br /&gt;
&lt;br /&gt;
Developers tend to like the Prepared Statement approach because all the SQL code stays within the application. This makes your application relatively database independent.&lt;br /&gt;
&lt;br /&gt;
== Defense Option 2: Stored Procedures ==&lt;br /&gt;
 &lt;br /&gt;
Stored procedures are not always safe from SQL injection. However, certain standard stored procedure programming constructs have the same effect as the use of parameterized queries when implemented safely* which is the norm for most stored procedure languages. They require the developer to just build SQL statements with parameters which are automatically parameterized unless the developer does something largely out of the norm. The difference between prepared statements and stored procedures is that the SQL code for a stored procedure is defined and stored in the database itself, and then called from the application. Both of these techniques have the same effectiveness in preventing SQL injection so your organization should choose which approach makes the most sense for you.&lt;br /&gt;
 	&lt;br /&gt;
&amp;amp;#42;Note: 'Implemented safely' means the stored procedure does not include any unsafe dynamic SQL generation. Developers do not usually generate dynamic SQL inside stored procedures. However, it can be done, but should be avoided. If it can't be avoided, the stored procedure must use input validation or proper escaping as described in this article to make sure that all user supplied input to the stored procedure can't be used to inject SQL code into the dynamically generated query. Auditors should always look for uses of sp_execute, execute or exec within SQL Server stored procedures. Similar audit guidelines are necessary for similar functions for other vendors.&lt;br /&gt;
 &lt;br /&gt;
There are also several cases where stored procedures can increase risk.  For example, on MS SQL server, you have 3 main default roles: db_datareader, db_datawriter and db_owner. Before stored procedures came into use, DBA's would give db_datareader or db_datawriter rights to the webservice's user, depending on the requirements. However, stored procedures require execute rights, a role that is not available by default. Some setups where the user management has been centralized, but is limited to those 3 roles, cause all web apps to run under db_owner rights so stored procedures can work. Naturally, that means that if a server is breached the attacker has full rights to the database, where previously they might only have had read-access. More on this topic here. [http://www.sqldbatips.com/showarticle.asp?ID=8  http://www.sqldbatips.com/showarticle.asp?ID=8 ]&lt;br /&gt;
&lt;br /&gt;
;Safe Java Stored Procedure Example&lt;br /&gt;
&lt;br /&gt;
The following code example uses a CallableStatement, Java's implementation of the stored procedure interface, to execute the same database query. The &amp;quot;sp_getAccountBalance&amp;quot; stored procedure would have to be predefined in the database and implement the same functionality as the query defined above.&lt;br /&gt;
 &lt;br /&gt;
  String custname = request.getParameter(&amp;quot;customerName&amp;quot;); // This should REALLY be validated&lt;br /&gt;
  try {&lt;br /&gt;
  	'''CallableStatement cs = connection.prepareCall(&amp;quot;{call sp_getAccountBalance(?)}&amp;quot;);'''&lt;br /&gt;
  	'''cs.setString(1, custname);'''&lt;br /&gt;
  	ResultSet results = cs.executeQuery();		&lt;br /&gt;
  	// … result set handling &lt;br /&gt;
  } catch (SQLException se) {			&lt;br /&gt;
  	// … logging and error handling&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
;Safe VB .NET Stored Procedure Example	&lt;br /&gt;
&lt;br /&gt;
The following code example uses a SqlCommand, .NET’s implementation of the stored procedure interface, to execute the same database query. The &amp;quot;sp_getAccountBalance&amp;quot; stored procedure would have to be predefined in the database and implement the same functionality as the query defined above.&lt;br /&gt;
 &lt;br /&gt;
  Try&lt;br /&gt;
  	Dim command As SqlCommand = new SqlCommand(&amp;quot;sp_getAccountBalance&amp;quot;, connection)&lt;br /&gt;
  	'''command.CommandType = CommandType.StoredProcedure'''&lt;br /&gt;
  	'''command.Parameters.Add(new SqlParameter(&amp;quot;@CustomerName&amp;quot;, CustomerName.Text))'''&lt;br /&gt;
  	Dim reader As SqlDataReader = command.ExecuteReader()&lt;br /&gt;
  	‘ …&lt;br /&gt;
  Catch se As SqlException &lt;br /&gt;
  	‘ error handling&lt;br /&gt;
  End Try&lt;br /&gt;
&lt;br /&gt;
== Defense Option 3: White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
Various parts of SQL queries aren't legal locations for the use of bind variables, such as the names of tables or columns, and the sort order indicator (ASC or DESC). In such situations, input validation or query redesign is the most appropriate defense. For the names of tables or columns, ideally those values come from the code, and not from user parameters. But if user parameter values are used to make different for table names and column names, then the parameter values should be mapped to the legal/expected table or column names to make sure unvalidated user input doesn't end up in the query. Please note, this is a symptom of poor design and a full re-write should be considered if time allows. Here is an example of table name validation.&lt;br /&gt;
&lt;br /&gt;
  String tableName;&lt;br /&gt;
  switch(PARAM):&lt;br /&gt;
    case &amp;quot;Value1&amp;quot;: tableName = &amp;quot;fooTable&amp;quot;;&lt;br /&gt;
                   break;&lt;br /&gt;
    case &amp;quot;Value2&amp;quot;: tableName = &amp;quot;barTable&amp;quot;;&lt;br /&gt;
                   break;&lt;br /&gt;
      ...&lt;br /&gt;
    default      : throw new InputValidationException(&amp;quot;unexpected value provided for table name&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
The tableName can then be directly appended to the SQL query since it is now known to be one of the legal and expected values for a table name in this query. Keep in mind that generic table validation functions can lead to data loss as table names are used in queries where they are not expected.&lt;br /&gt;
&lt;br /&gt;
For something simple like a sort order, it would be best if the user supplied input is converted to a boolean, and then that boolean is used to select the safe value to append to the query. This is a very standard need in dynamic query creation. For example:&lt;br /&gt;
&lt;br /&gt;
  public String someMethod(boolean sortOrder) {&lt;br /&gt;
  &lt;br /&gt;
  String SQLquery = &amp;quot;some SQL ... order by Salary &amp;quot; + (sortOrder ? &amp;quot;ASC&amp;quot; : &amp;quot;DESC&amp;quot;);&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
Any time user input can be converted to a non-String, like a date, numeric, boolean, enumerated type, etc. before it is appended to a query, or used to select a value to append to the query, this ensures it is safe to do so.&lt;br /&gt;
&lt;br /&gt;
Input validation is also recommended as a secondary defense in ALL cases, even when using bind variables as is discussed later in this article. More techniques on how to implement strong white list input validation is described in the [[Input Validation Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
==Defense Option 4: Escaping All User Supplied Input==&lt;br /&gt;
&lt;br /&gt;
This technique should only be used as a last resort, when none of the above are feasible. Input validation is probably a better choice as this methodology is frail compared to other defenses and we cannot guarantee it will prevent all SQL Injection in all situations. &lt;br /&gt;
&lt;br /&gt;
This technique is to escape user input before putting it in a query. It is very database specific in its implementation. Its usually only recommended to retrofit legacy code when implementing input validation isn't cost effective. Applications built from scratch, or applications requiring low risk tolerance should be built or re-written using parameterized queries, stored procedures, or some kind of Object Relational Mapper (ORM) that builds your queries for you.&lt;br /&gt;
&lt;br /&gt;
This technique works like this. Each DBMS supports one or more character escaping schemes specific to certain kinds of queries. If you then escape all user supplied input using the proper escaping scheme for the database you are using, the DBMS will not confuse that input with SQL code written by the developer, thus avoiding any possible SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
* Full details on [[ESAPI|ESAPI are available here on OWASP]].&lt;br /&gt;
* The javadoc for [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/index.html ESAPI is available here at its Google Code repository].&lt;br /&gt;
* You can also directly [http://code.google.com/p/owasp-esapi-java/source/browse/#svn/trunk/src/main/java/org/owasp/esapi browse the source at Google], which is frequently helpful if the javadoc isn't perfectly clear.&lt;br /&gt;
&lt;br /&gt;
To find the javadoc specifically for the database encoders, click on the ‘Codec’ class on the left hand side. There are lots of Codecs implemented. The two Database specific codecs are OracleCodec, and MySQLCodec.&lt;br /&gt;
&lt;br /&gt;
Just click on their names in the ‘All Known Implementing Classes:’ at the top of the Interface Codec page.&lt;br /&gt;
&lt;br /&gt;
At this time, ESAPI currently has database encoders for:&lt;br /&gt;
* Oracle&lt;br /&gt;
* MySQL (Both ANSI and native modes are supported)&lt;br /&gt;
&lt;br /&gt;
Database encoders for:&lt;br /&gt;
* SQL Server&lt;br /&gt;
* PostgreSQL&lt;br /&gt;
&lt;br /&gt;
Are forthcoming. If your database encoder is missing, please let us know.&lt;br /&gt;
&lt;br /&gt;
===Database Specific Escaping Details===&lt;br /&gt;
&lt;br /&gt;
If you want to build your own escaping routines, here are the escaping details for each of the databases that we have developed ESAPI Encoders for:&lt;br /&gt;
&lt;br /&gt;
====Oracle Escaping====&lt;br /&gt;
&lt;br /&gt;
This information is based on the Oracle Escape character information found here: [http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_characters_when_writing_SQL_queries.3F http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_characters_when_writing_SQL_queries.3F]&lt;br /&gt;
&lt;br /&gt;
=====Escaping Dynamic Queries=====&lt;br /&gt;
&lt;br /&gt;
To use an ESAPI database codec is pretty simple. An Oracle example looks something like:&lt;br /&gt;
  ESAPI.encoder().encodeForSQL( new OracleCodec(), queryparam );&lt;br /&gt;
&lt;br /&gt;
So, if you had an existing Dynamic query being generated in your code that was going to Oracle that looked like this:&lt;br /&gt;
&lt;br /&gt;
  String query = &amp;quot;SELECT user_id FROM user_data WHERE user_name = '&amp;quot; + req.getParameter(&amp;quot;userID&amp;quot;) &lt;br /&gt;
  + &amp;quot;' and user_password = '&amp;quot; + req.getParameter(&amp;quot;pwd&amp;quot;) +&amp;quot;'&amp;quot;;&lt;br /&gt;
  try {&lt;br /&gt;
      Statement statement = connection.createStatement( … );&lt;br /&gt;
      ResultSet results = statement.executeQuery( query );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
You would rewrite the first line to look like this:&lt;br /&gt;
&lt;br /&gt;
 '''Codec ORACLE_CODEC = new OracleCodec();'''&lt;br /&gt;
  String query = &amp;quot;SELECT user_id FROM user_data WHERE user_name = '&amp;quot; + &lt;br /&gt;
    '''ESAPI.encoder().encodeForSQL( ORACLE_CODEC, req.getParameter(&amp;quot;userID&amp;quot;))''' + &amp;quot;' and user_password = '&amp;quot;&lt;br /&gt;
    + '''ESAPI.encoder().encodeForSQL( ORACLE_CODEC, req.getParameter(&amp;quot;pwd&amp;quot;))''' +&amp;quot;'&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
And it would now be safe from SQL injection, regardless of the input supplied.&lt;br /&gt;
&lt;br /&gt;
For maximum code readability, you could also construct your own OracleEncoder.&lt;br /&gt;
&lt;br /&gt;
  Encoder oe = new OracleEncoder();&lt;br /&gt;
  String query = &amp;quot;SELECT user_id FROM user_data WHERE user_name = '&amp;quot; &lt;br /&gt;
    + '''oe.encode( req.getParameter(&amp;quot;userID&amp;quot;))''' + &amp;quot;' and user_password = '&amp;quot; &lt;br /&gt;
    + '''oe.encode( req.getParameter(&amp;quot;pwd&amp;quot;))''' +&amp;quot;'&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
With this type of solution, all your developers would have to do is wrap each user supplied parameter being passed in into an '''ESAPI.encoder().encodeForOracle( )''' call or whatever you named it, and you would be done.&lt;br /&gt;
&lt;br /&gt;
=====Turn off character replacement=====&lt;br /&gt;
&lt;br /&gt;
Use SET DEFINE OFF or SET SCAN OFF to ensure that automatic character replacement is turned off. If this character replacement is turned on, the &amp;amp; character will be treated like a SQLPlus variable prefix that could allow an attacker to retrieve private data. &lt;br /&gt;
&lt;br /&gt;
See [http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12040.htm#i2698854 http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12040.htm#i2698854] and [http://stackoverflow.com/questions/152837/how-to-insert-a-string-which-contains-an http://stackoverflow.com/questions/152837/how-to-insert-a-string-which-contains-an] for more information&lt;br /&gt;
&lt;br /&gt;
=====Escaping Wildcard characters in Like Clauses=====&lt;br /&gt;
&lt;br /&gt;
The LIKE keyword allows for text scanning searches. In Oracle, the underscore '_' character matches only one character, while the ampersand '%' is used to match zero or more occurrences of any characters. These characters must be escaped in LIKE clause criteria. For example:&lt;br /&gt;
&lt;br /&gt;
 SELECT name FROM emp &lt;br /&gt;
 WHERE id LIKE '%/_%' ESCAPE '/';&lt;br /&gt;
&lt;br /&gt;
 SELECT name FROM emp &lt;br /&gt;
 WHERE id LIKE '%\%%' ESCAPE '\';&lt;br /&gt;
&lt;br /&gt;
=====Oracle 10g escaping=====&lt;br /&gt;
&lt;br /&gt;
An alternative for Oracle 10g and later is to place { and } around the string to escape the entire string. However, you have to be careful that there isn't a } character already in the string. You must search for these and if there is one, then you must replace it with }}. Otherwise that character will end the escaping early, and may introduce a vulnerability.&lt;br /&gt;
&lt;br /&gt;
====MySQL Escaping====&lt;br /&gt;
&lt;br /&gt;
MySQL supports two escaping modes:&lt;br /&gt;
&lt;br /&gt;
# ANSI_QUOTES SQL mode, and a mode with this off, which we call&lt;br /&gt;
# MySQL mode.&lt;br /&gt;
&lt;br /&gt;
ANSI SQL mode: Simply encode all ' (single tick) characters with '&amp;amp;#39; (two single ticks)&lt;br /&gt;
&lt;br /&gt;
MySQL mode, do the following:&lt;br /&gt;
&lt;br /&gt;
  NUL (0x00) --&amp;gt; \0  [This is a zero, not the letter O]&lt;br /&gt;
  BS  (0x08) --&amp;gt; \b&lt;br /&gt;
  TAB (0x09) --&amp;gt; \t&lt;br /&gt;
  LF  (0x0a) --&amp;gt; \n&lt;br /&gt;
  CR  (0x0d) --&amp;gt; \r&lt;br /&gt;
  SUB (0x1a) --&amp;gt; \Z&lt;br /&gt;
  &amp;quot;   (0x22) --&amp;gt; \&amp;quot;&lt;br /&gt;
  %   (0x25) --&amp;gt; \%&lt;br /&gt;
  '   (0x27) --&amp;gt; \'&lt;br /&gt;
  \   (0x5c) --&amp;gt; \\&lt;br /&gt;
  _   (0x5f) --&amp;gt; \_ &lt;br /&gt;
  all other non-alphanumeric characters with ASCII values less than 256  --&amp;gt; \c&lt;br /&gt;
  where 'c' is the original non-alphanumeric character.&lt;br /&gt;
&lt;br /&gt;
This information is based on the MySQL Escape character information found here: http://mirror.yandex.ru/mirrors/ftp.mysql.com/doc/refman/5.0/en/string-syntax.html&lt;br /&gt;
&lt;br /&gt;
====SQL Server Escaping====&lt;br /&gt;
&lt;br /&gt;
We have not implemented the SQL Server escaping routine yet, but the following has good pointers to articles describing how to prevent SQL injection attacks on SQL server&lt;br /&gt;
* http://blogs.msdn.com/raulga/archive/2007/01/04/dynamic-sql-sql-injection.aspx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====DB2 Escaping====&lt;br /&gt;
This information is based on DB2 WebQuery special characters found here:  https://www-304.ibm.com/support/docview.wss?uid=nas14488c61e3223e8a78625744f00782983&lt;br /&gt;
as well as some information from Oracle's JDBC DB2 driver found here:&lt;br /&gt;
http://docs.oracle.com/cd/E12840_01/wls/docs103/jdbc_drivers/sqlescape.html&lt;br /&gt;
&lt;br /&gt;
Information in regards to differences between several DB2 Universal drivers can be found here:  http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/rjvjcsqc.htm&lt;br /&gt;
&lt;br /&gt;
===Hex-encoding all input===&lt;br /&gt;
&lt;br /&gt;
A somewhat special case of escaping is the process of hex-encode the entire string received from the user (this can be seen as escaping every character).  The web application should hex-encode the user input before including it to the SQL statement.  The SQL statement should take into account this fact, and accordingly compare the data. For example, if we have to look up a record matching a sessionID, and the user transmitted the string abc123 as session ID, the select statement would be:&lt;br /&gt;
&lt;br /&gt;
    SELECT ... FROM session&lt;br /&gt;
    WHERE hex_encode (sessionID) = '616263313233'&lt;br /&gt;
&lt;br /&gt;
(hex_encode should be replace by the particular facility for the database being used).  The string 606162313233 is the hex encoded version of the string received from the user (it is the sequence of hex values of the ASCII/UTF-8 codes of the user data).&lt;br /&gt;
&lt;br /&gt;
If an attacker were to transmit a string containing a single-quote character followed by their attempt to inject SQL code, the constructed SQL statement will only look like:&lt;br /&gt;
&lt;br /&gt;
    WHERE hex_encode ( ... ) = '2720 ... '&lt;br /&gt;
&lt;br /&gt;
27 being the ASCII code (in hex) of the single-quote, which is simply hex-encoded like any other character in the string.  The resulting SQL can only contain numeric digits and a to f letters, and never any special character that could enable an SQL injection.&lt;br /&gt;
&lt;br /&gt;
===Escaping SQLi in PHP===&lt;br /&gt;
&lt;br /&gt;
Use prepared statements and parameterized queries. These are SQL statements that are sent to and parsed by the database server separately from any parameters. This way it is impossible for an attacker to inject malicious SQL.&amp;lt;br&amp;gt;&lt;br /&gt;
You basically have two options to achieve this:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using [http://php.net/manual/en/book.pdo.php PDO] (for any supported database driver):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$stmt = $pdo-&amp;gt;prepare('SELECT * FROM employees WHERE name = :name');&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute(array('name' =&amp;gt; $name));&lt;br /&gt;
&lt;br /&gt;
foreach ($stmt as $row) {&lt;br /&gt;
    // do something with $row&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using [http://php.net/manual/en/book.mysqli.php MySQLi] (for MySQL):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$stmt = $dbConnection-&amp;gt;prepare('SELECT * FROM employees WHERE name = ?');&lt;br /&gt;
$stmt-&amp;gt;bind_param('s', $name);&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute();&lt;br /&gt;
&lt;br /&gt;
$result = $stmt-&amp;gt;get_result();&lt;br /&gt;
while ($row = $result-&amp;gt;fetch_assoc()) {&lt;br /&gt;
    // do something with $row&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you're connecting to a database other than MySQL, there is a driver-specific second option that you can refer to (e.g. pg_prepare() and pg_execute() for PostgreSQL). PDO is the universal option.&lt;br /&gt;
&lt;br /&gt;
= Additional Defenses =&lt;br /&gt;
&lt;br /&gt;
Beyond adopting one of the four primary defenses, we also recommend adopting all of these additional defenses in order to provide defense in depth. These additional defenses are:&lt;br /&gt;
&lt;br /&gt;
* '''Least Privilege'''&lt;br /&gt;
* '''White List Input Validation'''&lt;br /&gt;
&lt;br /&gt;
== Least Privilege ==&lt;br /&gt;
&lt;br /&gt;
To minimize the potential damage of a successful SQL injection attack, you should minimize the privileges assigned to every database account in your environment. Do not assign DBA or admin type access rights to your application accounts. We understand that this is easy, and everything just ‘works’ when you do it this way, but it is very dangerous. Start from the ground up to determine what access rights your application accounts require, rather than trying to figure out what access rights you need to take away. Make sure that accounts that only need read access are only granted read access to the tables they need access to. If an account only needs access to portions of a table, consider creating a view that limits access to that portion of the data and assigning the account access to the view instead, rather than the underlying table. Rarely, if ever, grant create or delete access to database accounts.&lt;br /&gt;
&lt;br /&gt;
If you adopt a policy where you use stored procedures everywhere, and don’t allow application accounts to directly execute their own queries, then restrict those accounts to only be able to execute the stored procedures they need. Don’t grant them any rights directly to the tables in the database.&lt;br /&gt;
&lt;br /&gt;
SQL injection is not the only threat to your database data. Attackers can simply change the parameter values from one of the legal values they are presented with, to a value that is unauthorized for them, but the application itself might be authorized to access. As such, minimizing the privileges granted to your application will reduce the likelihood of such unauthorized access attempts, even when an attacker is not trying to use SQL injection as part of their exploit.&lt;br /&gt;
&lt;br /&gt;
While you are at it, you should minimize the privileges of the operating system account that the DBMS runs under. Don't run your DBMS as root or system! Most DBMSs run out of the box with a very powerful system account. For example, MySQL runs as system on Windows by default! Change the DBMS's OS account to something more appropriate, with restricted privileges.&lt;br /&gt;
&lt;br /&gt;
=== Multiple DB Users ===&lt;br /&gt;
&lt;br /&gt;
The designer of web applications should not only avoid using the same owner/admin account in the web applications to connect to the database. Different DB users could be used for different web applications. In general, each separate web application that requires access to the database could have a designated database user account that the web-app will use to connect to the DB. That way, the designer of the application can have good granularity in the access control, thus reducing the privileges as much as possible. Each DB user will then have select access to what it needs only, and write-access as needed.&lt;br /&gt;
&lt;br /&gt;
As an example, a login page requires read access to the username and password fields of a table, but no write access of any form (no insert, update, or delete). However, the sign-up page certainly requires insert privilege to that table; this restriction can only be enforced if these web apps use different DB users to connect to the database.&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
&lt;br /&gt;
SQL views can further increase the granularity of access by limiting the read access to specific fields of a table or joins of tables. It could potentially have additional benefits: for example, suppose that the system is required (perhaps due to some specific legal requirements) to store the passwords of the users, instead of salted-hashed passwords.  The designer could use views to compensate for this limitation; revoke all access to the table (from all DB users except the owner/admin) and create a view that outputs the hash of the password field and not the field itself.  Any SQL injection attack that succeeds in stealing DB information will be restricted to stealing the hash of the passwords (could even be a keyed hash), since no DB user for any of the web applications has access to the table itself.&lt;br /&gt;
&lt;br /&gt;
== White List Input Validation ==&lt;br /&gt;
&lt;br /&gt;
In addition to being a primary defense when nothing else is possible (e.g., when a bind variable isn't legal), input validation can also be a secondary defense used to detect unauthorized input before it is passed to the SQL query. For more information please see the [[Input Validation Cheat Sheet]]. Proceed with caution here. Validated data is not necessarily safe to insert into SQL queries via string building.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''SQL Injection Attack Cheat Sheets'''&lt;br /&gt;
&lt;br /&gt;
The following articles describe how to exploit different kinds of SQL Injection Vulnerabilities on various platforms that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;SQL Injection Cheat Sheet&amp;quot; - http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/&lt;br /&gt;
* &amp;quot;Bypassing WAF's with SQLi&amp;quot; - [[SQL Injection Bypassing WAF]]&lt;br /&gt;
&lt;br /&gt;
'''Description of SQL Injection Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[SQL Injection]] Vulnerabilities&lt;br /&gt;
* OWASP article on [[Blind_SQL_Injection]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Avoid SQL Injection Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Guide Project|OWASP Developers Guide]] article on how to [[Guide to SQL Injection | Avoid SQL Injection]] Vulnerabilities&lt;br /&gt;
* OWASP Cheat Sheet that provides [[Query_Parameterization_Cheat_Sheet|numerous language specific examples of parameterized queries using both Prepared Statements and Stored Procedures]]&lt;br /&gt;
* [http://bobby-tables.com/ The Bobby Tables site (inspired by the XKCD webcomic) has numerous examples in different languages of parameterized Prepared Statements and Stored Procedures]&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for SQL Injection Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on how to [[Reviewing Code for SQL Injection|Review Code for SQL Injection]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for SQL Injection Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on how to [[Testing for SQL Injection (OWASP-DV-005)|Test for SQL Injection]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:wichers|Dave Wichers]] - dave.wichers[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
[[User:jmanico|Jim Manico]] - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Matt Seil - mseil[at]acm.org&amp;lt;br&amp;gt;&lt;br /&gt;
[https://owasp.org/index.php/Dhiraj_Mishra Dhiraj Mishra] - mishra.dhiraj[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
[[Category:Popular]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Reflected_File_Download&amp;diff=229153</id>
		<title>Reflected File Download</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Reflected_File_Download&amp;diff=229153"/>
				<updated>2017-04-26T09:38:41Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: disable URLs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{template: Attack}}&amp;lt;br&amp;gt;&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
&lt;br /&gt;
'''Reflected File Download''' is an attack combining [http://stackoverflow.com/questions/2163803/what-is-the-semicolon-reserved-for-in-urls URL path segments] (now deprecated) with web services vulnerable to [https://securitycafe.ro/2017/01/18/practical-jsonp-injection/ JSONP Injection] to deliver malware to end users.&lt;br /&gt;
&lt;br /&gt;
Let's assume we have a vulnerable API that reflects whatever we send to it (the URL was real apparently, now fixed):&lt;br /&gt;
&lt;br /&gt;
    hxxps://google.com/s?q=rfd%22||calc||&lt;br /&gt;
    {&amp;quot;results&amp;quot;:[&amp;quot;q&amp;quot;, &amp;quot;rfd\&amp;quot;||calc||&amp;quot;,&amp;quot;I love rfd&amp;quot;]}&lt;br /&gt;
&lt;br /&gt;
Now, this is normally harmless in a browser as it's JSON so it's not going to be rendered but the browser will rather offer to download the response as a file. Now here's the path segments come to help the attacker:&lt;br /&gt;
&lt;br /&gt;
    hxxps://google.com/s;/setup.bat;?q=rfd%22||calc||&lt;br /&gt;
&lt;br /&gt;
Everything between semicolons (`;/setup.bat;`) will be not sent to the web service, but instead the browser will interpret it as the file name... to save the API response. Now, a file called setup.bat will be downloaded and run without asking about dangers of running files downloaded from Internet (because it contains the word &amp;quot;setup&amp;quot; in its name). The contents will be interpreted as Windows batch file, and the `calc.exe` command will be run.&lt;br /&gt;
&lt;br /&gt;
Prevention:&lt;br /&gt;
&lt;br /&gt;
* sanitize your API's input (in this case they should just allow alphanumerics); escaping is not sufficient&lt;br /&gt;
* add `Content-Disposition: attachment; filename=&amp;quot;whatever.txt&amp;quot;` on APIs that are not going to be rendered; Google was missing the filename part which actually made the attack easier&lt;br /&gt;
* add `X-Content-Type-Options: nosniff` header to API responses&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* [https://www.blackhat.com/docs/eu-14/materials/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf Oren Hafif &amp;quot;Reflected File Download A New Web Attack Vector&amp;quot;, BlackHat EU 2014]&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&lt;br /&gt;
==Overview==&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Reflected_File_Download&amp;diff=229152</id>
		<title>Reflected File Download</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Reflected_File_Download&amp;diff=229152"/>
				<updated>2017-04-26T09:37:45Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: add basic information on RFD and references&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{template: Attack}}&amp;lt;br&amp;gt;&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
&lt;br /&gt;
'''Reflected File Download''' is an attack combining [http://stackoverflow.com/questions/2163803/what-is-the-semicolon-reserved-for-in-urls URL path segments] (now deprecated) with web services vulnerable to [https://securitycafe.ro/2017/01/18/practical-jsonp-injection/ JSONP Injection] to deliver malware to end users.&lt;br /&gt;
&lt;br /&gt;
Let's assume we have a vulnerable API that reflects whatever we send to it (the URL was real apparently, now fixed):&lt;br /&gt;
&lt;br /&gt;
    https://google.com/s?q=rfd%22||calc||&lt;br /&gt;
&lt;br /&gt;
    {&amp;quot;results&amp;quot;:[&amp;quot;q&amp;quot;, &amp;quot;rfd\&amp;quot;||calc||&amp;quot;,&amp;quot;I love rfd&amp;quot;]}&lt;br /&gt;
&lt;br /&gt;
Now, this is normally harmless in a browser as it's JSON so it's not going to be rendered but the browser will rather offer to download the response as a file. Now here's the path segments come to help the attacker:&lt;br /&gt;
&lt;br /&gt;
    https://google.com/s;/setup.bat;?q=rfd%22||calc||&lt;br /&gt;
&lt;br /&gt;
Everything between semicolons (`;/setup.bat;`) will be not sent to the web service, but instead the browser will interpret it as the file name... to save the API response. Now, a file called setup.bat will be downloaded and run without asking about dangers of running files downloaded from Internet (because it contains the word &amp;quot;setup&amp;quot; in its name). The contents will be interpreted as Windows batch file, and the `calc.exe` command will be run.&lt;br /&gt;
&lt;br /&gt;
Prevention:&lt;br /&gt;
&lt;br /&gt;
* sanitize your API's input (in this case they should just allow alphanumerics); escaping is not sufficient&lt;br /&gt;
* add `Content-Disposition: attachment; filename=&amp;quot;whatever.txt&amp;quot;` on APIs that are not going to be rendered; Google was missing the filename part which actually made the attack easier&lt;br /&gt;
* add `X-Content-Type-Options: nosniff` header to API responses&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* [https://www.blackhat.com/docs/eu-14/materials/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf Oren Hafif &amp;quot;Reflected File Download A New Web Attack Vector&amp;quot;, BlackHat EU 2014]&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&lt;br /&gt;
==Overview==&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SameSite&amp;diff=228931</id>
		<title>SameSite</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SameSite&amp;diff=228931"/>
				<updated>2017-04-21T14:44:32Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: add text from my article https://ipsec.pl/python/2017/understanding-http-cookie-samesite-flag-usage-scenarios.html&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
SameSite prevents the browser from sending this cookie along with cross-site requests. The main goal is mitigate the risk of cross-origin information leakage, and provides some protection against cross-site request forgery attacks. Possible values for the flag are &amp;lt;code&amp;gt;lax&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;strict&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;strict&amp;lt;/code&amp;gt; value will prevent the cookie from being sent by the browser to the target site in all cross-site browsing context, even when following a regular link. For example, for a GitHub-like website this would mean that if a logged-in user follows a link to a private GitHub project posted on a corporate discussion forum or email, GitHub will '''not''' receive the session cookie and the user will not be able to access the project.&lt;br /&gt;
&lt;br /&gt;
A bank website however most likely doesn't want to allow any transactional pages to be linked from external sites so the &amp;lt;code&amp;gt;strict&amp;lt;/code&amp;gt; flag would be most appropriate here.&lt;br /&gt;
&lt;br /&gt;
The default &amp;lt;code&amp;gt;lax&amp;lt;/code&amp;gt; value provides a reasonable balance between security and usability for websites that want to maintain user's logged-in session after the user arrives from an external link. In the above GitHub scenario, the session cookie would be allowed when following a regular link from an external website while blocking it in CSRF-prone request methods (e.g. &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
As of April 2017 the SameSite attribute is implemented in Chrome and Opera.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://tools.ietf.org/html/draft-west-first-party-cookies-07&lt;br /&gt;
* https://caniuse.com/#search=samesite&lt;br /&gt;
* http://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/&lt;br /&gt;
* https://chloe.re/2016/04/13/goodbye-csrf-samesite-to-the-rescue/&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228930</id>
		<title>Session Management Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228930"/>
				<updated>2017-04-21T14:38:08Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* HttpOnly Attribute */ SameSite Attribute&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
'''Web Authentication, Session Management, and Access Control''' &lt;br /&gt;
&lt;br /&gt;
A web session is a sequence of network HTTP request and response transactions associated to the same user. Modern and complex web applications require the retaining of information or status about each user for the duration of multiple requests. Therefore, sessions provide the ability to establish variables – such as access rights and localization settings – which will apply to each and every interaction a user has with the web application for the duration of the session. &lt;br /&gt;
&lt;br /&gt;
Web applications can create sessions to keep track of anonymous users after the very first user request. An example would be maintaining the user language preference. Additionally, web applications will make use of sessions once the user has authenticated. This ensures the ability to identify the user on any subsequent requests as well as being able to apply security access controls, authorized access to the user private data, and to increase the usability of the application. Therefore, current web applications can provide session capabilities both pre and post authentication. &lt;br /&gt;
&lt;br /&gt;
Once an authenticated session has been established, the session ID (or token) is temporarily equivalent to the strongest authentication method used by the application, such as username and password, passphrases, one-time passwords (OTP), client-based digital certificates, smartcards, or biometrics (such as fingerprint or eye retina). See the OWASP Authentication Cheat Sheet: [https://www.owasp.org/index.php/Authentication_Cheat_Sheet https://www.owasp.org/index.php/Authentication_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
HTTP is a stateless protocol (RFC2616 [5]), where each request and response pair is independent of other web interactions. Therefore, in order to introduce the concept of a session, it is required to implement session management capabilities that link both the authentication and access control (or authorization) modules commonly available in web applications: &lt;br /&gt;
&lt;br /&gt;
[[Image:Session-Management-Diagram Cheat-Sheet.png|center|Session-Management-Diagram Cheat-Sheet.png]] &amp;lt;br&amp;gt; The session ID or token binds the user authentication credentials (in the form of a user session) to the user HTTP traffic and the appropriate access controls enforced by the web application. The complexity of these three components (authentication, session management, and access control) in modern web applications, plus the fact that its implementation and binding resides on the web developer’s hands (as web development framework do not provide strict relationships between these modules), makes the implementation of a secure session management module very challenging. &lt;br /&gt;
&lt;br /&gt;
The disclosure, capture, prediction, brute force, or fixation of the session ID will lead to session hijacking (or sidejacking) attacks, where an attacker is able to fully impersonate a victim user in the web application. Attackers can perform two types of session hijacking attacks, targeted or generic. In a targeted attack, the attacker’s goal is to impersonate a specific (or privileged) web application victim user. For  generic attacks, the attacker’s goal is to impersonate (or get access as) any valid or legitimate user in the web application. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session ID Properties  =&lt;br /&gt;
&lt;br /&gt;
In order to keep the authenticated state and track the users progress within the web application, applications provide users with a session identifier (session ID or token) that is assigned at session creation time, and is shared and exchanged by the user and the web application for the duration of the session (it is sent on every HTTP request). The session ID is a “name=value” pair. &lt;br /&gt;
&lt;br /&gt;
With the goal of implementing secure session IDs, the generation of identifiers (IDs or tokens) must meet the following properties: &lt;br /&gt;
&lt;br /&gt;
== Session ID Name Fingerprinting  ==&lt;br /&gt;
&lt;br /&gt;
The name used by the session ID should not be extremely descriptive nor offer unnecessary details about the purpose and meaning of the ID. &lt;br /&gt;
&lt;br /&gt;
The session ID names used by the most common web application development frameworks can be easily fingerprinted [0], such as PHPSESSID (PHP), JSESSIONID (J2EE), CFID &amp;amp;amp; CFTOKEN (ColdFusion), ASP.NET_SessionId (ASP .NET), etc. Therefore, the session ID name can disclose the technologies and programming languages used by the web application. &lt;br /&gt;
&lt;br /&gt;
It is recommended to change the default session ID name of the web development framework to a generic name, such as “id”. &lt;br /&gt;
&lt;br /&gt;
== Session ID Length  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be long enough to prevent brute force attacks, where an attacker can go through the whole range of ID values and verify the existence of valid sessions. &lt;br /&gt;
&lt;br /&gt;
The session ID length must be at least 128 bits (16 bytes).&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID length of 128 bits is provided as a reference based on the assumptions made on the next section &amp;quot;Session ID Entropy&amp;quot;. However, this number should not be considered as an absolute minimum value, as other implementation factors might influence its strength. For example, there are well-known implementations, such as Microsoft ASP.NET, making use of 120-bit random numbers for its session IDs (represented by 20-character strings [10]) that can provide a very good effective entropy, and as a result, can be considered long enough to avoid guessing or brute force attacks.&lt;br /&gt;
&lt;br /&gt;
== Session ID Entropy  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be unpredictable (random enough) to prevent guessing attacks, where an attacker is able to guess or predict the ID of a valid session through statistical analysis techniques. For this purpose, a good PRNG (Pseudo Random Number Generator) must be used. &lt;br /&gt;
&lt;br /&gt;
The session ID value must provide at least 64 bits of entropy (if a good PRNG is used, this value is estimated to be half the length of the session ID).&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID entropy is really affected by other external and difficult to measure factors, such as the number of concurrent active sessions the web application commonly has, the absolute session expiration timeout, the amount of session ID guesses per second the attacker can make and the target web application can support, etc [2]. If a session ID with an entropy of 64 bits is used, it will take an attacker at least 292 years to successfully guess a valid session ID, assuming the attacker can try 10,000 guesses per second with 100,000 valid simultaneous sessions available in the web application [2]. &lt;br /&gt;
&lt;br /&gt;
== Session ID Content (or Value)  ==&lt;br /&gt;
&lt;br /&gt;
The session ID content (or value) must be meaningless to prevent information disclosure attacks, where an attacker is able to decode the contents of the ID and extract details of the user, the session, or the inner workings of the web application. &lt;br /&gt;
&lt;br /&gt;
The session ID must simply be an identifier on the client side, and its value must never include sensitive information (or PII). The meaning and business or application logic associated to the session ID must be stored on the server side, and specifically, in session objects or in a session management database or repository. The stored information can include the client IP address, User-Agent, e-mail, username, user ID, role, privilege level, access rights, language preferences, account ID, current state, last login, session timeouts, and other internal session details. If the session objects and properties contain sensitive information, such as credit card numbers, it is required to duly encrypt and protect the session management repository. &lt;br /&gt;
&lt;br /&gt;
It is recommended to create cryptographically strong session IDs through the usage of cryptographic hash functions such as SHA1 (160 bits). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management Implementation  =&lt;br /&gt;
&lt;br /&gt;
The session management implementation defines the exchange mechanism that will be used between the user and the web application to share and continuously exchange the session ID. There are multiple mechanisms available in HTTP to maintain session state within web applications, such as cookies (standard HTTP header), URL parameters (URL rewriting – RFC 2396), URL arguments on GET requests, body arguments on POST requests, such as hidden form fields (HTML forms), or proprietary HTTP headers. &lt;br /&gt;
&lt;br /&gt;
The preferred session ID exchange mechanism should allow defining advanced token properties, such as the token expiration date and time, or granular usage constraints. This is one of the reasons why cookies (RFCs 2109 &amp;amp;amp; 2965 &amp;amp;amp; 6265 [1]) are one of the most extensively used session ID exchange mechanisms, offering advanced capabilities not available in other methods. &lt;br /&gt;
&lt;br /&gt;
The usage of specific session ID exchange mechanisms, such as those where the ID is included in the URL, might disclose the session ID (in web links and logs, web browser history and bookmarks, the Referer header or search engines), as well as facilitate other attacks, such as the manipulation of the ID or session fixation attacks [3]. &lt;br /&gt;
&lt;br /&gt;
== Built-in Session Management Implementations  ==&lt;br /&gt;
&lt;br /&gt;
Web development frameworks, such as J2EE, ASP .NET, PHP, and others, provide their own session management features and associated implementation. It is recommended to use these built-in frameworks versus building a home made one from scratch, as they are used worldwide on multiple web environments and have been tested by the web application security and development communities over time. &lt;br /&gt;
&lt;br /&gt;
However, be advised that these frameworks have also presented vulnerabilities and weaknesses in the past, so it is always recommended to use the latest version available, that potentially fixes all the well-known vulnerabilities, as well as review and change the default configuration to enhance its security by following the recommendations described along this document. &lt;br /&gt;
&lt;br /&gt;
The storage capabilities or repository used by the session management mechanism to temporarily save the session IDs must be secure, protecting the session IDs against local or remote accidental disclosure or unauthorized access. &lt;br /&gt;
&lt;br /&gt;
== Used vs. Accepted Session ID Exchange Mechanisms  ==&lt;br /&gt;
&lt;br /&gt;
A web application should make use of cookies for session ID exchange management. If a user submits a session ID through a different exchange mechanism, such as a URL parameter, the web application should avoid accepting it as part of a defensive strategy to stop session fixation.&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': Even if a web application makes use of cookies as its default session ID exchange mechanism, it might accept other exchange mechanisms too. It is therefore required to confirm via thorough testing all the different mechanisms currently accepted by the web application when processing and managing session IDs, and limit the accepted session ID tracking mechanisms to just cookies. In the past, some web applications used URL parameters, or even switched from cookies to URL parameters (via automatic URL rewriting), if certain conditions are met (for example, the identification of web clients without support for cookies or not accepting cookies due to user privacy concerns).&lt;br /&gt;
&lt;br /&gt;
== Transport Layer Security  ==&lt;br /&gt;
&lt;br /&gt;
In order to protect the session ID exchange from active eavesdropping and passive disclosure in the network traffic, it is mandatory to use an encrypted HTTPS (SSL/TLS) connection for the entire web session, not only for the authentication process where the user credentials are exchanged. &lt;br /&gt;
&lt;br /&gt;
Additionally, the “Secure” cookie attribute (see below) must be used to ensure the session ID is only exchanged through an encrypted channel. The usage of an encrypted communication channel also protects the session against some session fixation attacks where the attacker is able to intercept and manipulate the web traffic to inject (or fix) the session ID on the victims web browser [4]. &lt;br /&gt;
&lt;br /&gt;
The following set of HTTPS (SSL/TLS) best practices are focused on protecting the session ID (specifically when cookies are used) and helping with the integration of HTTPS within the web application: &lt;br /&gt;
&lt;br /&gt;
*Web applications should never switch a given session from HTTP to HTTPS, or viceversa, as this will disclose the session ID in the clear through the network. &lt;br /&gt;
*Web applications should not mix encrypted and unencrypted contents (HTML pages, images, CSS, Javascript files, etc) on the same host (or even domain - see the “domain” cookie attribute), as the request of any web object over an unencrypted channel might disclose the session ID. &lt;br /&gt;
*Web applications, in general, should not offer public unencrypted contents and private encrypted contents from the same host. It is recommended to instead use two different hosts, such as www.example.com over HTTP (unencrypted) for the public contents, and secure.example.com over HTTPS (encrypted) for the private and sensitive contents (where sessions exist). The former host only has port TCP/80 open, while the later only has port TCP/443 open. &lt;br /&gt;
*Web applications should avoid the extremely common HTTP to HTTPS redirection on the home page (using a 30x HTTP response), as this single unprotected HTTP request/response exchange can be used by an attacker to gather (or fix) a valid session ID.&lt;br /&gt;
* Web applications should make use of “HTTP Strict Transport Security (HSTS)” (previously called STS) to enforce HTTPS connections.&lt;br /&gt;
&lt;br /&gt;
See the OWASP Transport Layer Protection Cheat Sheet: [https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
It is important to emphasize that SSL/TLS (HTTPS) does not protect against session ID prediction, brute force, client-side tampering or fixation. Yet, session ID disclosure and capture from the network traffic is one of the most prevalent attack vectors even today. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Cookies  =&lt;br /&gt;
&lt;br /&gt;
The session ID exchange mechanism based on cookies provides multiple security features in the form of cookie attributes that can be used to protect the exchange of the session ID: &lt;br /&gt;
&lt;br /&gt;
== Secure Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “Secure” cookie attribute instructs web browsers to only send the cookie through an encrypted HTTPS (SSL/TLS) connection. This session protection mechanism is mandatory to prevent the disclosure of the session ID through MitM (Man-in-the-Middle) attacks. It ensures that an attacker cannot simply capture the session ID from web browser traffic. &lt;br /&gt;
&lt;br /&gt;
Forcing the web application to only use HTTPS for its communication (even when port TCP/80, HTTP, is closed in the web application host) does not protect against session ID disclosure if the “Secure” cookie has not been set - the web browser can be deceived to disclose the session ID over an unencrypted HTTP connection. The attacker can intercept and manipulate the victim user traffic and inject an HTTP unencrypted reference to the web application that will force the web browser to submit the session ID in the clear.&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/SecureFlag SecureFlag]&lt;br /&gt;
&lt;br /&gt;
== HttpOnly Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “HttpOnly” cookie attribute instructs web browsers not to allow scripts (e.g. JavaScript or VBscript) an ability to access the cookies via the DOM document.cookie object. This session ID protection is mandatory to prevent session ID stealing through XSS attacks. &lt;br /&gt;
&lt;br /&gt;
See the OWASP XSS Prevention Cheat Sheet: [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet].&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/HttpOnly HttpOnly]&lt;br /&gt;
&lt;br /&gt;
== SameSite Attribute ==&lt;br /&gt;
SameSite allows a server define a cookie attribute making it impossible to the browser send this cookie along with cross-site requests. The main goal is mitigate the risk of cross-origin information leakage, and provides some protection against cross-site request forgery attacks.&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/SameSite SameSite]&lt;br /&gt;
&lt;br /&gt;
== Domain and Path Attributes  ==&lt;br /&gt;
&lt;br /&gt;
The “Domain” cookie attribute instructs web browsers to only send the cookie to the specified domain and all subdomains. If the attribute is not set, by default the cookie will only be sent to the origin server. The “Path” cookie attribute instructs web browsers to only send the cookie to the specified directory or subdirectories (or paths or resources) within the web application. If the attribute is not set, by default the cookie will only be sent for the directory (or path) of the resource requested and setting the cookie. &lt;br /&gt;
&lt;br /&gt;
It is recommended to use a narrow or restricted scope for these two attributes. In this way, the “Domain” attribute should not be set (restricting the cookie just to the origin server) and the “Path” attribute should be set as restrictive as possible to the web application path that makes use of the session ID. &lt;br /&gt;
&lt;br /&gt;
Setting the “Domain” attribute to a too permissive value, such as “example.com” allows an attacker to launch attacks on the session IDs between different hosts and web applications belonging to the same domain, known as cross-subdomain cookies. For example, vulnerabilities in www.example.com might allow an attacker to get access to the session IDs from secure.example.com. &lt;br /&gt;
&lt;br /&gt;
Additionally, it is recommended not to mix web applications of different security levels on the same domain. Vulnerabilities in one of the web applications would allow an attacker to set the session ID for a different web application on the same domain by using a permissive “Domain” attribute (such as “example.com”) which is a technique that can be used in session fixation attacks [4]. &lt;br /&gt;
&lt;br /&gt;
Although the “Path” attribute allows the isolation of session IDs between different web applications using different paths on the same host, it is highly recommended not to run different web applications (especially from different security levels or scopes) on the same host. Other methods can be used by these applications to access the session IDs, such as the “document.cookie” object. Also, any web application can set cookies for any path on that host. &lt;br /&gt;
&lt;br /&gt;
Cookies are vulnerable to DNS spoofing/hijacking/poisoning attacks, where an attacker can manipulate the DNS resolution to force the web browser to disclose the session ID for a given host or domain. &lt;br /&gt;
&lt;br /&gt;
== Expire and Max-Age Attributes  ==&lt;br /&gt;
&lt;br /&gt;
Session management mechanisms based on cookies can make use of two types of cookies, non-persistent (or session) cookies, and persistent cookies. If a cookie presents the “Max-Age” (that has preference over “Expires”) or “Expires” attributes, it will be considered a persistent cookie and will be stored on disk by the web browser based until the expiration time. Typically, session management capabilities to track users after authentication make use of non-persistent cookies. This forces the session to disappear from the client if the current web browser instance is closed. Therefore, it is highly recommended to use non-persistent cookies for session management purposes, so that the session ID does not remain on the web client cache for long periods of time, from where an attacker can obtain it. &lt;br /&gt;
&lt;br /&gt;
* Ensure that sensitive information is not comprised, by ensuring that sensitive information is not persistent / encrypting / stored on a need basis for the duration of the need&lt;br /&gt;
&lt;br /&gt;
* Ensure that unauthorized activities cannot take place via cookie manipulation&lt;br /&gt;
&lt;br /&gt;
* Ensure secure flag is set to prevent accidental transmission over “the wire” in a non-secure manner&lt;br /&gt;
&lt;br /&gt;
* Determine if all state transitions in the application code properly check for the cookies and enforce their use&lt;br /&gt;
&lt;br /&gt;
* Ensure entire cookie should be encrypted if sensitive data is persisted in the cookie&lt;br /&gt;
&lt;br /&gt;
* Define all cookies being used by the application, their name and why they are needed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session ID Life Cycle  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Generation and Verification: Permissive and Strict Session Management  ==&lt;br /&gt;
&lt;br /&gt;
There are two types of session management mechanisms for web applications, permissive and strict, related to session fixation vulnerabilities. The permissive mechanism allow the web application to initially accept any session ID value set by the user as valid, creating a new session for it, while the strict mechanism enforces that the web application will only accept session ID values that have been previously generated by the web application. &lt;br /&gt;
&lt;br /&gt;
The session tokens should be handled by the web server if possible or generated via a cryptographically secure random number generator.&lt;br /&gt;
&lt;br /&gt;
Although the most common mechanism in use today is the strict one (more secure). Developers must ensure that the web application does not use a permissive mechanism under certain circumstances. Web applications should never accept a session ID they have never generated, and in case of receiving one, they should generate and offer the user a new valid session ID. Additionally, this scenario should be detected as a suspicious activity and an alert should be generated. &lt;br /&gt;
&lt;br /&gt;
== Manage Session ID as Any Other User Input  ==&lt;br /&gt;
&lt;br /&gt;
Session IDs must be considered untrusted, as any other user input processed by the web application, and they must be thoroughly validated and verified. Depending on the session management mechanism used, the session ID will be received in a GET or POST parameter, in the URL or in an HTTP header (e.g. cookies). If web applications do not validate and filter out invalid session ID values before processing them, they can potentially be used to exploit other web vulnerabilities, such as SQL injection if the session IDs are stored on a relational database, or persistent XSS if the session IDs are stored and reflected back afterwards by the web application. &lt;br /&gt;
&lt;br /&gt;
== Renew the Session ID After Any Privilege Level Change  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be renewed or regenerated by the web application after any privilege level change within the associated user session. The most common scenario where the session ID regeneration is mandatory is during the authentication process, as the privilege level of the user changes from the unauthenticated (or anonymous) state to the authenticated state. Other common scenarios must also be considered, such as password changes, permission changes or switching from a regular user role to an administrator role within the web application. For all these web application critical pages, previous session IDs have to be ignored, a new session ID must be assigned to every new request received for the critical resource, and the old or previous session ID must be destroyed. &lt;br /&gt;
&lt;br /&gt;
The most common web development frameworks provide session functions and methods to renew the session ID, such as “request.getSession(true) &amp;amp;amp; HttpSession.invalidate()” (J2EE), “Session.Abandon() &amp;amp;amp; Response.Cookies.Add(new…)“ (ASP .NET), or “session_start() &amp;amp;amp; session_regenerate_id(true)” (PHP). &lt;br /&gt;
&lt;br /&gt;
The session ID regeneration is mandatory to prevent session fixation attacks [3], where an attacker sets the session ID on the victims user web browser instead of gathering the victims session ID, as in most of the other session-based attacks, and independently of using HTTP or HTTPS. This protection mitigates the impact of other web-based vulnerabilities that can also be used to launch session fixation attacks, such as HTTP response splitting or XSS [4]. &lt;br /&gt;
&lt;br /&gt;
A complementary recommendation is to use a different session ID or token name (or set of session IDs) pre and post authentication, so that the web application can keep track of anonymous users and authenticated users without the risk of exposing or binding the user session between both states. &lt;br /&gt;
&lt;br /&gt;
== Considerations When Using Multiple Cookies  ==&lt;br /&gt;
&lt;br /&gt;
If the web application uses cookies as the session ID exchange mechanism, and multiple cookies are set for a given session, the web application must verify all cookies (and enforce relationships between them) before allowing access to the user session. &lt;br /&gt;
&lt;br /&gt;
It is very common for web applications to set a user cookie pre-authentication over HTTP to keep track of unauthenticated (or anonymous) users. Once the user authenticates in the web application, a new post-authentication secure cookie is set over HTTPS, and a binding between both cookies and the user session is established. If the web application does not verify both cookies for authenticated sessions, an attacker can make use of the pre-authentication unprotected cookie to get access to the authenticated user session [4]. &lt;br /&gt;
&lt;br /&gt;
Web applications should try to avoid the same cookie name for different paths or domain scopes within the same web application, as this increases the complexity of the solution and potentially introduces scoping issues.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session Expiration  =&lt;br /&gt;
&lt;br /&gt;
In order to minimize the time period an attacker can launch attacks over active sessions and hijack them, it is mandatory to set expiration timeouts for every session, establishing the amount of time a session will remain active. Insufficient session expiration by the web application increases the exposure of other session-based attacks, as for the attacker to be able to reuse a valid session ID and hijack the associated session, it must still be active. &lt;br /&gt;
&lt;br /&gt;
The shorter the session interval is, the lesser the time an attacker has to use the valid session ID. The session expiration timeout values must be set accordingly with the purpose and nature of the web application, and balance security and usability, so that the user can comfortably complete the operations within the web application without his session frequently expiring. Both the idle and absolute timeout values are highly dependent on how critical the web application and its data are. Common idle timeouts ranges are 2-5 minutes for high-value applications and 15- 30 minutes for low risk applications. &lt;br /&gt;
&lt;br /&gt;
When a session expires, the web application must take active actions to invalidate the session on both sides, client and server. The latter is the most relevant and mandatory from a security perspective. &lt;br /&gt;
&lt;br /&gt;
For most session exchange mechanisms, client side actions to invalidate the session ID are based on clearing out the token value. For example, to invalidate a cookie it is recommended to provide an empty (or invalid) value for the session ID, and set the “Expires” (or “Max-Age”) attribute to a date from the past (in case a persistent cookie is being used): &lt;br /&gt;
&amp;lt;pre&amp;gt;Set-Cookie: id=; Expires=Friday, 17-May-03 18:45:00 GMT &amp;lt;/pre&amp;gt; &lt;br /&gt;
In order to close and invalidate the session on the server side, it is mandatory for the web application to take active actions when the session expires, or the user actively logs out, by using the functions and methods offered by the session management mechanisms, such as “HttpSession.invalidate()” (J2EE), “Session.Abandon()“ (ASP .NET) or “session_destroy()/unset()“ (PHP). &lt;br /&gt;
&lt;br /&gt;
== Automatic Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
=== Idle Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an idle or inactivity timeout. This timeout defines the amount of time a session will remain active in case there is no activity in the session, closing and invalidating the session upon the defined idle period since the last HTTP request received by the web application for a given session ID. &lt;br /&gt;
&lt;br /&gt;
The idle timeout limits the chances an attacker has to guess and use a valid session ID from another user. However, if the attacker is able to hijack a given session, the idle timeout does not limit the attacker’s actions, as he can generate activity on the session periodically to keep the session active for longer periods of time. &lt;br /&gt;
&lt;br /&gt;
Session timeout management and expiration must be enforced server-side. If the client is used to enforce the session timeout, for example using the session token or other client parameters to track time references (e.g. number of minutes since login time), an attacker could manipulate these to extend the session duration. &lt;br /&gt;
&lt;br /&gt;
=== Absolute Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an absolute timeout, regardless of session activity. This timeout defines the maximum amount of time a session can be active, closing and invalidating the session upon the defined absolute period since the given session was initially created by the web application. After invalidating the session, the user is forced to (re)authenticate again in the web application and establish a new session. &lt;br /&gt;
&lt;br /&gt;
The absolute session limits the amount of time an attacker can use a hijacked session and impersonate the victim user. &lt;br /&gt;
&lt;br /&gt;
=== Renewal Timeout  ===&lt;br /&gt;
&lt;br /&gt;
Alternatively, the web application can implement an additional renewal timeout after which the session ID is automatically renewed, in the middle of the user session, and independently of the session activity and, therefore, of the idle timeout. &lt;br /&gt;
&lt;br /&gt;
After a specific amount of time since the session was initially created, the web application can regenerate a new ID for the user session and try to set it, or renew it, on the client. The previous session ID value would still be valid for some time, accommodating a safety interval, before the client is aware of the new ID and starts using it. At that time, when the client switches to the new ID inside the current session, the application invalidates the previous ID.&lt;br /&gt;
&lt;br /&gt;
This scenario minimizes the amount of time a given session ID value, potentially obtained by an attacker, can be reused to hijack the user session, even when the victim user session is still active. The user session remains alive and open on the legitimate client, although its associated session ID value is transparently renewed periodically during the session duration, every time the renewal timeout expires. Therefore, the renewal timeout complements the idle and absolute timeouts, specially when the absolute timeout value extends significantly over time (e.g. it is an application requirement to keep the user sessions opened for long periods of time).&lt;br /&gt;
&lt;br /&gt;
Depending of the implementation, potentially there could be a race condition where the attacker with a still valid previous session ID sends a request before the victim user, right after the renewal timeout has just expired, and obtains first the value for the renewed session ID. At least in this scenario, the victim user might be aware of the attack as her session will be suddenly terminated because her associated session ID is not valid anymore.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Manual Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should provide mechanisms that allow security aware users to actively close their session once they have finished using the web application. &lt;br /&gt;
&lt;br /&gt;
=== Logout Button  ===&lt;br /&gt;
&lt;br /&gt;
Web applications must provide a visible an easily accessible logout (logoff, exit, or close session) button that is available on the web application header or menu and reachable from every web application resource and page, so that the user can manually close the session at any time. As described [[Session_Management_Cheat_Sheet#Session_Expiration|above]], the web application must invalidate the session at least on server side.&lt;br /&gt;
&lt;br /&gt;
'''NOTE''': Unfortunately, not all web applications facilitate users to close their current session. Thus, client-side enhancements such as the PopUp LogOut Firefox add-on [9] allow conscientious users to protect their sessions by helping to close them diligently.&lt;br /&gt;
&lt;br /&gt;
== Web Content Caching  ==&lt;br /&gt;
&lt;br /&gt;
Even after the session has been closed, it might be possible to access the private or sensitive data exchanged within the session through the web browser cache. Therefore, web applications must use restrictive cache directives for all the web traffic exchanged through HTTP and HTTPS, such as the “Cache-Control: no-cache,no-store” and “Pragma: no-cache” HTTP headers [5], and/or equivalent META tags on all or (at least) sensitive web pages. &lt;br /&gt;
&lt;br /&gt;
Independently of the cache policy defined by the web application, if caching web application contents is allowed, the session IDs must never be cached, so it is highly recommended to use the “Cache-Control: no-cache=&amp;quot;Set-Cookie, Set-Cookie2&amp;quot;” directive, to allow web clients to cache everything except the session ID. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Additional Client-Side Defenses for Session Management  =&lt;br /&gt;
&lt;br /&gt;
Web applications can complement the previously described session management defenses with additional countermeasures on the client side. Client-side protections, typically in the form of JavaScript checks and verifications, are not bullet proof and can easily be defeated by a skilled attacker, but can introduce another layer of defense that has to be bypassed by intruders. &lt;br /&gt;
&lt;br /&gt;
== Initial Login Timeout  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code in the login page to evaluate and measure the amount of time since the page was loaded and a session ID was granted. If a login attempt is tried after a specific amount of time, the client code can notify the user that the maximum amount of time to log in has passed and reload the login page, hence retrieving a new session ID. &lt;br /&gt;
&lt;br /&gt;
This extra protection mechanism tries to force the renewal of the session ID pre-authentication, avoiding scenarios where a previously used (or manually set) session ID is reused by the next victim using the same computer, for example, in session fixation attacks. &lt;br /&gt;
&lt;br /&gt;
== Force Session Logout On Web Browser Window Close Events  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code to capture all the web browser tab or window close (or even back) events and take the appropriate actions to close the current session before closing the web browser, emulating that the user has manually closed the session via the logout button. &lt;br /&gt;
&lt;br /&gt;
== Disable Web Browser Cross-Tab Sessions  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code once the user has logged in and a session has been established to force the user to re-authenticate if a new web browser tab or window is opened against the same web application. The web application does not want to allow multiple web browser tabs or windows to share the same session. Therefore, the application tries to force the web browser to not share the same session ID simultaneously between them. &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': This mechanism cannot be implemented if the session ID is exchanged through cookies, as cookies are shared by all web browser tabs/windows.&amp;amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
== Automatic Client Logout ==&lt;br /&gt;
&lt;br /&gt;
JavaScript code can be used by the web application in all (or critical) pages to automatically logout client sessions after the idle timeout expires, for example, by redirecting the user to the logout page (the same resource used by the logout button mentioned previously). &lt;br /&gt;
&lt;br /&gt;
The benefit of enhancing the server-side idle timeout functionality with client-side code is that the user can see that the session has finished due to inactivity, or even can be notified in advance that the session is about to expire through a count down timer and warning messages. This user-friendly approach helps to avoid loss of work in web pages that require extensive input data due to server-side silently expired sessions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Attacks Detection  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Guessing and Brute Force Detection  ==&lt;br /&gt;
&lt;br /&gt;
If an attacker tries to guess or brute force a valid session ID, he needs to launch multiple sequential requests against the target web application using different session IDs from a single (or set of) IP address(es). Additionally, if an attacker tries to analyze the predictability of the session ID (e.g. using statistical analysis), he needs to launch multiple sequential requests from a single (or set of) IP address(es) against the target web application to gather new valid session IDs. &lt;br /&gt;
&lt;br /&gt;
Web applications must be able to detect both scenarios based on the number of attempts to gather (or use) different session IDs and alert and/or block the offending IP address(es). &lt;br /&gt;
&lt;br /&gt;
== Detecting Session ID Anomalies  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should focus on detecting anomalies associated to the session ID, such as its manipulation. The OWASP AppSensor Project [7] provides a framework and methodology to implement built-in intrusion detection capabilities within web applications focused on the detection of anomalies and unexpected behaviors, in the form of detection points and response actions. Instead of using external protection layers, sometimes the business logic details and advanced intelligence are only available from inside the web application, where it is possible to establish multiple session related detection points, such as when an existing cookie is modified or deleted, a new cookie is added, the session ID from another user is reused, or when the user location or User-Agent changes in the middle of a session. &lt;br /&gt;
&lt;br /&gt;
== Binding the Session ID to Other User Properties  ==&lt;br /&gt;
&lt;br /&gt;
With the goal of detecting (and, in some scenarios, protecting against) user misbehaviors and session hijacking, it is highly recommended to bind the session ID to other user or client properties, such as the client IP address, User-Agent, or client-based digital certificate. If the web application detects any change or anomaly between these different properties in the middle of an established session, this is a very good indicator of session manipulation and hijacking attempts, and this simple fact can be used to alert and/or terminate the suspicious session. &lt;br /&gt;
&lt;br /&gt;
Although these properties cannot be used by web applications to trustingly defend against session attacks, they significantly increase the web application detection (and protection) capabilities. However, a skilled attacker can bypass these controls by reusing the same IP address assigned to the victim user by sharing the same network (very common in NAT environments, like Wi-Fi hotspots) or by using the same outbound web proxy (very common in corporate environments), or by manually modifying his User-Agent to look exactly as the victim users does. &lt;br /&gt;
&lt;br /&gt;
== Logging Sessions Life Cycle: Monitoring Creation, Usage, and Destruction of Session IDs  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should increase their logging capabilities by including information regarding the full life cycle of sessions. In particular, it is recommended to record session related events, such as the creation, renewal, and destruction of session IDs, as well as details about its usage within login and logout operations, privilege level changes within the session, timeout expiration, invalid session activities (when detected), and critical business operations during the session. &lt;br /&gt;
&lt;br /&gt;
The log details might include a timestamp, source IP address, web target resource requested (and involved in a session operation), HTTP headers (including the User-Agent and Referer), GET and POST parameters, error codes and messages, username (or user ID), plus the session ID (cookies, URL, GET, POST…). Sensitive data like the session ID should not be included in the logs in order to protect the session logs against session ID local or remote disclosure or unauthorized access. However, some kind of session-specific information must be logged into order to correlate log entries to specific sessions. It is recommended to log a salted-hash of the session ID instead of the session ID itself in order to allow for session-specific log correlation without exposing the session ID.&lt;br /&gt;
&lt;br /&gt;
In particular, web applications must thoroughly protect administrative interfaces that allow to manage all the current active sessions. Frequently these are used by support personnel to solve session related issues, or even general issues, by impersonating the user and looking at the web application as the user does.&lt;br /&gt;
&lt;br /&gt;
The session logs become one of the main web application intrusion detection data sources, and can also be used by intrusion protection systems to automatically terminate sessions and/or disable user accounts when (one or many) attacks are detected. If active protections are implemented, these defensive actions must be logged too.&lt;br /&gt;
&lt;br /&gt;
== Simultaneous Session Logons  ==&lt;br /&gt;
&lt;br /&gt;
It is the web application design decision to determine if multiple simultaneous logons from the same user are allowed from the same or from different client IP addresses. If the web application does not want to allow simultaneous session logons, it must take effective actions after each new authentication event, implicitly terminating the previously available session, or asking the user (through the old, new or both sessions) about the session that must remain active. &lt;br /&gt;
&lt;br /&gt;
It is recommended for web applications to add user capabilities that allow checking the details of active sessions at any time, monitor and alert the user about concurrent logons, provide user features to remotely terminate sessions manually, and track account activity history (logbook) by recording multiple client details such as IP address, User-Agent, login date and time, idle time, etc. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management WAF Protections  =&lt;br /&gt;
&lt;br /&gt;
There are situations where the web application source code is not available or cannot be modified, or when the changes required to implement the multiple security recommendations and best practices detailed above imply a full redesign of the web application architecture, and therefore, cannot be easily implemented in the short term. In these scenarios, or to complement the web application defenses, and with the goal of keeping the web application as secure as possible, it is recommended to use external protections such as Web Application Firewalls (WAFs) that can mitigate the session management threats already described. &lt;br /&gt;
&lt;br /&gt;
Web Application Firewalls offer detection and protection capabilities against session based attacks. On the one hand, it is trivial for WAFs to enforce the usage of security attributes on cookies, such as the “Secure” and “HttpOnly” flags, applying basic rewriting rules on the “Set-Cookie” header for all the web application responses that set a new cookie. On the other hand, more advanced capabilities can be implemented to allow the WAF to keep track of sessions, and the corresponding session IDs, and apply all kind of protections against session fixation (by renewing the session ID on the client-side when privilege changes are detected), enforcing sticky sessions (by verifying the relationship between the session ID and other client properties, like the IP address or User-Agent), or managing session expiration (by forcing both the client and the web application to finalize the session). &lt;br /&gt;
&lt;br /&gt;
The open-source ModSecurity WAF, plus the OWASP Core Rule Set [6], provide capabilities to detect and apply security cookie attributes, countermeasures against session fixation attacks, and session tracking features to enforce sticky sessions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
[0] '''OWASP Cookies Database. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_Cookies_Database &lt;br /&gt;
&lt;br /&gt;
[1] '''&amp;quot;HTTP State Management Mechanism&amp;quot;. RFC 6265. IETF.''' http://tools.ietf.org/html/rfc6265 &lt;br /&gt;
&lt;br /&gt;
[2] '''Insufficient Session-ID Length. OWASP.''' https://www.owasp.org/index.php/Insufficient_Session-ID_Length &lt;br /&gt;
&lt;br /&gt;
[3] '''Session Fixation. Mitja Kolšek. 2002.''' http://www.acrossecurity.com/papers/session_fixation.pdf &lt;br /&gt;
&lt;br /&gt;
[4] '''&amp;quot;SAP: Session (Fixation) Attacks and Protections (in Web Applications)&amp;quot;. Raul Siles. BlackHat EU 2011.''' &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-Slides.pdf &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-WP.pdf &lt;br /&gt;
&lt;br /&gt;
[5] '''&amp;quot;Hypertext Transfer Protocol -- HTTP/1.1&amp;quot;. RFC2616. IETF.''' http://tools.ietf.org/html/rfc2616 &lt;br /&gt;
&lt;br /&gt;
[6] '''OWASP ModSecurity Core Rule Set (CSR) Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project &lt;br /&gt;
&lt;br /&gt;
[7] '''OWASP AppSensor Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_AppSensor_Project &lt;br /&gt;
&lt;br /&gt;
[8] '''HttpOnly Session ID in URL and Page Body | Cross Site Scripting''' http://seckb.yehg.net/2012/06/httponly-session-id-in-url-and-page.html&lt;br /&gt;
&lt;br /&gt;
[9] '''PopUp LogOut Firefox add-on''' https://addons.mozilla.org/en-US/firefox/addon/popup-logout/ &amp;amp; http://popuplogout.iniqua.com&lt;br /&gt;
&lt;br /&gt;
[10] '''How and why session IDs are reused in ASP.NET''' https://support.microsoft.com/en-us/kb/899918&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Raul Siles (DinoSec) - raul[at]dinosec.com &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228929</id>
		<title>Session Management Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228929"/>
				<updated>2017-04-21T14:37:12Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* HttpOnly Attribute */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
'''Web Authentication, Session Management, and Access Control''' &lt;br /&gt;
&lt;br /&gt;
A web session is a sequence of network HTTP request and response transactions associated to the same user. Modern and complex web applications require the retaining of information or status about each user for the duration of multiple requests. Therefore, sessions provide the ability to establish variables – such as access rights and localization settings – which will apply to each and every interaction a user has with the web application for the duration of the session. &lt;br /&gt;
&lt;br /&gt;
Web applications can create sessions to keep track of anonymous users after the very first user request. An example would be maintaining the user language preference. Additionally, web applications will make use of sessions once the user has authenticated. This ensures the ability to identify the user on any subsequent requests as well as being able to apply security access controls, authorized access to the user private data, and to increase the usability of the application. Therefore, current web applications can provide session capabilities both pre and post authentication. &lt;br /&gt;
&lt;br /&gt;
Once an authenticated session has been established, the session ID (or token) is temporarily equivalent to the strongest authentication method used by the application, such as username and password, passphrases, one-time passwords (OTP), client-based digital certificates, smartcards, or biometrics (such as fingerprint or eye retina). See the OWASP Authentication Cheat Sheet: [https://www.owasp.org/index.php/Authentication_Cheat_Sheet https://www.owasp.org/index.php/Authentication_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
HTTP is a stateless protocol (RFC2616 [5]), where each request and response pair is independent of other web interactions. Therefore, in order to introduce the concept of a session, it is required to implement session management capabilities that link both the authentication and access control (or authorization) modules commonly available in web applications: &lt;br /&gt;
&lt;br /&gt;
[[Image:Session-Management-Diagram Cheat-Sheet.png|center|Session-Management-Diagram Cheat-Sheet.png]] &amp;lt;br&amp;gt; The session ID or token binds the user authentication credentials (in the form of a user session) to the user HTTP traffic and the appropriate access controls enforced by the web application. The complexity of these three components (authentication, session management, and access control) in modern web applications, plus the fact that its implementation and binding resides on the web developer’s hands (as web development framework do not provide strict relationships between these modules), makes the implementation of a secure session management module very challenging. &lt;br /&gt;
&lt;br /&gt;
The disclosure, capture, prediction, brute force, or fixation of the session ID will lead to session hijacking (or sidejacking) attacks, where an attacker is able to fully impersonate a victim user in the web application. Attackers can perform two types of session hijacking attacks, targeted or generic. In a targeted attack, the attacker’s goal is to impersonate a specific (or privileged) web application victim user. For  generic attacks, the attacker’s goal is to impersonate (or get access as) any valid or legitimate user in the web application. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session ID Properties  =&lt;br /&gt;
&lt;br /&gt;
In order to keep the authenticated state and track the users progress within the web application, applications provide users with a session identifier (session ID or token) that is assigned at session creation time, and is shared and exchanged by the user and the web application for the duration of the session (it is sent on every HTTP request). The session ID is a “name=value” pair. &lt;br /&gt;
&lt;br /&gt;
With the goal of implementing secure session IDs, the generation of identifiers (IDs or tokens) must meet the following properties: &lt;br /&gt;
&lt;br /&gt;
== Session ID Name Fingerprinting  ==&lt;br /&gt;
&lt;br /&gt;
The name used by the session ID should not be extremely descriptive nor offer unnecessary details about the purpose and meaning of the ID. &lt;br /&gt;
&lt;br /&gt;
The session ID names used by the most common web application development frameworks can be easily fingerprinted [0], such as PHPSESSID (PHP), JSESSIONID (J2EE), CFID &amp;amp;amp; CFTOKEN (ColdFusion), ASP.NET_SessionId (ASP .NET), etc. Therefore, the session ID name can disclose the technologies and programming languages used by the web application. &lt;br /&gt;
&lt;br /&gt;
It is recommended to change the default session ID name of the web development framework to a generic name, such as “id”. &lt;br /&gt;
&lt;br /&gt;
== Session ID Length  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be long enough to prevent brute force attacks, where an attacker can go through the whole range of ID values and verify the existence of valid sessions. &lt;br /&gt;
&lt;br /&gt;
The session ID length must be at least 128 bits (16 bytes).&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID length of 128 bits is provided as a reference based on the assumptions made on the next section &amp;quot;Session ID Entropy&amp;quot;. However, this number should not be considered as an absolute minimum value, as other implementation factors might influence its strength. For example, there are well-known implementations, such as Microsoft ASP.NET, making use of 120-bit random numbers for its session IDs (represented by 20-character strings [10]) that can provide a very good effective entropy, and as a result, can be considered long enough to avoid guessing or brute force attacks.&lt;br /&gt;
&lt;br /&gt;
== Session ID Entropy  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be unpredictable (random enough) to prevent guessing attacks, where an attacker is able to guess or predict the ID of a valid session through statistical analysis techniques. For this purpose, a good PRNG (Pseudo Random Number Generator) must be used. &lt;br /&gt;
&lt;br /&gt;
The session ID value must provide at least 64 bits of entropy (if a good PRNG is used, this value is estimated to be half the length of the session ID).&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID entropy is really affected by other external and difficult to measure factors, such as the number of concurrent active sessions the web application commonly has, the absolute session expiration timeout, the amount of session ID guesses per second the attacker can make and the target web application can support, etc [2]. If a session ID with an entropy of 64 bits is used, it will take an attacker at least 292 years to successfully guess a valid session ID, assuming the attacker can try 10,000 guesses per second with 100,000 valid simultaneous sessions available in the web application [2]. &lt;br /&gt;
&lt;br /&gt;
== Session ID Content (or Value)  ==&lt;br /&gt;
&lt;br /&gt;
The session ID content (or value) must be meaningless to prevent information disclosure attacks, where an attacker is able to decode the contents of the ID and extract details of the user, the session, or the inner workings of the web application. &lt;br /&gt;
&lt;br /&gt;
The session ID must simply be an identifier on the client side, and its value must never include sensitive information (or PII). The meaning and business or application logic associated to the session ID must be stored on the server side, and specifically, in session objects or in a session management database or repository. The stored information can include the client IP address, User-Agent, e-mail, username, user ID, role, privilege level, access rights, language preferences, account ID, current state, last login, session timeouts, and other internal session details. If the session objects and properties contain sensitive information, such as credit card numbers, it is required to duly encrypt and protect the session management repository. &lt;br /&gt;
&lt;br /&gt;
It is recommended to create cryptographically strong session IDs through the usage of cryptographic hash functions such as SHA1 (160 bits). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management Implementation  =&lt;br /&gt;
&lt;br /&gt;
The session management implementation defines the exchange mechanism that will be used between the user and the web application to share and continuously exchange the session ID. There are multiple mechanisms available in HTTP to maintain session state within web applications, such as cookies (standard HTTP header), URL parameters (URL rewriting – RFC 2396), URL arguments on GET requests, body arguments on POST requests, such as hidden form fields (HTML forms), or proprietary HTTP headers. &lt;br /&gt;
&lt;br /&gt;
The preferred session ID exchange mechanism should allow defining advanced token properties, such as the token expiration date and time, or granular usage constraints. This is one of the reasons why cookies (RFCs 2109 &amp;amp;amp; 2965 &amp;amp;amp; 6265 [1]) are one of the most extensively used session ID exchange mechanisms, offering advanced capabilities not available in other methods. &lt;br /&gt;
&lt;br /&gt;
The usage of specific session ID exchange mechanisms, such as those where the ID is included in the URL, might disclose the session ID (in web links and logs, web browser history and bookmarks, the Referer header or search engines), as well as facilitate other attacks, such as the manipulation of the ID or session fixation attacks [3]. &lt;br /&gt;
&lt;br /&gt;
== Built-in Session Management Implementations  ==&lt;br /&gt;
&lt;br /&gt;
Web development frameworks, such as J2EE, ASP .NET, PHP, and others, provide their own session management features and associated implementation. It is recommended to use these built-in frameworks versus building a home made one from scratch, as they are used worldwide on multiple web environments and have been tested by the web application security and development communities over time. &lt;br /&gt;
&lt;br /&gt;
However, be advised that these frameworks have also presented vulnerabilities and weaknesses in the past, so it is always recommended to use the latest version available, that potentially fixes all the well-known vulnerabilities, as well as review and change the default configuration to enhance its security by following the recommendations described along this document. &lt;br /&gt;
&lt;br /&gt;
The storage capabilities or repository used by the session management mechanism to temporarily save the session IDs must be secure, protecting the session IDs against local or remote accidental disclosure or unauthorized access. &lt;br /&gt;
&lt;br /&gt;
== Used vs. Accepted Session ID Exchange Mechanisms  ==&lt;br /&gt;
&lt;br /&gt;
A web application should make use of cookies for session ID exchange management. If a user submits a session ID through a different exchange mechanism, such as a URL parameter, the web application should avoid accepting it as part of a defensive strategy to stop session fixation.&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': Even if a web application makes use of cookies as its default session ID exchange mechanism, it might accept other exchange mechanisms too. It is therefore required to confirm via thorough testing all the different mechanisms currently accepted by the web application when processing and managing session IDs, and limit the accepted session ID tracking mechanisms to just cookies. In the past, some web applications used URL parameters, or even switched from cookies to URL parameters (via automatic URL rewriting), if certain conditions are met (for example, the identification of web clients without support for cookies or not accepting cookies due to user privacy concerns).&lt;br /&gt;
&lt;br /&gt;
== Transport Layer Security  ==&lt;br /&gt;
&lt;br /&gt;
In order to protect the session ID exchange from active eavesdropping and passive disclosure in the network traffic, it is mandatory to use an encrypted HTTPS (SSL/TLS) connection for the entire web session, not only for the authentication process where the user credentials are exchanged. &lt;br /&gt;
&lt;br /&gt;
Additionally, the “Secure” cookie attribute (see below) must be used to ensure the session ID is only exchanged through an encrypted channel. The usage of an encrypted communication channel also protects the session against some session fixation attacks where the attacker is able to intercept and manipulate the web traffic to inject (or fix) the session ID on the victims web browser [4]. &lt;br /&gt;
&lt;br /&gt;
The following set of HTTPS (SSL/TLS) best practices are focused on protecting the session ID (specifically when cookies are used) and helping with the integration of HTTPS within the web application: &lt;br /&gt;
&lt;br /&gt;
*Web applications should never switch a given session from HTTP to HTTPS, or viceversa, as this will disclose the session ID in the clear through the network. &lt;br /&gt;
*Web applications should not mix encrypted and unencrypted contents (HTML pages, images, CSS, Javascript files, etc) on the same host (or even domain - see the “domain” cookie attribute), as the request of any web object over an unencrypted channel might disclose the session ID. &lt;br /&gt;
*Web applications, in general, should not offer public unencrypted contents and private encrypted contents from the same host. It is recommended to instead use two different hosts, such as www.example.com over HTTP (unencrypted) for the public contents, and secure.example.com over HTTPS (encrypted) for the private and sensitive contents (where sessions exist). The former host only has port TCP/80 open, while the later only has port TCP/443 open. &lt;br /&gt;
*Web applications should avoid the extremely common HTTP to HTTPS redirection on the home page (using a 30x HTTP response), as this single unprotected HTTP request/response exchange can be used by an attacker to gather (or fix) a valid session ID.&lt;br /&gt;
* Web applications should make use of “HTTP Strict Transport Security (HSTS)” (previously called STS) to enforce HTTPS connections.&lt;br /&gt;
&lt;br /&gt;
See the OWASP Transport Layer Protection Cheat Sheet: [https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
It is important to emphasize that SSL/TLS (HTTPS) does not protect against session ID prediction, brute force, client-side tampering or fixation. Yet, session ID disclosure and capture from the network traffic is one of the most prevalent attack vectors even today. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Cookies  =&lt;br /&gt;
&lt;br /&gt;
The session ID exchange mechanism based on cookies provides multiple security features in the form of cookie attributes that can be used to protect the exchange of the session ID: &lt;br /&gt;
&lt;br /&gt;
== Secure Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “Secure” cookie attribute instructs web browsers to only send the cookie through an encrypted HTTPS (SSL/TLS) connection. This session protection mechanism is mandatory to prevent the disclosure of the session ID through MitM (Man-in-the-Middle) attacks. It ensures that an attacker cannot simply capture the session ID from web browser traffic. &lt;br /&gt;
&lt;br /&gt;
Forcing the web application to only use HTTPS for its communication (even when port TCP/80, HTTP, is closed in the web application host) does not protect against session ID disclosure if the “Secure” cookie has not been set - the web browser can be deceived to disclose the session ID over an unencrypted HTTP connection. The attacker can intercept and manipulate the victim user traffic and inject an HTTP unencrypted reference to the web application that will force the web browser to submit the session ID in the clear.&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/SecureFlag SecureFlag]&lt;br /&gt;
&lt;br /&gt;
== HttpOnly Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “HttpOnly” cookie attribute instructs web browsers not to allow scripts (e.g. JavaScript or VBscript) an ability to access the cookies via the DOM document.cookie object. This session ID protection is mandatory to prevent session ID stealing through XSS attacks. &lt;br /&gt;
&lt;br /&gt;
See the OWASP XSS Prevention Cheat Sheet: [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet].&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/HttpOnly HttpOnly]&lt;br /&gt;
&lt;br /&gt;
== Domain and Path Attributes  ==&lt;br /&gt;
&lt;br /&gt;
The “Domain” cookie attribute instructs web browsers to only send the cookie to the specified domain and all subdomains. If the attribute is not set, by default the cookie will only be sent to the origin server. The “Path” cookie attribute instructs web browsers to only send the cookie to the specified directory or subdirectories (or paths or resources) within the web application. If the attribute is not set, by default the cookie will only be sent for the directory (or path) of the resource requested and setting the cookie. &lt;br /&gt;
&lt;br /&gt;
It is recommended to use a narrow or restricted scope for these two attributes. In this way, the “Domain” attribute should not be set (restricting the cookie just to the origin server) and the “Path” attribute should be set as restrictive as possible to the web application path that makes use of the session ID. &lt;br /&gt;
&lt;br /&gt;
Setting the “Domain” attribute to a too permissive value, such as “example.com” allows an attacker to launch attacks on the session IDs between different hosts and web applications belonging to the same domain, known as cross-subdomain cookies. For example, vulnerabilities in www.example.com might allow an attacker to get access to the session IDs from secure.example.com. &lt;br /&gt;
&lt;br /&gt;
Additionally, it is recommended not to mix web applications of different security levels on the same domain. Vulnerabilities in one of the web applications would allow an attacker to set the session ID for a different web application on the same domain by using a permissive “Domain” attribute (such as “example.com”) which is a technique that can be used in session fixation attacks [4]. &lt;br /&gt;
&lt;br /&gt;
Although the “Path” attribute allows the isolation of session IDs between different web applications using different paths on the same host, it is highly recommended not to run different web applications (especially from different security levels or scopes) on the same host. Other methods can be used by these applications to access the session IDs, such as the “document.cookie” object. Also, any web application can set cookies for any path on that host. &lt;br /&gt;
&lt;br /&gt;
Cookies are vulnerable to DNS spoofing/hijacking/poisoning attacks, where an attacker can manipulate the DNS resolution to force the web browser to disclose the session ID for a given host or domain. &lt;br /&gt;
&lt;br /&gt;
== Expire and Max-Age Attributes  ==&lt;br /&gt;
&lt;br /&gt;
Session management mechanisms based on cookies can make use of two types of cookies, non-persistent (or session) cookies, and persistent cookies. If a cookie presents the “Max-Age” (that has preference over “Expires”) or “Expires” attributes, it will be considered a persistent cookie and will be stored on disk by the web browser based until the expiration time. Typically, session management capabilities to track users after authentication make use of non-persistent cookies. This forces the session to disappear from the client if the current web browser instance is closed. Therefore, it is highly recommended to use non-persistent cookies for session management purposes, so that the session ID does not remain on the web client cache for long periods of time, from where an attacker can obtain it. &lt;br /&gt;
&lt;br /&gt;
* Ensure that sensitive information is not comprised, by ensuring that sensitive information is not persistent / encrypting / stored on a need basis for the duration of the need&lt;br /&gt;
&lt;br /&gt;
* Ensure that unauthorized activities cannot take place via cookie manipulation&lt;br /&gt;
&lt;br /&gt;
* Ensure secure flag is set to prevent accidental transmission over “the wire” in a non-secure manner&lt;br /&gt;
&lt;br /&gt;
* Determine if all state transitions in the application code properly check for the cookies and enforce their use&lt;br /&gt;
&lt;br /&gt;
* Ensure entire cookie should be encrypted if sensitive data is persisted in the cookie&lt;br /&gt;
&lt;br /&gt;
* Define all cookies being used by the application, their name and why they are needed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session ID Life Cycle  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Generation and Verification: Permissive and Strict Session Management  ==&lt;br /&gt;
&lt;br /&gt;
There are two types of session management mechanisms for web applications, permissive and strict, related to session fixation vulnerabilities. The permissive mechanism allow the web application to initially accept any session ID value set by the user as valid, creating a new session for it, while the strict mechanism enforces that the web application will only accept session ID values that have been previously generated by the web application. &lt;br /&gt;
&lt;br /&gt;
The session tokens should be handled by the web server if possible or generated via a cryptographically secure random number generator.&lt;br /&gt;
&lt;br /&gt;
Although the most common mechanism in use today is the strict one (more secure). Developers must ensure that the web application does not use a permissive mechanism under certain circumstances. Web applications should never accept a session ID they have never generated, and in case of receiving one, they should generate and offer the user a new valid session ID. Additionally, this scenario should be detected as a suspicious activity and an alert should be generated. &lt;br /&gt;
&lt;br /&gt;
== Manage Session ID as Any Other User Input  ==&lt;br /&gt;
&lt;br /&gt;
Session IDs must be considered untrusted, as any other user input processed by the web application, and they must be thoroughly validated and verified. Depending on the session management mechanism used, the session ID will be received in a GET or POST parameter, in the URL or in an HTTP header (e.g. cookies). If web applications do not validate and filter out invalid session ID values before processing them, they can potentially be used to exploit other web vulnerabilities, such as SQL injection if the session IDs are stored on a relational database, or persistent XSS if the session IDs are stored and reflected back afterwards by the web application. &lt;br /&gt;
&lt;br /&gt;
== Renew the Session ID After Any Privilege Level Change  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be renewed or regenerated by the web application after any privilege level change within the associated user session. The most common scenario where the session ID regeneration is mandatory is during the authentication process, as the privilege level of the user changes from the unauthenticated (or anonymous) state to the authenticated state. Other common scenarios must also be considered, such as password changes, permission changes or switching from a regular user role to an administrator role within the web application. For all these web application critical pages, previous session IDs have to be ignored, a new session ID must be assigned to every new request received for the critical resource, and the old or previous session ID must be destroyed. &lt;br /&gt;
&lt;br /&gt;
The most common web development frameworks provide session functions and methods to renew the session ID, such as “request.getSession(true) &amp;amp;amp; HttpSession.invalidate()” (J2EE), “Session.Abandon() &amp;amp;amp; Response.Cookies.Add(new…)“ (ASP .NET), or “session_start() &amp;amp;amp; session_regenerate_id(true)” (PHP). &lt;br /&gt;
&lt;br /&gt;
The session ID regeneration is mandatory to prevent session fixation attacks [3], where an attacker sets the session ID on the victims user web browser instead of gathering the victims session ID, as in most of the other session-based attacks, and independently of using HTTP or HTTPS. This protection mitigates the impact of other web-based vulnerabilities that can also be used to launch session fixation attacks, such as HTTP response splitting or XSS [4]. &lt;br /&gt;
&lt;br /&gt;
A complementary recommendation is to use a different session ID or token name (or set of session IDs) pre and post authentication, so that the web application can keep track of anonymous users and authenticated users without the risk of exposing or binding the user session between both states. &lt;br /&gt;
&lt;br /&gt;
== Considerations When Using Multiple Cookies  ==&lt;br /&gt;
&lt;br /&gt;
If the web application uses cookies as the session ID exchange mechanism, and multiple cookies are set for a given session, the web application must verify all cookies (and enforce relationships between them) before allowing access to the user session. &lt;br /&gt;
&lt;br /&gt;
It is very common for web applications to set a user cookie pre-authentication over HTTP to keep track of unauthenticated (or anonymous) users. Once the user authenticates in the web application, a new post-authentication secure cookie is set over HTTPS, and a binding between both cookies and the user session is established. If the web application does not verify both cookies for authenticated sessions, an attacker can make use of the pre-authentication unprotected cookie to get access to the authenticated user session [4]. &lt;br /&gt;
&lt;br /&gt;
Web applications should try to avoid the same cookie name for different paths or domain scopes within the same web application, as this increases the complexity of the solution and potentially introduces scoping issues.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session Expiration  =&lt;br /&gt;
&lt;br /&gt;
In order to minimize the time period an attacker can launch attacks over active sessions and hijack them, it is mandatory to set expiration timeouts for every session, establishing the amount of time a session will remain active. Insufficient session expiration by the web application increases the exposure of other session-based attacks, as for the attacker to be able to reuse a valid session ID and hijack the associated session, it must still be active. &lt;br /&gt;
&lt;br /&gt;
The shorter the session interval is, the lesser the time an attacker has to use the valid session ID. The session expiration timeout values must be set accordingly with the purpose and nature of the web application, and balance security and usability, so that the user can comfortably complete the operations within the web application without his session frequently expiring. Both the idle and absolute timeout values are highly dependent on how critical the web application and its data are. Common idle timeouts ranges are 2-5 minutes for high-value applications and 15- 30 minutes for low risk applications. &lt;br /&gt;
&lt;br /&gt;
When a session expires, the web application must take active actions to invalidate the session on both sides, client and server. The latter is the most relevant and mandatory from a security perspective. &lt;br /&gt;
&lt;br /&gt;
For most session exchange mechanisms, client side actions to invalidate the session ID are based on clearing out the token value. For example, to invalidate a cookie it is recommended to provide an empty (or invalid) value for the session ID, and set the “Expires” (or “Max-Age”) attribute to a date from the past (in case a persistent cookie is being used): &lt;br /&gt;
&amp;lt;pre&amp;gt;Set-Cookie: id=; Expires=Friday, 17-May-03 18:45:00 GMT &amp;lt;/pre&amp;gt; &lt;br /&gt;
In order to close and invalidate the session on the server side, it is mandatory for the web application to take active actions when the session expires, or the user actively logs out, by using the functions and methods offered by the session management mechanisms, such as “HttpSession.invalidate()” (J2EE), “Session.Abandon()“ (ASP .NET) or “session_destroy()/unset()“ (PHP). &lt;br /&gt;
&lt;br /&gt;
== Automatic Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
=== Idle Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an idle or inactivity timeout. This timeout defines the amount of time a session will remain active in case there is no activity in the session, closing and invalidating the session upon the defined idle period since the last HTTP request received by the web application for a given session ID. &lt;br /&gt;
&lt;br /&gt;
The idle timeout limits the chances an attacker has to guess and use a valid session ID from another user. However, if the attacker is able to hijack a given session, the idle timeout does not limit the attacker’s actions, as he can generate activity on the session periodically to keep the session active for longer periods of time. &lt;br /&gt;
&lt;br /&gt;
Session timeout management and expiration must be enforced server-side. If the client is used to enforce the session timeout, for example using the session token or other client parameters to track time references (e.g. number of minutes since login time), an attacker could manipulate these to extend the session duration. &lt;br /&gt;
&lt;br /&gt;
=== Absolute Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an absolute timeout, regardless of session activity. This timeout defines the maximum amount of time a session can be active, closing and invalidating the session upon the defined absolute period since the given session was initially created by the web application. After invalidating the session, the user is forced to (re)authenticate again in the web application and establish a new session. &lt;br /&gt;
&lt;br /&gt;
The absolute session limits the amount of time an attacker can use a hijacked session and impersonate the victim user. &lt;br /&gt;
&lt;br /&gt;
=== Renewal Timeout  ===&lt;br /&gt;
&lt;br /&gt;
Alternatively, the web application can implement an additional renewal timeout after which the session ID is automatically renewed, in the middle of the user session, and independently of the session activity and, therefore, of the idle timeout. &lt;br /&gt;
&lt;br /&gt;
After a specific amount of time since the session was initially created, the web application can regenerate a new ID for the user session and try to set it, or renew it, on the client. The previous session ID value would still be valid for some time, accommodating a safety interval, before the client is aware of the new ID and starts using it. At that time, when the client switches to the new ID inside the current session, the application invalidates the previous ID.&lt;br /&gt;
&lt;br /&gt;
This scenario minimizes the amount of time a given session ID value, potentially obtained by an attacker, can be reused to hijack the user session, even when the victim user session is still active. The user session remains alive and open on the legitimate client, although its associated session ID value is transparently renewed periodically during the session duration, every time the renewal timeout expires. Therefore, the renewal timeout complements the idle and absolute timeouts, specially when the absolute timeout value extends significantly over time (e.g. it is an application requirement to keep the user sessions opened for long periods of time).&lt;br /&gt;
&lt;br /&gt;
Depending of the implementation, potentially there could be a race condition where the attacker with a still valid previous session ID sends a request before the victim user, right after the renewal timeout has just expired, and obtains first the value for the renewed session ID. At least in this scenario, the victim user might be aware of the attack as her session will be suddenly terminated because her associated session ID is not valid anymore.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Manual Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should provide mechanisms that allow security aware users to actively close their session once they have finished using the web application. &lt;br /&gt;
&lt;br /&gt;
=== Logout Button  ===&lt;br /&gt;
&lt;br /&gt;
Web applications must provide a visible an easily accessible logout (logoff, exit, or close session) button that is available on the web application header or menu and reachable from every web application resource and page, so that the user can manually close the session at any time. As described [[Session_Management_Cheat_Sheet#Session_Expiration|above]], the web application must invalidate the session at least on server side.&lt;br /&gt;
&lt;br /&gt;
'''NOTE''': Unfortunately, not all web applications facilitate users to close their current session. Thus, client-side enhancements such as the PopUp LogOut Firefox add-on [9] allow conscientious users to protect their sessions by helping to close them diligently.&lt;br /&gt;
&lt;br /&gt;
== Web Content Caching  ==&lt;br /&gt;
&lt;br /&gt;
Even after the session has been closed, it might be possible to access the private or sensitive data exchanged within the session through the web browser cache. Therefore, web applications must use restrictive cache directives for all the web traffic exchanged through HTTP and HTTPS, such as the “Cache-Control: no-cache,no-store” and “Pragma: no-cache” HTTP headers [5], and/or equivalent META tags on all or (at least) sensitive web pages. &lt;br /&gt;
&lt;br /&gt;
Independently of the cache policy defined by the web application, if caching web application contents is allowed, the session IDs must never be cached, so it is highly recommended to use the “Cache-Control: no-cache=&amp;quot;Set-Cookie, Set-Cookie2&amp;quot;” directive, to allow web clients to cache everything except the session ID. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Additional Client-Side Defenses for Session Management  =&lt;br /&gt;
&lt;br /&gt;
Web applications can complement the previously described session management defenses with additional countermeasures on the client side. Client-side protections, typically in the form of JavaScript checks and verifications, are not bullet proof and can easily be defeated by a skilled attacker, but can introduce another layer of defense that has to be bypassed by intruders. &lt;br /&gt;
&lt;br /&gt;
== Initial Login Timeout  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code in the login page to evaluate and measure the amount of time since the page was loaded and a session ID was granted. If a login attempt is tried after a specific amount of time, the client code can notify the user that the maximum amount of time to log in has passed and reload the login page, hence retrieving a new session ID. &lt;br /&gt;
&lt;br /&gt;
This extra protection mechanism tries to force the renewal of the session ID pre-authentication, avoiding scenarios where a previously used (or manually set) session ID is reused by the next victim using the same computer, for example, in session fixation attacks. &lt;br /&gt;
&lt;br /&gt;
== Force Session Logout On Web Browser Window Close Events  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code to capture all the web browser tab or window close (or even back) events and take the appropriate actions to close the current session before closing the web browser, emulating that the user has manually closed the session via the logout button. &lt;br /&gt;
&lt;br /&gt;
== Disable Web Browser Cross-Tab Sessions  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code once the user has logged in and a session has been established to force the user to re-authenticate if a new web browser tab or window is opened against the same web application. The web application does not want to allow multiple web browser tabs or windows to share the same session. Therefore, the application tries to force the web browser to not share the same session ID simultaneously between them. &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': This mechanism cannot be implemented if the session ID is exchanged through cookies, as cookies are shared by all web browser tabs/windows.&amp;amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
== Automatic Client Logout ==&lt;br /&gt;
&lt;br /&gt;
JavaScript code can be used by the web application in all (or critical) pages to automatically logout client sessions after the idle timeout expires, for example, by redirecting the user to the logout page (the same resource used by the logout button mentioned previously). &lt;br /&gt;
&lt;br /&gt;
The benefit of enhancing the server-side idle timeout functionality with client-side code is that the user can see that the session has finished due to inactivity, or even can be notified in advance that the session is about to expire through a count down timer and warning messages. This user-friendly approach helps to avoid loss of work in web pages that require extensive input data due to server-side silently expired sessions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Attacks Detection  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Guessing and Brute Force Detection  ==&lt;br /&gt;
&lt;br /&gt;
If an attacker tries to guess or brute force a valid session ID, he needs to launch multiple sequential requests against the target web application using different session IDs from a single (or set of) IP address(es). Additionally, if an attacker tries to analyze the predictability of the session ID (e.g. using statistical analysis), he needs to launch multiple sequential requests from a single (or set of) IP address(es) against the target web application to gather new valid session IDs. &lt;br /&gt;
&lt;br /&gt;
Web applications must be able to detect both scenarios based on the number of attempts to gather (or use) different session IDs and alert and/or block the offending IP address(es). &lt;br /&gt;
&lt;br /&gt;
== Detecting Session ID Anomalies  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should focus on detecting anomalies associated to the session ID, such as its manipulation. The OWASP AppSensor Project [7] provides a framework and methodology to implement built-in intrusion detection capabilities within web applications focused on the detection of anomalies and unexpected behaviors, in the form of detection points and response actions. Instead of using external protection layers, sometimes the business logic details and advanced intelligence are only available from inside the web application, where it is possible to establish multiple session related detection points, such as when an existing cookie is modified or deleted, a new cookie is added, the session ID from another user is reused, or when the user location or User-Agent changes in the middle of a session. &lt;br /&gt;
&lt;br /&gt;
== Binding the Session ID to Other User Properties  ==&lt;br /&gt;
&lt;br /&gt;
With the goal of detecting (and, in some scenarios, protecting against) user misbehaviors and session hijacking, it is highly recommended to bind the session ID to other user or client properties, such as the client IP address, User-Agent, or client-based digital certificate. If the web application detects any change or anomaly between these different properties in the middle of an established session, this is a very good indicator of session manipulation and hijacking attempts, and this simple fact can be used to alert and/or terminate the suspicious session. &lt;br /&gt;
&lt;br /&gt;
Although these properties cannot be used by web applications to trustingly defend against session attacks, they significantly increase the web application detection (and protection) capabilities. However, a skilled attacker can bypass these controls by reusing the same IP address assigned to the victim user by sharing the same network (very common in NAT environments, like Wi-Fi hotspots) or by using the same outbound web proxy (very common in corporate environments), or by manually modifying his User-Agent to look exactly as the victim users does. &lt;br /&gt;
&lt;br /&gt;
== Logging Sessions Life Cycle: Monitoring Creation, Usage, and Destruction of Session IDs  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should increase their logging capabilities by including information regarding the full life cycle of sessions. In particular, it is recommended to record session related events, such as the creation, renewal, and destruction of session IDs, as well as details about its usage within login and logout operations, privilege level changes within the session, timeout expiration, invalid session activities (when detected), and critical business operations during the session. &lt;br /&gt;
&lt;br /&gt;
The log details might include a timestamp, source IP address, web target resource requested (and involved in a session operation), HTTP headers (including the User-Agent and Referer), GET and POST parameters, error codes and messages, username (or user ID), plus the session ID (cookies, URL, GET, POST…). Sensitive data like the session ID should not be included in the logs in order to protect the session logs against session ID local or remote disclosure or unauthorized access. However, some kind of session-specific information must be logged into order to correlate log entries to specific sessions. It is recommended to log a salted-hash of the session ID instead of the session ID itself in order to allow for session-specific log correlation without exposing the session ID.&lt;br /&gt;
&lt;br /&gt;
In particular, web applications must thoroughly protect administrative interfaces that allow to manage all the current active sessions. Frequently these are used by support personnel to solve session related issues, or even general issues, by impersonating the user and looking at the web application as the user does.&lt;br /&gt;
&lt;br /&gt;
The session logs become one of the main web application intrusion detection data sources, and can also be used by intrusion protection systems to automatically terminate sessions and/or disable user accounts when (one or many) attacks are detected. If active protections are implemented, these defensive actions must be logged too.&lt;br /&gt;
&lt;br /&gt;
== Simultaneous Session Logons  ==&lt;br /&gt;
&lt;br /&gt;
It is the web application design decision to determine if multiple simultaneous logons from the same user are allowed from the same or from different client IP addresses. If the web application does not want to allow simultaneous session logons, it must take effective actions after each new authentication event, implicitly terminating the previously available session, or asking the user (through the old, new or both sessions) about the session that must remain active. &lt;br /&gt;
&lt;br /&gt;
It is recommended for web applications to add user capabilities that allow checking the details of active sessions at any time, monitor and alert the user about concurrent logons, provide user features to remotely terminate sessions manually, and track account activity history (logbook) by recording multiple client details such as IP address, User-Agent, login date and time, idle time, etc. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management WAF Protections  =&lt;br /&gt;
&lt;br /&gt;
There are situations where the web application source code is not available or cannot be modified, or when the changes required to implement the multiple security recommendations and best practices detailed above imply a full redesign of the web application architecture, and therefore, cannot be easily implemented in the short term. In these scenarios, or to complement the web application defenses, and with the goal of keeping the web application as secure as possible, it is recommended to use external protections such as Web Application Firewalls (WAFs) that can mitigate the session management threats already described. &lt;br /&gt;
&lt;br /&gt;
Web Application Firewalls offer detection and protection capabilities against session based attacks. On the one hand, it is trivial for WAFs to enforce the usage of security attributes on cookies, such as the “Secure” and “HttpOnly” flags, applying basic rewriting rules on the “Set-Cookie” header for all the web application responses that set a new cookie. On the other hand, more advanced capabilities can be implemented to allow the WAF to keep track of sessions, and the corresponding session IDs, and apply all kind of protections against session fixation (by renewing the session ID on the client-side when privilege changes are detected), enforcing sticky sessions (by verifying the relationship between the session ID and other client properties, like the IP address or User-Agent), or managing session expiration (by forcing both the client and the web application to finalize the session). &lt;br /&gt;
&lt;br /&gt;
The open-source ModSecurity WAF, plus the OWASP Core Rule Set [6], provide capabilities to detect and apply security cookie attributes, countermeasures against session fixation attacks, and session tracking features to enforce sticky sessions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
[0] '''OWASP Cookies Database. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_Cookies_Database &lt;br /&gt;
&lt;br /&gt;
[1] '''&amp;quot;HTTP State Management Mechanism&amp;quot;. RFC 6265. IETF.''' http://tools.ietf.org/html/rfc6265 &lt;br /&gt;
&lt;br /&gt;
[2] '''Insufficient Session-ID Length. OWASP.''' https://www.owasp.org/index.php/Insufficient_Session-ID_Length &lt;br /&gt;
&lt;br /&gt;
[3] '''Session Fixation. Mitja Kolšek. 2002.''' http://www.acrossecurity.com/papers/session_fixation.pdf &lt;br /&gt;
&lt;br /&gt;
[4] '''&amp;quot;SAP: Session (Fixation) Attacks and Protections (in Web Applications)&amp;quot;. Raul Siles. BlackHat EU 2011.''' &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-Slides.pdf &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-WP.pdf &lt;br /&gt;
&lt;br /&gt;
[5] '''&amp;quot;Hypertext Transfer Protocol -- HTTP/1.1&amp;quot;. RFC2616. IETF.''' http://tools.ietf.org/html/rfc2616 &lt;br /&gt;
&lt;br /&gt;
[6] '''OWASP ModSecurity Core Rule Set (CSR) Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project &lt;br /&gt;
&lt;br /&gt;
[7] '''OWASP AppSensor Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_AppSensor_Project &lt;br /&gt;
&lt;br /&gt;
[8] '''HttpOnly Session ID in URL and Page Body | Cross Site Scripting''' http://seckb.yehg.net/2012/06/httponly-session-id-in-url-and-page.html&lt;br /&gt;
&lt;br /&gt;
[9] '''PopUp LogOut Firefox add-on''' https://addons.mozilla.org/en-US/firefox/addon/popup-logout/ &amp;amp; http://popuplogout.iniqua.com&lt;br /&gt;
&lt;br /&gt;
[10] '''How and why session IDs are reused in ASP.NET''' https://support.microsoft.com/en-us/kb/899918&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Raul Siles (DinoSec) - raul[at]dinosec.com &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228928</id>
		<title>Session Management Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Session_Management_Cheat_Sheet&amp;diff=228928"/>
				<updated>2017-04-21T14:34:15Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Secure Attribute */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
'''Web Authentication, Session Management, and Access Control''' &lt;br /&gt;
&lt;br /&gt;
A web session is a sequence of network HTTP request and response transactions associated to the same user. Modern and complex web applications require the retaining of information or status about each user for the duration of multiple requests. Therefore, sessions provide the ability to establish variables – such as access rights and localization settings – which will apply to each and every interaction a user has with the web application for the duration of the session. &lt;br /&gt;
&lt;br /&gt;
Web applications can create sessions to keep track of anonymous users after the very first user request. An example would be maintaining the user language preference. Additionally, web applications will make use of sessions once the user has authenticated. This ensures the ability to identify the user on any subsequent requests as well as being able to apply security access controls, authorized access to the user private data, and to increase the usability of the application. Therefore, current web applications can provide session capabilities both pre and post authentication. &lt;br /&gt;
&lt;br /&gt;
Once an authenticated session has been established, the session ID (or token) is temporarily equivalent to the strongest authentication method used by the application, such as username and password, passphrases, one-time passwords (OTP), client-based digital certificates, smartcards, or biometrics (such as fingerprint or eye retina). See the OWASP Authentication Cheat Sheet: [https://www.owasp.org/index.php/Authentication_Cheat_Sheet https://www.owasp.org/index.php/Authentication_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
HTTP is a stateless protocol (RFC2616 [5]), where each request and response pair is independent of other web interactions. Therefore, in order to introduce the concept of a session, it is required to implement session management capabilities that link both the authentication and access control (or authorization) modules commonly available in web applications: &lt;br /&gt;
&lt;br /&gt;
[[Image:Session-Management-Diagram Cheat-Sheet.png|center|Session-Management-Diagram Cheat-Sheet.png]] &amp;lt;br&amp;gt; The session ID or token binds the user authentication credentials (in the form of a user session) to the user HTTP traffic and the appropriate access controls enforced by the web application. The complexity of these three components (authentication, session management, and access control) in modern web applications, plus the fact that its implementation and binding resides on the web developer’s hands (as web development framework do not provide strict relationships between these modules), makes the implementation of a secure session management module very challenging. &lt;br /&gt;
&lt;br /&gt;
The disclosure, capture, prediction, brute force, or fixation of the session ID will lead to session hijacking (or sidejacking) attacks, where an attacker is able to fully impersonate a victim user in the web application. Attackers can perform two types of session hijacking attacks, targeted or generic. In a targeted attack, the attacker’s goal is to impersonate a specific (or privileged) web application victim user. For  generic attacks, the attacker’s goal is to impersonate (or get access as) any valid or legitimate user in the web application. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session ID Properties  =&lt;br /&gt;
&lt;br /&gt;
In order to keep the authenticated state and track the users progress within the web application, applications provide users with a session identifier (session ID or token) that is assigned at session creation time, and is shared and exchanged by the user and the web application for the duration of the session (it is sent on every HTTP request). The session ID is a “name=value” pair. &lt;br /&gt;
&lt;br /&gt;
With the goal of implementing secure session IDs, the generation of identifiers (IDs or tokens) must meet the following properties: &lt;br /&gt;
&lt;br /&gt;
== Session ID Name Fingerprinting  ==&lt;br /&gt;
&lt;br /&gt;
The name used by the session ID should not be extremely descriptive nor offer unnecessary details about the purpose and meaning of the ID. &lt;br /&gt;
&lt;br /&gt;
The session ID names used by the most common web application development frameworks can be easily fingerprinted [0], such as PHPSESSID (PHP), JSESSIONID (J2EE), CFID &amp;amp;amp; CFTOKEN (ColdFusion), ASP.NET_SessionId (ASP .NET), etc. Therefore, the session ID name can disclose the technologies and programming languages used by the web application. &lt;br /&gt;
&lt;br /&gt;
It is recommended to change the default session ID name of the web development framework to a generic name, such as “id”. &lt;br /&gt;
&lt;br /&gt;
== Session ID Length  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be long enough to prevent brute force attacks, where an attacker can go through the whole range of ID values and verify the existence of valid sessions. &lt;br /&gt;
&lt;br /&gt;
The session ID length must be at least 128 bits (16 bytes).&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID length of 128 bits is provided as a reference based on the assumptions made on the next section &amp;quot;Session ID Entropy&amp;quot;. However, this number should not be considered as an absolute minimum value, as other implementation factors might influence its strength. For example, there are well-known implementations, such as Microsoft ASP.NET, making use of 120-bit random numbers for its session IDs (represented by 20-character strings [10]) that can provide a very good effective entropy, and as a result, can be considered long enough to avoid guessing or brute force attacks.&lt;br /&gt;
&lt;br /&gt;
== Session ID Entropy  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be unpredictable (random enough) to prevent guessing attacks, where an attacker is able to guess or predict the ID of a valid session through statistical analysis techniques. For this purpose, a good PRNG (Pseudo Random Number Generator) must be used. &lt;br /&gt;
&lt;br /&gt;
The session ID value must provide at least 64 bits of entropy (if a good PRNG is used, this value is estimated to be half the length of the session ID).&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': The session ID entropy is really affected by other external and difficult to measure factors, such as the number of concurrent active sessions the web application commonly has, the absolute session expiration timeout, the amount of session ID guesses per second the attacker can make and the target web application can support, etc [2]. If a session ID with an entropy of 64 bits is used, it will take an attacker at least 292 years to successfully guess a valid session ID, assuming the attacker can try 10,000 guesses per second with 100,000 valid simultaneous sessions available in the web application [2]. &lt;br /&gt;
&lt;br /&gt;
== Session ID Content (or Value)  ==&lt;br /&gt;
&lt;br /&gt;
The session ID content (or value) must be meaningless to prevent information disclosure attacks, where an attacker is able to decode the contents of the ID and extract details of the user, the session, or the inner workings of the web application. &lt;br /&gt;
&lt;br /&gt;
The session ID must simply be an identifier on the client side, and its value must never include sensitive information (or PII). The meaning and business or application logic associated to the session ID must be stored on the server side, and specifically, in session objects or in a session management database or repository. The stored information can include the client IP address, User-Agent, e-mail, username, user ID, role, privilege level, access rights, language preferences, account ID, current state, last login, session timeouts, and other internal session details. If the session objects and properties contain sensitive information, such as credit card numbers, it is required to duly encrypt and protect the session management repository. &lt;br /&gt;
&lt;br /&gt;
It is recommended to create cryptographically strong session IDs through the usage of cryptographic hash functions such as SHA1 (160 bits). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management Implementation  =&lt;br /&gt;
&lt;br /&gt;
The session management implementation defines the exchange mechanism that will be used between the user and the web application to share and continuously exchange the session ID. There are multiple mechanisms available in HTTP to maintain session state within web applications, such as cookies (standard HTTP header), URL parameters (URL rewriting – RFC 2396), URL arguments on GET requests, body arguments on POST requests, such as hidden form fields (HTML forms), or proprietary HTTP headers. &lt;br /&gt;
&lt;br /&gt;
The preferred session ID exchange mechanism should allow defining advanced token properties, such as the token expiration date and time, or granular usage constraints. This is one of the reasons why cookies (RFCs 2109 &amp;amp;amp; 2965 &amp;amp;amp; 6265 [1]) are one of the most extensively used session ID exchange mechanisms, offering advanced capabilities not available in other methods. &lt;br /&gt;
&lt;br /&gt;
The usage of specific session ID exchange mechanisms, such as those where the ID is included in the URL, might disclose the session ID (in web links and logs, web browser history and bookmarks, the Referer header or search engines), as well as facilitate other attacks, such as the manipulation of the ID or session fixation attacks [3]. &lt;br /&gt;
&lt;br /&gt;
== Built-in Session Management Implementations  ==&lt;br /&gt;
&lt;br /&gt;
Web development frameworks, such as J2EE, ASP .NET, PHP, and others, provide their own session management features and associated implementation. It is recommended to use these built-in frameworks versus building a home made one from scratch, as they are used worldwide on multiple web environments and have been tested by the web application security and development communities over time. &lt;br /&gt;
&lt;br /&gt;
However, be advised that these frameworks have also presented vulnerabilities and weaknesses in the past, so it is always recommended to use the latest version available, that potentially fixes all the well-known vulnerabilities, as well as review and change the default configuration to enhance its security by following the recommendations described along this document. &lt;br /&gt;
&lt;br /&gt;
The storage capabilities or repository used by the session management mechanism to temporarily save the session IDs must be secure, protecting the session IDs against local or remote accidental disclosure or unauthorized access. &lt;br /&gt;
&lt;br /&gt;
== Used vs. Accepted Session ID Exchange Mechanisms  ==&lt;br /&gt;
&lt;br /&gt;
A web application should make use of cookies for session ID exchange management. If a user submits a session ID through a different exchange mechanism, such as a URL parameter, the web application should avoid accepting it as part of a defensive strategy to stop session fixation.&lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': Even if a web application makes use of cookies as its default session ID exchange mechanism, it might accept other exchange mechanisms too. It is therefore required to confirm via thorough testing all the different mechanisms currently accepted by the web application when processing and managing session IDs, and limit the accepted session ID tracking mechanisms to just cookies. In the past, some web applications used URL parameters, or even switched from cookies to URL parameters (via automatic URL rewriting), if certain conditions are met (for example, the identification of web clients without support for cookies or not accepting cookies due to user privacy concerns).&lt;br /&gt;
&lt;br /&gt;
== Transport Layer Security  ==&lt;br /&gt;
&lt;br /&gt;
In order to protect the session ID exchange from active eavesdropping and passive disclosure in the network traffic, it is mandatory to use an encrypted HTTPS (SSL/TLS) connection for the entire web session, not only for the authentication process where the user credentials are exchanged. &lt;br /&gt;
&lt;br /&gt;
Additionally, the “Secure” cookie attribute (see below) must be used to ensure the session ID is only exchanged through an encrypted channel. The usage of an encrypted communication channel also protects the session against some session fixation attacks where the attacker is able to intercept and manipulate the web traffic to inject (or fix) the session ID on the victims web browser [4]. &lt;br /&gt;
&lt;br /&gt;
The following set of HTTPS (SSL/TLS) best practices are focused on protecting the session ID (specifically when cookies are used) and helping with the integration of HTTPS within the web application: &lt;br /&gt;
&lt;br /&gt;
*Web applications should never switch a given session from HTTP to HTTPS, or viceversa, as this will disclose the session ID in the clear through the network. &lt;br /&gt;
*Web applications should not mix encrypted and unencrypted contents (HTML pages, images, CSS, Javascript files, etc) on the same host (or even domain - see the “domain” cookie attribute), as the request of any web object over an unencrypted channel might disclose the session ID. &lt;br /&gt;
*Web applications, in general, should not offer public unencrypted contents and private encrypted contents from the same host. It is recommended to instead use two different hosts, such as www.example.com over HTTP (unencrypted) for the public contents, and secure.example.com over HTTPS (encrypted) for the private and sensitive contents (where sessions exist). The former host only has port TCP/80 open, while the later only has port TCP/443 open. &lt;br /&gt;
*Web applications should avoid the extremely common HTTP to HTTPS redirection on the home page (using a 30x HTTP response), as this single unprotected HTTP request/response exchange can be used by an attacker to gather (or fix) a valid session ID.&lt;br /&gt;
* Web applications should make use of “HTTP Strict Transport Security (HSTS)” (previously called STS) to enforce HTTPS connections.&lt;br /&gt;
&lt;br /&gt;
See the OWASP Transport Layer Protection Cheat Sheet: [https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
It is important to emphasize that SSL/TLS (HTTPS) does not protect against session ID prediction, brute force, client-side tampering or fixation. Yet, session ID disclosure and capture from the network traffic is one of the most prevalent attack vectors even today. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Cookies  =&lt;br /&gt;
&lt;br /&gt;
The session ID exchange mechanism based on cookies provides multiple security features in the form of cookie attributes that can be used to protect the exchange of the session ID: &lt;br /&gt;
&lt;br /&gt;
== Secure Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “Secure” cookie attribute instructs web browsers to only send the cookie through an encrypted HTTPS (SSL/TLS) connection. This session protection mechanism is mandatory to prevent the disclosure of the session ID through MitM (Man-in-the-Middle) attacks. It ensures that an attacker cannot simply capture the session ID from web browser traffic. &lt;br /&gt;
&lt;br /&gt;
Forcing the web application to only use HTTPS for its communication (even when port TCP/80, HTTP, is closed in the web application host) does not protect against session ID disclosure if the “Secure” cookie has not been set - the web browser can be deceived to disclose the session ID over an unencrypted HTTP connection. The attacker can intercept and manipulate the victim user traffic and inject an HTTP unencrypted reference to the web application that will force the web browser to submit the session ID in the clear.&lt;br /&gt;
&lt;br /&gt;
See also: [https://www.owasp.org/index.php/SecureFlag SecureFlag]&lt;br /&gt;
&lt;br /&gt;
== HttpOnly Attribute  ==&lt;br /&gt;
&lt;br /&gt;
The “HttpOnly” cookie attribute instructs web browsers not to allow scripts (e.g. JavaScript or VBscript) an ability to access the cookies via the DOM document.cookie object. This session ID protection is mandatory to prevent session ID stealing through XSS attacks. &lt;br /&gt;
&lt;br /&gt;
See the OWASP XSS Prevention Cheat Sheet: [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet]. &lt;br /&gt;
&lt;br /&gt;
== Domain and Path Attributes  ==&lt;br /&gt;
&lt;br /&gt;
The “Domain” cookie attribute instructs web browsers to only send the cookie to the specified domain and all subdomains. If the attribute is not set, by default the cookie will only be sent to the origin server. The “Path” cookie attribute instructs web browsers to only send the cookie to the specified directory or subdirectories (or paths or resources) within the web application. If the attribute is not set, by default the cookie will only be sent for the directory (or path) of the resource requested and setting the cookie. &lt;br /&gt;
&lt;br /&gt;
It is recommended to use a narrow or restricted scope for these two attributes. In this way, the “Domain” attribute should not be set (restricting the cookie just to the origin server) and the “Path” attribute should be set as restrictive as possible to the web application path that makes use of the session ID. &lt;br /&gt;
&lt;br /&gt;
Setting the “Domain” attribute to a too permissive value, such as “example.com” allows an attacker to launch attacks on the session IDs between different hosts and web applications belonging to the same domain, known as cross-subdomain cookies. For example, vulnerabilities in www.example.com might allow an attacker to get access to the session IDs from secure.example.com. &lt;br /&gt;
&lt;br /&gt;
Additionally, it is recommended not to mix web applications of different security levels on the same domain. Vulnerabilities in one of the web applications would allow an attacker to set the session ID for a different web application on the same domain by using a permissive “Domain” attribute (such as “example.com”) which is a technique that can be used in session fixation attacks [4]. &lt;br /&gt;
&lt;br /&gt;
Although the “Path” attribute allows the isolation of session IDs between different web applications using different paths on the same host, it is highly recommended not to run different web applications (especially from different security levels or scopes) on the same host. Other methods can be used by these applications to access the session IDs, such as the “document.cookie” object. Also, any web application can set cookies for any path on that host. &lt;br /&gt;
&lt;br /&gt;
Cookies are vulnerable to DNS spoofing/hijacking/poisoning attacks, where an attacker can manipulate the DNS resolution to force the web browser to disclose the session ID for a given host or domain. &lt;br /&gt;
&lt;br /&gt;
== Expire and Max-Age Attributes  ==&lt;br /&gt;
&lt;br /&gt;
Session management mechanisms based on cookies can make use of two types of cookies, non-persistent (or session) cookies, and persistent cookies. If a cookie presents the “Max-Age” (that has preference over “Expires”) or “Expires” attributes, it will be considered a persistent cookie and will be stored on disk by the web browser based until the expiration time. Typically, session management capabilities to track users after authentication make use of non-persistent cookies. This forces the session to disappear from the client if the current web browser instance is closed. Therefore, it is highly recommended to use non-persistent cookies for session management purposes, so that the session ID does not remain on the web client cache for long periods of time, from where an attacker can obtain it. &lt;br /&gt;
&lt;br /&gt;
* Ensure that sensitive information is not comprised, by ensuring that sensitive information is not persistent / encrypting / stored on a need basis for the duration of the need&lt;br /&gt;
&lt;br /&gt;
* Ensure that unauthorized activities cannot take place via cookie manipulation&lt;br /&gt;
&lt;br /&gt;
* Ensure secure flag is set to prevent accidental transmission over “the wire” in a non-secure manner&lt;br /&gt;
&lt;br /&gt;
* Determine if all state transitions in the application code properly check for the cookies and enforce their use&lt;br /&gt;
&lt;br /&gt;
* Ensure entire cookie should be encrypted if sensitive data is persisted in the cookie&lt;br /&gt;
&lt;br /&gt;
* Define all cookies being used by the application, their name and why they are needed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session ID Life Cycle  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Generation and Verification: Permissive and Strict Session Management  ==&lt;br /&gt;
&lt;br /&gt;
There are two types of session management mechanisms for web applications, permissive and strict, related to session fixation vulnerabilities. The permissive mechanism allow the web application to initially accept any session ID value set by the user as valid, creating a new session for it, while the strict mechanism enforces that the web application will only accept session ID values that have been previously generated by the web application. &lt;br /&gt;
&lt;br /&gt;
The session tokens should be handled by the web server if possible or generated via a cryptographically secure random number generator.&lt;br /&gt;
&lt;br /&gt;
Although the most common mechanism in use today is the strict one (more secure). Developers must ensure that the web application does not use a permissive mechanism under certain circumstances. Web applications should never accept a session ID they have never generated, and in case of receiving one, they should generate and offer the user a new valid session ID. Additionally, this scenario should be detected as a suspicious activity and an alert should be generated. &lt;br /&gt;
&lt;br /&gt;
== Manage Session ID as Any Other User Input  ==&lt;br /&gt;
&lt;br /&gt;
Session IDs must be considered untrusted, as any other user input processed by the web application, and they must be thoroughly validated and verified. Depending on the session management mechanism used, the session ID will be received in a GET or POST parameter, in the URL or in an HTTP header (e.g. cookies). If web applications do not validate and filter out invalid session ID values before processing them, they can potentially be used to exploit other web vulnerabilities, such as SQL injection if the session IDs are stored on a relational database, or persistent XSS if the session IDs are stored and reflected back afterwards by the web application. &lt;br /&gt;
&lt;br /&gt;
== Renew the Session ID After Any Privilege Level Change  ==&lt;br /&gt;
&lt;br /&gt;
The session ID must be renewed or regenerated by the web application after any privilege level change within the associated user session. The most common scenario where the session ID regeneration is mandatory is during the authentication process, as the privilege level of the user changes from the unauthenticated (or anonymous) state to the authenticated state. Other common scenarios must also be considered, such as password changes, permission changes or switching from a regular user role to an administrator role within the web application. For all these web application critical pages, previous session IDs have to be ignored, a new session ID must be assigned to every new request received for the critical resource, and the old or previous session ID must be destroyed. &lt;br /&gt;
&lt;br /&gt;
The most common web development frameworks provide session functions and methods to renew the session ID, such as “request.getSession(true) &amp;amp;amp; HttpSession.invalidate()” (J2EE), “Session.Abandon() &amp;amp;amp; Response.Cookies.Add(new…)“ (ASP .NET), or “session_start() &amp;amp;amp; session_regenerate_id(true)” (PHP). &lt;br /&gt;
&lt;br /&gt;
The session ID regeneration is mandatory to prevent session fixation attacks [3], where an attacker sets the session ID on the victims user web browser instead of gathering the victims session ID, as in most of the other session-based attacks, and independently of using HTTP or HTTPS. This protection mitigates the impact of other web-based vulnerabilities that can also be used to launch session fixation attacks, such as HTTP response splitting or XSS [4]. &lt;br /&gt;
&lt;br /&gt;
A complementary recommendation is to use a different session ID or token name (or set of session IDs) pre and post authentication, so that the web application can keep track of anonymous users and authenticated users without the risk of exposing or binding the user session between both states. &lt;br /&gt;
&lt;br /&gt;
== Considerations When Using Multiple Cookies  ==&lt;br /&gt;
&lt;br /&gt;
If the web application uses cookies as the session ID exchange mechanism, and multiple cookies are set for a given session, the web application must verify all cookies (and enforce relationships between them) before allowing access to the user session. &lt;br /&gt;
&lt;br /&gt;
It is very common for web applications to set a user cookie pre-authentication over HTTP to keep track of unauthenticated (or anonymous) users. Once the user authenticates in the web application, a new post-authentication secure cookie is set over HTTPS, and a binding between both cookies and the user session is established. If the web application does not verify both cookies for authenticated sessions, an attacker can make use of the pre-authentication unprotected cookie to get access to the authenticated user session [4]. &lt;br /&gt;
&lt;br /&gt;
Web applications should try to avoid the same cookie name for different paths or domain scopes within the same web application, as this increases the complexity of the solution and potentially introduces scoping issues.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Session Expiration  =&lt;br /&gt;
&lt;br /&gt;
In order to minimize the time period an attacker can launch attacks over active sessions and hijack them, it is mandatory to set expiration timeouts for every session, establishing the amount of time a session will remain active. Insufficient session expiration by the web application increases the exposure of other session-based attacks, as for the attacker to be able to reuse a valid session ID and hijack the associated session, it must still be active. &lt;br /&gt;
&lt;br /&gt;
The shorter the session interval is, the lesser the time an attacker has to use the valid session ID. The session expiration timeout values must be set accordingly with the purpose and nature of the web application, and balance security and usability, so that the user can comfortably complete the operations within the web application without his session frequently expiring. Both the idle and absolute timeout values are highly dependent on how critical the web application and its data are. Common idle timeouts ranges are 2-5 minutes for high-value applications and 15- 30 minutes for low risk applications. &lt;br /&gt;
&lt;br /&gt;
When a session expires, the web application must take active actions to invalidate the session on both sides, client and server. The latter is the most relevant and mandatory from a security perspective. &lt;br /&gt;
&lt;br /&gt;
For most session exchange mechanisms, client side actions to invalidate the session ID are based on clearing out the token value. For example, to invalidate a cookie it is recommended to provide an empty (or invalid) value for the session ID, and set the “Expires” (or “Max-Age”) attribute to a date from the past (in case a persistent cookie is being used): &lt;br /&gt;
&amp;lt;pre&amp;gt;Set-Cookie: id=; Expires=Friday, 17-May-03 18:45:00 GMT &amp;lt;/pre&amp;gt; &lt;br /&gt;
In order to close and invalidate the session on the server side, it is mandatory for the web application to take active actions when the session expires, or the user actively logs out, by using the functions and methods offered by the session management mechanisms, such as “HttpSession.invalidate()” (J2EE), “Session.Abandon()“ (ASP .NET) or “session_destroy()/unset()“ (PHP). &lt;br /&gt;
&lt;br /&gt;
== Automatic Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
=== Idle Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an idle or inactivity timeout. This timeout defines the amount of time a session will remain active in case there is no activity in the session, closing and invalidating the session upon the defined idle period since the last HTTP request received by the web application for a given session ID. &lt;br /&gt;
&lt;br /&gt;
The idle timeout limits the chances an attacker has to guess and use a valid session ID from another user. However, if the attacker is able to hijack a given session, the idle timeout does not limit the attacker’s actions, as he can generate activity on the session periodically to keep the session active for longer periods of time. &lt;br /&gt;
&lt;br /&gt;
Session timeout management and expiration must be enforced server-side. If the client is used to enforce the session timeout, for example using the session token or other client parameters to track time references (e.g. number of minutes since login time), an attacker could manipulate these to extend the session duration. &lt;br /&gt;
&lt;br /&gt;
=== Absolute Timeout  ===&lt;br /&gt;
&lt;br /&gt;
All sessions should implement an absolute timeout, regardless of session activity. This timeout defines the maximum amount of time a session can be active, closing and invalidating the session upon the defined absolute period since the given session was initially created by the web application. After invalidating the session, the user is forced to (re)authenticate again in the web application and establish a new session. &lt;br /&gt;
&lt;br /&gt;
The absolute session limits the amount of time an attacker can use a hijacked session and impersonate the victim user. &lt;br /&gt;
&lt;br /&gt;
=== Renewal Timeout  ===&lt;br /&gt;
&lt;br /&gt;
Alternatively, the web application can implement an additional renewal timeout after which the session ID is automatically renewed, in the middle of the user session, and independently of the session activity and, therefore, of the idle timeout. &lt;br /&gt;
&lt;br /&gt;
After a specific amount of time since the session was initially created, the web application can regenerate a new ID for the user session and try to set it, or renew it, on the client. The previous session ID value would still be valid for some time, accommodating a safety interval, before the client is aware of the new ID and starts using it. At that time, when the client switches to the new ID inside the current session, the application invalidates the previous ID.&lt;br /&gt;
&lt;br /&gt;
This scenario minimizes the amount of time a given session ID value, potentially obtained by an attacker, can be reused to hijack the user session, even when the victim user session is still active. The user session remains alive and open on the legitimate client, although its associated session ID value is transparently renewed periodically during the session duration, every time the renewal timeout expires. Therefore, the renewal timeout complements the idle and absolute timeouts, specially when the absolute timeout value extends significantly over time (e.g. it is an application requirement to keep the user sessions opened for long periods of time).&lt;br /&gt;
&lt;br /&gt;
Depending of the implementation, potentially there could be a race condition where the attacker with a still valid previous session ID sends a request before the victim user, right after the renewal timeout has just expired, and obtains first the value for the renewed session ID. At least in this scenario, the victim user might be aware of the attack as her session will be suddenly terminated because her associated session ID is not valid anymore.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Manual Session Expiration  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should provide mechanisms that allow security aware users to actively close their session once they have finished using the web application. &lt;br /&gt;
&lt;br /&gt;
=== Logout Button  ===&lt;br /&gt;
&lt;br /&gt;
Web applications must provide a visible an easily accessible logout (logoff, exit, or close session) button that is available on the web application header or menu and reachable from every web application resource and page, so that the user can manually close the session at any time. As described [[Session_Management_Cheat_Sheet#Session_Expiration|above]], the web application must invalidate the session at least on server side.&lt;br /&gt;
&lt;br /&gt;
'''NOTE''': Unfortunately, not all web applications facilitate users to close their current session. Thus, client-side enhancements such as the PopUp LogOut Firefox add-on [9] allow conscientious users to protect their sessions by helping to close them diligently.&lt;br /&gt;
&lt;br /&gt;
== Web Content Caching  ==&lt;br /&gt;
&lt;br /&gt;
Even after the session has been closed, it might be possible to access the private or sensitive data exchanged within the session through the web browser cache. Therefore, web applications must use restrictive cache directives for all the web traffic exchanged through HTTP and HTTPS, such as the “Cache-Control: no-cache,no-store” and “Pragma: no-cache” HTTP headers [5], and/or equivalent META tags on all or (at least) sensitive web pages. &lt;br /&gt;
&lt;br /&gt;
Independently of the cache policy defined by the web application, if caching web application contents is allowed, the session IDs must never be cached, so it is highly recommended to use the “Cache-Control: no-cache=&amp;quot;Set-Cookie, Set-Cookie2&amp;quot;” directive, to allow web clients to cache everything except the session ID. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Additional Client-Side Defenses for Session Management  =&lt;br /&gt;
&lt;br /&gt;
Web applications can complement the previously described session management defenses with additional countermeasures on the client side. Client-side protections, typically in the form of JavaScript checks and verifications, are not bullet proof and can easily be defeated by a skilled attacker, but can introduce another layer of defense that has to be bypassed by intruders. &lt;br /&gt;
&lt;br /&gt;
== Initial Login Timeout  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code in the login page to evaluate and measure the amount of time since the page was loaded and a session ID was granted. If a login attempt is tried after a specific amount of time, the client code can notify the user that the maximum amount of time to log in has passed and reload the login page, hence retrieving a new session ID. &lt;br /&gt;
&lt;br /&gt;
This extra protection mechanism tries to force the renewal of the session ID pre-authentication, avoiding scenarios where a previously used (or manually set) session ID is reused by the next victim using the same computer, for example, in session fixation attacks. &lt;br /&gt;
&lt;br /&gt;
== Force Session Logout On Web Browser Window Close Events  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code to capture all the web browser tab or window close (or even back) events and take the appropriate actions to close the current session before closing the web browser, emulating that the user has manually closed the session via the logout button. &lt;br /&gt;
&lt;br /&gt;
== Disable Web Browser Cross-Tab Sessions  ==&lt;br /&gt;
&lt;br /&gt;
Web applications can use JavaScript code once the user has logged in and a session has been established to force the user to re-authenticate if a new web browser tab or window is opened against the same web application. The web application does not want to allow multiple web browser tabs or windows to share the same session. Therefore, the application tries to force the web browser to not share the same session ID simultaneously between them. &lt;br /&gt;
&lt;br /&gt;
'''''NOTE''''': This mechanism cannot be implemented if the session ID is exchanged through cookies, as cookies are shared by all web browser tabs/windows.&amp;amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
== Automatic Client Logout ==&lt;br /&gt;
&lt;br /&gt;
JavaScript code can be used by the web application in all (or critical) pages to automatically logout client sessions after the idle timeout expires, for example, by redirecting the user to the logout page (the same resource used by the logout button mentioned previously). &lt;br /&gt;
&lt;br /&gt;
The benefit of enhancing the server-side idle timeout functionality with client-side code is that the user can see that the session has finished due to inactivity, or even can be notified in advance that the session is about to expire through a count down timer and warning messages. This user-friendly approach helps to avoid loss of work in web pages that require extensive input data due to server-side silently expired sessions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Attacks Detection  =&lt;br /&gt;
&lt;br /&gt;
== Session ID Guessing and Brute Force Detection  ==&lt;br /&gt;
&lt;br /&gt;
If an attacker tries to guess or brute force a valid session ID, he needs to launch multiple sequential requests against the target web application using different session IDs from a single (or set of) IP address(es). Additionally, if an attacker tries to analyze the predictability of the session ID (e.g. using statistical analysis), he needs to launch multiple sequential requests from a single (or set of) IP address(es) against the target web application to gather new valid session IDs. &lt;br /&gt;
&lt;br /&gt;
Web applications must be able to detect both scenarios based on the number of attempts to gather (or use) different session IDs and alert and/or block the offending IP address(es). &lt;br /&gt;
&lt;br /&gt;
== Detecting Session ID Anomalies  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should focus on detecting anomalies associated to the session ID, such as its manipulation. The OWASP AppSensor Project [7] provides a framework and methodology to implement built-in intrusion detection capabilities within web applications focused on the detection of anomalies and unexpected behaviors, in the form of detection points and response actions. Instead of using external protection layers, sometimes the business logic details and advanced intelligence are only available from inside the web application, where it is possible to establish multiple session related detection points, such as when an existing cookie is modified or deleted, a new cookie is added, the session ID from another user is reused, or when the user location or User-Agent changes in the middle of a session. &lt;br /&gt;
&lt;br /&gt;
== Binding the Session ID to Other User Properties  ==&lt;br /&gt;
&lt;br /&gt;
With the goal of detecting (and, in some scenarios, protecting against) user misbehaviors and session hijacking, it is highly recommended to bind the session ID to other user or client properties, such as the client IP address, User-Agent, or client-based digital certificate. If the web application detects any change or anomaly between these different properties in the middle of an established session, this is a very good indicator of session manipulation and hijacking attempts, and this simple fact can be used to alert and/or terminate the suspicious session. &lt;br /&gt;
&lt;br /&gt;
Although these properties cannot be used by web applications to trustingly defend against session attacks, they significantly increase the web application detection (and protection) capabilities. However, a skilled attacker can bypass these controls by reusing the same IP address assigned to the victim user by sharing the same network (very common in NAT environments, like Wi-Fi hotspots) or by using the same outbound web proxy (very common in corporate environments), or by manually modifying his User-Agent to look exactly as the victim users does. &lt;br /&gt;
&lt;br /&gt;
== Logging Sessions Life Cycle: Monitoring Creation, Usage, and Destruction of Session IDs  ==&lt;br /&gt;
&lt;br /&gt;
Web applications should increase their logging capabilities by including information regarding the full life cycle of sessions. In particular, it is recommended to record session related events, such as the creation, renewal, and destruction of session IDs, as well as details about its usage within login and logout operations, privilege level changes within the session, timeout expiration, invalid session activities (when detected), and critical business operations during the session. &lt;br /&gt;
&lt;br /&gt;
The log details might include a timestamp, source IP address, web target resource requested (and involved in a session operation), HTTP headers (including the User-Agent and Referer), GET and POST parameters, error codes and messages, username (or user ID), plus the session ID (cookies, URL, GET, POST…). Sensitive data like the session ID should not be included in the logs in order to protect the session logs against session ID local or remote disclosure or unauthorized access. However, some kind of session-specific information must be logged into order to correlate log entries to specific sessions. It is recommended to log a salted-hash of the session ID instead of the session ID itself in order to allow for session-specific log correlation without exposing the session ID.&lt;br /&gt;
&lt;br /&gt;
In particular, web applications must thoroughly protect administrative interfaces that allow to manage all the current active sessions. Frequently these are used by support personnel to solve session related issues, or even general issues, by impersonating the user and looking at the web application as the user does.&lt;br /&gt;
&lt;br /&gt;
The session logs become one of the main web application intrusion detection data sources, and can also be used by intrusion protection systems to automatically terminate sessions and/or disable user accounts when (one or many) attacks are detected. If active protections are implemented, these defensive actions must be logged too.&lt;br /&gt;
&lt;br /&gt;
== Simultaneous Session Logons  ==&lt;br /&gt;
&lt;br /&gt;
It is the web application design decision to determine if multiple simultaneous logons from the same user are allowed from the same or from different client IP addresses. If the web application does not want to allow simultaneous session logons, it must take effective actions after each new authentication event, implicitly terminating the previously available session, or asking the user (through the old, new or both sessions) about the session that must remain active. &lt;br /&gt;
&lt;br /&gt;
It is recommended for web applications to add user capabilities that allow checking the details of active sessions at any time, monitor and alert the user about concurrent logons, provide user features to remotely terminate sessions manually, and track account activity history (logbook) by recording multiple client details such as IP address, User-Agent, login date and time, idle time, etc. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Session Management WAF Protections  =&lt;br /&gt;
&lt;br /&gt;
There are situations where the web application source code is not available or cannot be modified, or when the changes required to implement the multiple security recommendations and best practices detailed above imply a full redesign of the web application architecture, and therefore, cannot be easily implemented in the short term. In these scenarios, or to complement the web application defenses, and with the goal of keeping the web application as secure as possible, it is recommended to use external protections such as Web Application Firewalls (WAFs) that can mitigate the session management threats already described. &lt;br /&gt;
&lt;br /&gt;
Web Application Firewalls offer detection and protection capabilities against session based attacks. On the one hand, it is trivial for WAFs to enforce the usage of security attributes on cookies, such as the “Secure” and “HttpOnly” flags, applying basic rewriting rules on the “Set-Cookie” header for all the web application responses that set a new cookie. On the other hand, more advanced capabilities can be implemented to allow the WAF to keep track of sessions, and the corresponding session IDs, and apply all kind of protections against session fixation (by renewing the session ID on the client-side when privilege changes are detected), enforcing sticky sessions (by verifying the relationship between the session ID and other client properties, like the IP address or User-Agent), or managing session expiration (by forcing both the client and the web application to finalize the session). &lt;br /&gt;
&lt;br /&gt;
The open-source ModSecurity WAF, plus the OWASP Core Rule Set [6], provide capabilities to detect and apply security cookie attributes, countermeasures against session fixation attacks, and session tracking features to enforce sticky sessions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
[0] '''OWASP Cookies Database. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_Cookies_Database &lt;br /&gt;
&lt;br /&gt;
[1] '''&amp;quot;HTTP State Management Mechanism&amp;quot;. RFC 6265. IETF.''' http://tools.ietf.org/html/rfc6265 &lt;br /&gt;
&lt;br /&gt;
[2] '''Insufficient Session-ID Length. OWASP.''' https://www.owasp.org/index.php/Insufficient_Session-ID_Length &lt;br /&gt;
&lt;br /&gt;
[3] '''Session Fixation. Mitja Kolšek. 2002.''' http://www.acrossecurity.com/papers/session_fixation.pdf &lt;br /&gt;
&lt;br /&gt;
[4] '''&amp;quot;SAP: Session (Fixation) Attacks and Protections (in Web Applications)&amp;quot;. Raul Siles. BlackHat EU 2011.''' &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-Slides.pdf &lt;br /&gt;
&lt;br /&gt;
https://media.blackhat.com/bh-eu-11/Raul_Siles/BlackHat_EU_2011_Siles_SAP_Session-WP.pdf &lt;br /&gt;
&lt;br /&gt;
[5] '''&amp;quot;Hypertext Transfer Protocol -- HTTP/1.1&amp;quot;. RFC2616. IETF.''' http://tools.ietf.org/html/rfc2616 &lt;br /&gt;
&lt;br /&gt;
[6] '''OWASP ModSecurity Core Rule Set (CSR) Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project &lt;br /&gt;
&lt;br /&gt;
[7] '''OWASP AppSensor Project. OWASP.''' https://www.owasp.org/index.php/Category:OWASP_AppSensor_Project &lt;br /&gt;
&lt;br /&gt;
[8] '''HttpOnly Session ID in URL and Page Body | Cross Site Scripting''' http://seckb.yehg.net/2012/06/httponly-session-id-in-url-and-page.html&lt;br /&gt;
&lt;br /&gt;
[9] '''PopUp LogOut Firefox add-on''' https://addons.mozilla.org/en-US/firefox/addon/popup-logout/ &amp;amp; http://popuplogout.iniqua.com&lt;br /&gt;
&lt;br /&gt;
[10] '''How and why session IDs are reused in ASP.NET''' https://support.microsoft.com/en-us/kb/899918&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Raul Siles (DinoSec) - raul[at]dinosec.com &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Password_Storage_Cheat_Sheet&amp;diff=228923</id>
		<title>Password Storage Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Password_Storage_Cheat_Sheet&amp;diff=228923"/>
				<updated>2017-04-21T11:10:32Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Leverage an adaptive one-way function */ formatting, update Argon2 wording&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
Media covers the theft of large collections of passwords on an almost daily basis. Media coverage of password theft discloses the password storage scheme, the weakness of that scheme, and often discloses a large population of compromised credentials that can affect multiple web sites or other applications. This article provides guidance on properly storing passwords, secret question responses, and similar credential information. Proper storage helps prevent theft, compromise, and malicious use of credentials.&lt;br /&gt;
Information systems store passwords and other credentials in a variety of protected forms. Common vulnerabilities allow the theft of protected passwords through attack vectors such as SQL Injection. Protected passwords can also be stolen from artifacts such as logs, dumps, and backups.&lt;br /&gt;
&lt;br /&gt;
Specific guidance herein protects against stored credential theft but the bulk of guidance aims to prevent credential compromise. That is, this guidance helps designs resist revealing users’ credentials or allowing system access in the event threats steal protected credential information. For more information and a thorough treatment of this topic, refer to the Secure Password Storage Threat Model here [http://goo.gl/Spvzs http://goo.gl/Spvzs].&lt;br /&gt;
&lt;br /&gt;
= Guidance =&lt;br /&gt;
&lt;br /&gt;
==  Do not limit the character set and set long max lengths for credentials ==&lt;br /&gt;
&lt;br /&gt;
Some organizations restrict the 1) types of special characters and 2) length of credentials accepted by systems because of their inability to prevent SQL Injection, Cross-site scripting, command-injection and other forms of injection attacks. These restrictions, while well-intentioned, facilitate certain simple attacks such as brute force.&lt;br /&gt;
&lt;br /&gt;
Do not allow short or no-length passwords and do not apply character set, or encoding restrictions on the entry or storage of credentials. Continue applying encoding, escaping, masking, outright omission, and other best practices to eliminate injection risks.&lt;br /&gt;
&lt;br /&gt;
A reasonable long password length is 160. Very long password policies can lead to DOS in certain circumstances[http://arstechnica.com/security/2013/09/long-passwords-are-good-but-too-much-length-can-be-bad-for-security/].&lt;br /&gt;
&lt;br /&gt;
== Use a cryptographically strong credential-specific salt ==&lt;br /&gt;
&lt;br /&gt;
A salt is fixed-length cryptographically-strong random value. Append credential data to the salt and use this as input to a protective function. Store the protected form appended to the salt as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;[protected form] = [salt] + protect([protection func], [salt] + [credential]);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Follow these practices to properly implement credential-specific salts:&lt;br /&gt;
&lt;br /&gt;
* Generate a unique salt upon creation of each stored credential (not just per user or system wide);&lt;br /&gt;
* Use cryptographically-strong random [*3] data;&lt;br /&gt;
* As storage permits, use a 32 byte or 64 byte salt (actual size dependent on protection function);&lt;br /&gt;
* Scheme security does not depend on hiding, splitting, or otherwise obscuring the salt.&lt;br /&gt;
&lt;br /&gt;
Salts serve two purposes: 1) prevent the protected form from revealing two identical credentials and 2) augment entropy fed to protecting function without relying on credential complexity. The second aims to make pre-computed lookup attacks [*2] on an individual credential and time-based attacks on a population intractable.&lt;br /&gt;
&lt;br /&gt;
== Impose infeasible verification on attacker ==&lt;br /&gt;
&lt;br /&gt;
The function used to protect stored credentials should balance attacker and defender verification. The defender needs an acceptable response time for verification of users’ credentials during peak use. However, the time required to map &amp;lt;code&amp;gt;&amp;lt;credential&amp;gt; → &amp;lt;protected form&amp;gt;&amp;lt;/code&amp;gt;  must remain beyond threats’ hardware (GPU, FPGA) and technique (dictionary-based, brute force, etc) capabilities.&lt;br /&gt;
&lt;br /&gt;
Two approaches facilitate this, each imperfectly.&lt;br /&gt;
&lt;br /&gt;
=== Leverage an adaptive one-way function ===&lt;br /&gt;
&lt;br /&gt;
Adaptive one-way functions compute a one-way (irreversible) transform. Each function allows configuration of ‘work factor’. Underlying mechanisms used to achieve irreversibility and govern work factors (such as time, space, and parallelism) vary between functions and remain unimportant to this discussion. &lt;br /&gt;
&lt;br /&gt;
Select:&lt;br /&gt;
&lt;br /&gt;
* '''Argon2'''[*7] is the winner of the [https://password-hashing.net/ password hashing competition] and should be considered as your first choice for new applications; &lt;br /&gt;
* '''PBKDF2''' [*4] when FIPS certification or enterprise support on many platforms is required;&lt;br /&gt;
* '''scrypt''' [*5] where resisting any/all hardware accelerated attacks is necessary but support isn’t.&lt;br /&gt;
* '''bcrypt''' where PBKDF2 or scrypt support is not available.&lt;br /&gt;
&lt;br /&gt;
Example protect() pseudo-code follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;return [salt] + pbkdf2([salt], [credential], c=10000); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Designers select one-way adaptive functions to implement protect() because these functions can be configured to cost (linearly or exponentially) more than a hash function to execute. Defenders adjust work factor to keep pace with threats’ increasing hardware capabilities. Those implementing adaptive one-way functions must tune work factors so as to impede attackers while providing acceptable user experience and scale. &lt;br /&gt;
&lt;br /&gt;
Additionally, adaptive one-way functions do not effectively prevent reversal of common dictionary-based credentials (users with password ‘password’) regardless of user population size or salt usage.&lt;br /&gt;
&lt;br /&gt;
==== Work Factor ====&lt;br /&gt;
&lt;br /&gt;
Since resources are normally considered limited, a common rule of thumb for tuning the work factor (or cost) is to make protect() run as slow as possible without affecting the users' experience and without increasing the need for extra hardware over budget. So, if the registration and authentication's cases accept protect() taking up to 1 second, you can tune the cost so that it takes 1 second to run on your hardware. This way, it shouldn't be so slow that your users become affected, but it should also affect the attackers' attempt as much as possible. &lt;br /&gt;
&lt;br /&gt;
While there is a minimum number of iterations recommended to ensure data safety, this value changes every year as technology improves. An example of the iteration count chosen by a well known company is the 10,000 iterations Apple uses for its iTunes passwords (using PBKDF2)[http://images.apple.com/ipad/business/docs/iOS_Security_May12.pdf](PDF file). However, it is critical to understand that a single work factor does not fit all designs. Experimentation is important.[*6]&lt;br /&gt;
&lt;br /&gt;
=== Leverage Keyed functions ===&lt;br /&gt;
&lt;br /&gt;
Keyed functions, such as HMACs, compute a one-way (irreversible) transform using a private key and given input. For example, HMACs inherit properties of hash functions including their speed, allowing for near instant verification. Key size imposes infeasible size- and/or space- requirements on compromise--even for common credentials (aka password = ‘password’).&lt;br /&gt;
Designers protecting stored credentials with keyed functions:&lt;br /&gt;
&lt;br /&gt;
* Use a single “site-wide” key;&lt;br /&gt;
* Protect this key as any private key using best practices;&lt;br /&gt;
* Store the key outside the credential store (aka: not in the database);&lt;br /&gt;
* Generate the key using cryptographically-strong pseudo-random data;&lt;br /&gt;
* Do not worry about output block size (i.e. SHA-256 vs. SHA-512).&lt;br /&gt;
&lt;br /&gt;
Example protect() pseudo-code follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;return [salt] + HMAC-SHA-256([key], [salt] + [credential]);  &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Upholding security improvement over (solely) salted schemes relies on proper key management.&lt;br /&gt;
&lt;br /&gt;
== Design password storage assuming eventual compromise ==&lt;br /&gt;
&lt;br /&gt;
The frequency and ease with which threats steal protected credentials demands “design for failure”. Having detected theft, a credential storage scheme must support continued operation by marking credential data as compromised. It's also critical to engage alternative credential validation workflows as follows:&lt;br /&gt;
&lt;br /&gt;
# Protect the user’s account&lt;br /&gt;
## Invalidate authentication ‘shortcuts’ by disallowing login without 2nd factors, secret questions or some other form os strong authentication.&lt;br /&gt;
## Disallow changes to user accounts such as editing secret questions and changing account multi-factor configuration settings.&lt;br /&gt;
# Load and use new protection scheme&lt;br /&gt;
## Load a new, stronger credential protection scheme&lt;br /&gt;
## Include version information stored with form&lt;br /&gt;
## Set ‘tainted’/‘compromised’ bit until user resets credentials&lt;br /&gt;
## Rotate any keys and/or adjust protection function parameters such as work factor or salt&lt;br /&gt;
## Increment scheme version number&lt;br /&gt;
# When user logs in:&lt;br /&gt;
## Validate credentials based on stored version (old or new); if older compromised version is still active for user, demand 2nd factor or secret answers until the new method is implemented or activated for that user&lt;br /&gt;
## Prompt user for credential change, apologize, &amp;amp; conduct out-of-band confirmation&lt;br /&gt;
## Convert stored credentials to new scheme as user successfully log in&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
&lt;br /&gt;
* [1] Morris, R. Thompson, K., Password Security: A Case History, 04/03/1978, p4: http://cm.bell-labs.com/cm/cs/who/dmr/passwd.ps&lt;br /&gt;
* [2] Space-based (Lookup) attacks: Space-time Tradeoff: Hellman, M., Crypanalytic Time-Memory Trade-Off, Transactions of Information Theory, Vol. IT-26, No. 4, July, 1980 http://www-ee.stanford.edu/~hellman/publications/36.pdf Rainbow Tables -http://ophcrack.sourceforge.net/tables.php&lt;br /&gt;
* [3] For example: [http://docs.oracle.com/javase/6/docs/api/java/security/SecureRandom.html SecureRandom.html].&lt;br /&gt;
* [4] Kalski, B., PKCS #5: Password-Based Cryptography Specification Version 2.0, IETF RFC 2898, September, 2000, p9 http://www.ietf.org/rfc/rfc2898.txt&lt;br /&gt;
* [5] Percival, C., Stronger Key Derivation Via Sequential Memory-Hard Functions, BSDCan ‘09, May, 2009 http://www.tarsnap.com/scrypt/scrypt.pdf&lt;br /&gt;
* [6] For instance, one might set work factors targeting the following run times: (1) Password-generated session key - fraction of a second; (2) User credential - ~0.5 seconds; (3) Password-generated site (or other long-lived) key - potentially a second or more.&lt;br /&gt;
* [7] Argon2 detailed specifications can be found here. https://password-hashing.net/argon2-specs.pdf&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
John Steven - john.steven[at]owasp.org (author)&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org (editor)&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228922</id>
		<title>Authentication Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228922"/>
				<updated>2017-04-21T11:07:56Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Password Complexity */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;English&amp;lt;/b&amp;gt; | [[Authentication_Cheat_Sheet_Español | Spanish]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
'''Authentication''' is the process of verification that an individual, entity  or website is who it claims to be. Authentication in the context of web applications 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.&lt;br /&gt;
&lt;br /&gt;
'''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.&lt;br /&gt;
&lt;br /&gt;
== Authentication General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
=== User IDs ===&lt;br /&gt;
&lt;br /&gt;
Make sure your usernames/userids are case insensitive. User 'smith' and user 'Smith' should be the same user. User names should also be unique. For high security applications usernames could be assigned and secret instead of user-defined public data.&lt;br /&gt;
&lt;br /&gt;
==== Email address as a User ID ====&lt;br /&gt;
&lt;br /&gt;
For information on validating email addresses, please visit the [https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet#Email_Address_Validation input validation cheatsheet email discussion].&lt;br /&gt;
&lt;br /&gt;
=== Implement Proper Password Strength Controls ===&lt;br /&gt;
&lt;br /&gt;
A key concern when using passwords for authentication is password strength. A &amp;quot;strong&amp;quot; password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password: &lt;br /&gt;
&lt;br /&gt;
==== Password Length ====&lt;br /&gt;
&lt;br /&gt;
Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. &lt;br /&gt;
&lt;br /&gt;
* '''Minimum''' length of the passwords should be '''enforced''' by the application.&lt;br /&gt;
** Passwords '''shorter than 10 characters''' are considered to be weak ([http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf NIST SP800-132]).&lt;br /&gt;
&lt;br /&gt;
While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set ''passphrases'' (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.&lt;br /&gt;
&lt;br /&gt;
* '''Maximum''' password length should not be set '''too low''', as it will prevent users from creating passphrases. Typical maximum length is 128 characters.&lt;br /&gt;
** Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.&lt;br /&gt;
&lt;br /&gt;
==== Password Complexity ====&lt;br /&gt;
&lt;br /&gt;
Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.&lt;br /&gt;
&lt;br /&gt;
The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:&lt;br /&gt;
&lt;br /&gt;
*Password must meet at least 3 out of the following 4 complexity rules&lt;br /&gt;
**at least 1 uppercase character (A-Z) &lt;br /&gt;
**at least 1 lowercase character (a-z) &lt;br /&gt;
**at least 1 digit (0-9) &lt;br /&gt;
**at least 1 [[Password special characters|special character (punctuation)]] &amp;amp;mdash; do not forget to treat space as special characters too&lt;br /&gt;
*at least 10 characters &lt;br /&gt;
*at most 128 characters&lt;br /&gt;
*not more than 2 identical characters in a row (e.g., 111 not allowed)&lt;br /&gt;
&lt;br /&gt;
Further reading:&lt;br /&gt;
&lt;br /&gt;
* [https://www.youtube.com/watch?v=zUM7i8fsf0g Your Password Complexity Requirements are Worthless - OWASP AppSecUSA 2014] presentation for further discussion of legacy password complexity rules&lt;br /&gt;
* [https://www.korelogic.com/Resources/Presentations/bsidesavl_pathwell_2014-06.pdf PathWell: Password Topology Histogram Wear-Leveling]&lt;br /&gt;
&lt;br /&gt;
==== Password Topologies ====&lt;br /&gt;
&lt;br /&gt;
* Ban commonly used password topologies&lt;br /&gt;
* Force multiple users to use different password topologies&lt;br /&gt;
* Require a minimum topology change between old and new passwords&lt;br /&gt;
&lt;br /&gt;
==== Additional Information ====&lt;br /&gt;
&lt;br /&gt;
* Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).&lt;br /&gt;
* As application's require more complex password policies, they need to be very clear about what these policies are. The required policy needs to be explicitly stated on the password change page&lt;br /&gt;
* If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with.&lt;br /&gt;
&lt;br /&gt;
=== Implement Secure Password Recovery Mechanism ===&lt;br /&gt;
&lt;br /&gt;
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [[Forgot Password Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Store Passwords in a Secure Fashion ===&lt;br /&gt;
&lt;br /&gt;
It is critical for a application to store a password using the right cryptographic technique. Please see [[Password Storage Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Transmit Passwords Only Over TLS or Other Strong Transport ===&lt;br /&gt;
&lt;br /&gt;
See: [[Transport Layer Protection Cheat Sheet]]&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS or other strong transport. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS or other strong transport. Failure to utilize TLS or other strong transport for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS or other strong transport for authenticated pages after login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.&lt;br /&gt;
&lt;br /&gt;
=== Require Re-authentication for Sensitive Features ===&lt;br /&gt;
&lt;br /&gt;
In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address.  Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials.  Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.&lt;br /&gt;
&lt;br /&gt;
=== Consider Strong Transaction Authentication ===&lt;br /&gt;
&lt;br /&gt;
Some applications should use a second factor to check whether a user may perform sensitive operations. For more information see the [https://www.owasp.org/index.php/Transaction_Authorization_Cheat_Sheet Transaction Authorization Cheat Sheet].&lt;br /&gt;
&lt;br /&gt;
==== TLS Client Authentication ====&lt;br /&gt;
&lt;br /&gt;
TLS Client Authentication, also known as two-way TLS authentication, consists of both, browser and server, sending their respective TLS certificates during the TLS handshake process. Just as you can validate the authenticity of a server by using the certificate and asking a well known Certificate Authority (CA) if the certificate is valid, the server can authenticate the user by receiving a certificate from the client and validating against a third party CA or its own CA. To do this, the server must provide the user with a certificate generated specifically for him, assigning values to the subject so that these can be used to determine what user the certificate should validate. The user installs the certificate on a browser and now uses it for the website.&lt;br /&gt;
&lt;br /&gt;
It is a good idea to do this when:&lt;br /&gt;
&lt;br /&gt;
*It is acceptable (or even preferred) that the user only has access to the website from only a single computer/browser.&lt;br /&gt;
*The user is not easily scared by the process of installing TLS certificates on his browser or there will be someone, probably from IT support, that will do this for the user.&lt;br /&gt;
*The website requires an extra step of security.&lt;br /&gt;
*It is also a good thing to use when the website is for an intranet of a company or organization.&lt;br /&gt;
&lt;br /&gt;
It is generally not a good idea to use this method for widely and publicly available websites that will have an average user. For example, it wouldn't be a good idea to implement this for a website like Facebook. While this technique can prevent the user from having to type a password (thus protecting against an average keylogger from stealing it), it is still considered a good idea to consider using both a password and TLS client authentication combined.&lt;br /&gt;
&lt;br /&gt;
For more information, see: [https://en.wikipedia.org/wiki/Transport_Layer_Security#Client-authenticated_TLS_handshake Client-authenticated TLS handshake]&lt;br /&gt;
&lt;br /&gt;
=== Authentication and Error Messages ===&lt;br /&gt;
&lt;br /&gt;
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.&lt;br /&gt;
&lt;br /&gt;
===== Authentication Responses =====&lt;br /&gt;
&lt;br /&gt;
An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.&lt;br /&gt;
&lt;br /&gt;
===== Incorrect Response Examples =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login for User foo: invalid password&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed, invalid user ID&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; account disabled&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; this user is not active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===== Correct Response Example =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login failed; Invalid userID or password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID. &lt;br /&gt;
&lt;br /&gt;
===== Error Codes and URLs =====&lt;br /&gt;
&lt;br /&gt;
The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.&lt;br /&gt;
&lt;br /&gt;
=== Prevent Brute-Force Attacks ===&lt;br /&gt;
&lt;br /&gt;
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.  Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.  Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.  Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.&lt;br /&gt;
&lt;br /&gt;
Also, multi-factor authentication is a very powerful deterrent when trying to prevent brute force attacks since the credentials are a moving target. When multi-factor is implemented and active, account lockout may no longer be necessary.&lt;br /&gt;
&lt;br /&gt;
== Logging and Monitoring == &lt;br /&gt;
Enable logging and monitoring of authentication functions to detect attacks / failures on a real time basis&lt;br /&gt;
&lt;br /&gt;
*Ensure that all failures are logged and reviewed&lt;br /&gt;
*Ensure that all password failures are logged and reviewed&lt;br /&gt;
*Ensure that all account lockouts are logged and reviewed&lt;br /&gt;
&lt;br /&gt;
== Use of authentication protocols that require no password ==&lt;br /&gt;
&lt;br /&gt;
While authentication through a user/password combination and using multi-factor authentication is considered generally secure, there are use cases where it isn't considered the best option or even safe. Examples of this are third party applications that desire connecting to the web application, either from a mobile device, another website, desktop or other situations. When this happens, it is NOT considered safe to allow the third party application to store the user/password combo, since then it extends the attack surface into their hands, where it isn't in your control. For this, and other use cases, there are several authentication protocols that can protect you from exposing your users' data to attackers.&lt;br /&gt;
&lt;br /&gt;
=== OAuth ===&lt;br /&gt;
&lt;br /&gt;
Open Authorization (OAuth) is a protocol that allows an application to authenticate against a server as a user, without requiring passwords or any third party server that acts as an identity provider. It uses a token generated by the server, and provides how the authorization flows most occur, so that a client, such as a mobile application, can tell the server what user is using the service. &lt;br /&gt;
&lt;br /&gt;
The recommendation is to use and implement OAuth 1.0a or OAuth 2.0, since the very first version (OAuth1.0) has been found to be vulnerable to session fixation.&lt;br /&gt;
&lt;br /&gt;
OAuth 2.0 relies on HTTPS for security and is currently used and implemented by API's from companies such as Facebook, Google, Twitter and Microsoft. OAuth1.0a is more difficult to use because it requires the use of cryptographic libraries for digital signatures. However, since OAuth1.0a does not rely on HTTPS for security it can be more suited for higher risk transactions.&lt;br /&gt;
&lt;br /&gt;
=== OpenId ===&lt;br /&gt;
&lt;br /&gt;
OpenId is an HTTP-based protocol that uses identity providers to validate that a user is who he says he is. It is a very simple protocol which allows a service provider initiated way for single sign-on (SSO). This allows the user to re-use a single identity given to a trusted OpenId identity provider and be the same user in multiple websites, without the need to provide any website the password, except for the OpenId identity provider.&lt;br /&gt;
&lt;br /&gt;
Due to its simplicity and that it provides protection of passwords, OpenId has been well adopted. Some of the well known identity providers for OpenId are Stack Exchange, Google, Facebook and Yahoo!&lt;br /&gt;
&lt;br /&gt;
For non-enterprise environments, OpenId is considered a secure and often better choice, as long as the identity provider is of trust.&lt;br /&gt;
&lt;br /&gt;
=== SAML ===&lt;br /&gt;
&lt;br /&gt;
Security Assertion Markup Language (SAML) is often considered to compete with OpenId. The most recommended version is 2.0, since it is very feature complete and provides a strong security. Like OpenId, SAML uses identity providers, but unlike OpenId, it is XML-based and provides more flexibility. SAML is based on browser redirects which send XML data. Furthermore, SAML isn't only initiated by a service provider; it can also be initiated from the identity provider. This allows the user to navigate through different portals while still being authenticated without having to do anything, making the process transparent.&lt;br /&gt;
&lt;br /&gt;
While OpenId has taken most of the consumer market, SAML is often the choice for enterprise applications. The reason for this is often that there are few OpenId identity providers which are considered of enterprise class (meaning that the way they validate the user identity doesn't have high standards required for enterprise identity). It is more common to see SAML being used inside of intranet websites, sometimes even using a server from the intranet as the identity provider.&lt;br /&gt;
&lt;br /&gt;
In the past few years, applications like SAP ERP and SharePoint (SharePoint by using Active Directory Federation Services 2.0) have decided to use SAML 2.0 authentication as an often preferred method for single sign-on implementations whenever enterprise federation is required for web services and web applications.&lt;br /&gt;
&lt;br /&gt;
'''See also: [[SAML Security Cheat Sheet]]'''&lt;br /&gt;
&lt;br /&gt;
=== FIDO ===&lt;br /&gt;
The Fast Identity Online (FIDO) Alliance has created two protocols to facilitate online authentication : the Universal Authentication Framework (UAF) protocol and the Universal Second Factor (U2F) protocol. While UAF focuses on passwordless authentication, U2F allows the addition of a second factor to existing password-based authentication. Both protocols are based on a public key cryptography challenge-response model. &lt;br /&gt;
&lt;br /&gt;
UAF takes advantage of existing security technologies present on devices for authentication including fingerprint sensors, cameras(face biometrics), microphones(voice biometrics), Trusted Execution Environments(TEEs), Secure Elements(SEs) and others. The protocol is designed to plug-in these device capabilities into a common authentication framework. UAF works with both native applications and web applications.&lt;br /&gt;
&lt;br /&gt;
U2F augments password-based authentication using a hardware token (typically USB) that stores cryptographic authentication keys and uses them for signing. The user can use the same token as a second factor for multiple applications. U2F works with web applications. It provides '''protection against phishing''' by using the URL of the website to lookup the stored authentication key.&lt;br /&gt;
&lt;br /&gt;
== Session Management General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
Session management is directly related to authentication. The '''Session Management General Guidelines''' previously available on this OWASP Authentication Cheat Sheet have been integrated into the [[Session Management Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Password Managers ==&lt;br /&gt;
&lt;br /&gt;
Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. While use of password managers is subject to controversies and many organisations block their usage, their contribution to authentication security is positive, as pointed out by [https://www.ncsc.gov.uk/blog-post/what-does-ncsc-think-password-managers National Cyber Security Centre].&lt;br /&gt;
&lt;br /&gt;
Web applications should at least not make password managers job more difficult than necessary by observing the following recommendations:&lt;br /&gt;
&lt;br /&gt;
* use standard HTML forms for username and password input with appropriate `type` attributes,&lt;br /&gt;
* do not artificially limit user passwords to a length &amp;quot;reasonable for humans&amp;quot; and allow passwords lengths up to 128 characters,&lt;br /&gt;
* do not artificially prevent copy and paste on username and password fields,&lt;br /&gt;
* avoid plugin-based login pages (Flash, Silverlight etc)&lt;br /&gt;
&lt;br /&gt;
As of 2017 [https://w3c.github.io/webappsec-credential-management/ Credential Management Level 1] standard for web browsers is being developed that may further facilitate interaction between password managers and complex log-in schemes (e.g. single sign-on).&lt;br /&gt;
&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
A PDF of this cheatsheet has been created here. https://magic.piktochart.com/output/7003174-authentication-cheat-sheet&lt;br /&gt;
&lt;br /&gt;
== Authors and Primary Editors  ==&lt;br /&gt;
&lt;br /&gt;
Eoin Keary eoinkeary[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico&amp;lt;br/&amp;gt;&lt;br /&gt;
Timo Goosen&amp;lt;br/&amp;gt;&lt;br /&gt;
Pawel Krawczyk&amp;lt;br/&amp;gt;&lt;br /&gt;
Sven Neuhaus&amp;lt;br/&amp;gt;&lt;br /&gt;
Manuel Aude Morales &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228921</id>
		<title>Authentication Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228921"/>
				<updated>2017-04-21T11:07:35Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Implement Proper Password Strength Controls */ the presentation is from 2014 and most of the recommendations are addressed here&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;English&amp;lt;/b&amp;gt; | [[Authentication_Cheat_Sheet_Español | Spanish]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
'''Authentication''' is the process of verification that an individual, entity  or website is who it claims to be. Authentication in the context of web applications 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.&lt;br /&gt;
&lt;br /&gt;
'''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.&lt;br /&gt;
&lt;br /&gt;
== Authentication General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
=== User IDs ===&lt;br /&gt;
&lt;br /&gt;
Make sure your usernames/userids are case insensitive. User 'smith' and user 'Smith' should be the same user. User names should also be unique. For high security applications usernames could be assigned and secret instead of user-defined public data.&lt;br /&gt;
&lt;br /&gt;
==== Email address as a User ID ====&lt;br /&gt;
&lt;br /&gt;
For information on validating email addresses, please visit the [https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet#Email_Address_Validation input validation cheatsheet email discussion].&lt;br /&gt;
&lt;br /&gt;
=== Implement Proper Password Strength Controls ===&lt;br /&gt;
&lt;br /&gt;
A key concern when using passwords for authentication is password strength. A &amp;quot;strong&amp;quot; password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password: &lt;br /&gt;
&lt;br /&gt;
==== Password Length ====&lt;br /&gt;
&lt;br /&gt;
Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. &lt;br /&gt;
&lt;br /&gt;
* '''Minimum''' length of the passwords should be '''enforced''' by the application.&lt;br /&gt;
** Passwords '''shorter than 10 characters''' are considered to be weak ([http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf NIST SP800-132]).&lt;br /&gt;
&lt;br /&gt;
While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set ''passphrases'' (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.&lt;br /&gt;
&lt;br /&gt;
* '''Maximum''' password length should not be set '''too low''', as it will prevent users from creating passphrases. Typical maximum length is 128 characters.&lt;br /&gt;
** Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.&lt;br /&gt;
&lt;br /&gt;
==== Password Complexity ====&lt;br /&gt;
&lt;br /&gt;
Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.&lt;br /&gt;
&lt;br /&gt;
The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:&lt;br /&gt;
&lt;br /&gt;
*Password must meet at least 3 out of the following 4 complexity rules&lt;br /&gt;
**at least 1 uppercase character (A-Z) &lt;br /&gt;
**at least 1 lowercase character (a-z) &lt;br /&gt;
**at least 1 digit (0-9) &lt;br /&gt;
**at least 1 [[Password special characters|special character (punctuation)]] &amp;amp;mdash; do not forget to treat space as special characters too&lt;br /&gt;
*at least 10 characters &lt;br /&gt;
*at most 128 characters&lt;br /&gt;
*not more than 2 identical characters in a row (e.g., 111 not allowed)&lt;br /&gt;
&lt;br /&gt;
Further reading:&lt;br /&gt;
&lt;br /&gt;
* [https://www.youtube.com/watch?v=zUM7i8fsf0g Your Password Complexity Requirements are Worthless - OWASP AppSecUSA 2014] presentation for further discussion of legacy password complexity rules&lt;br /&gt;
* [https://www.korelogic.com/Resources/Presentations/bsidesavl_pathwell_2014-06.pdf PathWell: Password Topology&lt;br /&gt;
Histogram Wear-Leveling]&lt;br /&gt;
&lt;br /&gt;
==== Password Topologies ====&lt;br /&gt;
&lt;br /&gt;
* Ban commonly used password topologies&lt;br /&gt;
* Force multiple users to use different password topologies&lt;br /&gt;
* Require a minimum topology change between old and new passwords&lt;br /&gt;
&lt;br /&gt;
==== Additional Information ====&lt;br /&gt;
&lt;br /&gt;
* Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).&lt;br /&gt;
* As application's require more complex password policies, they need to be very clear about what these policies are. The required policy needs to be explicitly stated on the password change page&lt;br /&gt;
* If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with.&lt;br /&gt;
&lt;br /&gt;
=== Implement Secure Password Recovery Mechanism ===&lt;br /&gt;
&lt;br /&gt;
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [[Forgot Password Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Store Passwords in a Secure Fashion ===&lt;br /&gt;
&lt;br /&gt;
It is critical for a application to store a password using the right cryptographic technique. Please see [[Password Storage Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Transmit Passwords Only Over TLS or Other Strong Transport ===&lt;br /&gt;
&lt;br /&gt;
See: [[Transport Layer Protection Cheat Sheet]]&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS or other strong transport. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS or other strong transport. Failure to utilize TLS or other strong transport for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS or other strong transport for authenticated pages after login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.&lt;br /&gt;
&lt;br /&gt;
=== Require Re-authentication for Sensitive Features ===&lt;br /&gt;
&lt;br /&gt;
In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address.  Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials.  Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.&lt;br /&gt;
&lt;br /&gt;
=== Consider Strong Transaction Authentication ===&lt;br /&gt;
&lt;br /&gt;
Some applications should use a second factor to check whether a user may perform sensitive operations. For more information see the [https://www.owasp.org/index.php/Transaction_Authorization_Cheat_Sheet Transaction Authorization Cheat Sheet].&lt;br /&gt;
&lt;br /&gt;
==== TLS Client Authentication ====&lt;br /&gt;
&lt;br /&gt;
TLS Client Authentication, also known as two-way TLS authentication, consists of both, browser and server, sending their respective TLS certificates during the TLS handshake process. Just as you can validate the authenticity of a server by using the certificate and asking a well known Certificate Authority (CA) if the certificate is valid, the server can authenticate the user by receiving a certificate from the client and validating against a third party CA or its own CA. To do this, the server must provide the user with a certificate generated specifically for him, assigning values to the subject so that these can be used to determine what user the certificate should validate. The user installs the certificate on a browser and now uses it for the website.&lt;br /&gt;
&lt;br /&gt;
It is a good idea to do this when:&lt;br /&gt;
&lt;br /&gt;
*It is acceptable (or even preferred) that the user only has access to the website from only a single computer/browser.&lt;br /&gt;
*The user is not easily scared by the process of installing TLS certificates on his browser or there will be someone, probably from IT support, that will do this for the user.&lt;br /&gt;
*The website requires an extra step of security.&lt;br /&gt;
*It is also a good thing to use when the website is for an intranet of a company or organization.&lt;br /&gt;
&lt;br /&gt;
It is generally not a good idea to use this method for widely and publicly available websites that will have an average user. For example, it wouldn't be a good idea to implement this for a website like Facebook. While this technique can prevent the user from having to type a password (thus protecting against an average keylogger from stealing it), it is still considered a good idea to consider using both a password and TLS client authentication combined.&lt;br /&gt;
&lt;br /&gt;
For more information, see: [https://en.wikipedia.org/wiki/Transport_Layer_Security#Client-authenticated_TLS_handshake Client-authenticated TLS handshake]&lt;br /&gt;
&lt;br /&gt;
=== Authentication and Error Messages ===&lt;br /&gt;
&lt;br /&gt;
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.&lt;br /&gt;
&lt;br /&gt;
===== Authentication Responses =====&lt;br /&gt;
&lt;br /&gt;
An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.&lt;br /&gt;
&lt;br /&gt;
===== Incorrect Response Examples =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login for User foo: invalid password&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed, invalid user ID&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; account disabled&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; this user is not active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===== Correct Response Example =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login failed; Invalid userID or password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID. &lt;br /&gt;
&lt;br /&gt;
===== Error Codes and URLs =====&lt;br /&gt;
&lt;br /&gt;
The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.&lt;br /&gt;
&lt;br /&gt;
=== Prevent Brute-Force Attacks ===&lt;br /&gt;
&lt;br /&gt;
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.  Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.  Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.  Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.&lt;br /&gt;
&lt;br /&gt;
Also, multi-factor authentication is a very powerful deterrent when trying to prevent brute force attacks since the credentials are a moving target. When multi-factor is implemented and active, account lockout may no longer be necessary.&lt;br /&gt;
&lt;br /&gt;
== Logging and Monitoring == &lt;br /&gt;
Enable logging and monitoring of authentication functions to detect attacks / failures on a real time basis&lt;br /&gt;
&lt;br /&gt;
*Ensure that all failures are logged and reviewed&lt;br /&gt;
*Ensure that all password failures are logged and reviewed&lt;br /&gt;
*Ensure that all account lockouts are logged and reviewed&lt;br /&gt;
&lt;br /&gt;
== Use of authentication protocols that require no password ==&lt;br /&gt;
&lt;br /&gt;
While authentication through a user/password combination and using multi-factor authentication is considered generally secure, there are use cases where it isn't considered the best option or even safe. Examples of this are third party applications that desire connecting to the web application, either from a mobile device, another website, desktop or other situations. When this happens, it is NOT considered safe to allow the third party application to store the user/password combo, since then it extends the attack surface into their hands, where it isn't in your control. For this, and other use cases, there are several authentication protocols that can protect you from exposing your users' data to attackers.&lt;br /&gt;
&lt;br /&gt;
=== OAuth ===&lt;br /&gt;
&lt;br /&gt;
Open Authorization (OAuth) is a protocol that allows an application to authenticate against a server as a user, without requiring passwords or any third party server that acts as an identity provider. It uses a token generated by the server, and provides how the authorization flows most occur, so that a client, such as a mobile application, can tell the server what user is using the service. &lt;br /&gt;
&lt;br /&gt;
The recommendation is to use and implement OAuth 1.0a or OAuth 2.0, since the very first version (OAuth1.0) has been found to be vulnerable to session fixation.&lt;br /&gt;
&lt;br /&gt;
OAuth 2.0 relies on HTTPS for security and is currently used and implemented by API's from companies such as Facebook, Google, Twitter and Microsoft. OAuth1.0a is more difficult to use because it requires the use of cryptographic libraries for digital signatures. However, since OAuth1.0a does not rely on HTTPS for security it can be more suited for higher risk transactions.&lt;br /&gt;
&lt;br /&gt;
=== OpenId ===&lt;br /&gt;
&lt;br /&gt;
OpenId is an HTTP-based protocol that uses identity providers to validate that a user is who he says he is. It is a very simple protocol which allows a service provider initiated way for single sign-on (SSO). This allows the user to re-use a single identity given to a trusted OpenId identity provider and be the same user in multiple websites, without the need to provide any website the password, except for the OpenId identity provider.&lt;br /&gt;
&lt;br /&gt;
Due to its simplicity and that it provides protection of passwords, OpenId has been well adopted. Some of the well known identity providers for OpenId are Stack Exchange, Google, Facebook and Yahoo!&lt;br /&gt;
&lt;br /&gt;
For non-enterprise environments, OpenId is considered a secure and often better choice, as long as the identity provider is of trust.&lt;br /&gt;
&lt;br /&gt;
=== SAML ===&lt;br /&gt;
&lt;br /&gt;
Security Assertion Markup Language (SAML) is often considered to compete with OpenId. The most recommended version is 2.0, since it is very feature complete and provides a strong security. Like OpenId, SAML uses identity providers, but unlike OpenId, it is XML-based and provides more flexibility. SAML is based on browser redirects which send XML data. Furthermore, SAML isn't only initiated by a service provider; it can also be initiated from the identity provider. This allows the user to navigate through different portals while still being authenticated without having to do anything, making the process transparent.&lt;br /&gt;
&lt;br /&gt;
While OpenId has taken most of the consumer market, SAML is often the choice for enterprise applications. The reason for this is often that there are few OpenId identity providers which are considered of enterprise class (meaning that the way they validate the user identity doesn't have high standards required for enterprise identity). It is more common to see SAML being used inside of intranet websites, sometimes even using a server from the intranet as the identity provider.&lt;br /&gt;
&lt;br /&gt;
In the past few years, applications like SAP ERP and SharePoint (SharePoint by using Active Directory Federation Services 2.0) have decided to use SAML 2.0 authentication as an often preferred method for single sign-on implementations whenever enterprise federation is required for web services and web applications.&lt;br /&gt;
&lt;br /&gt;
'''See also: [[SAML Security Cheat Sheet]]'''&lt;br /&gt;
&lt;br /&gt;
=== FIDO ===&lt;br /&gt;
The Fast Identity Online (FIDO) Alliance has created two protocols to facilitate online authentication : the Universal Authentication Framework (UAF) protocol and the Universal Second Factor (U2F) protocol. While UAF focuses on passwordless authentication, U2F allows the addition of a second factor to existing password-based authentication. Both protocols are based on a public key cryptography challenge-response model. &lt;br /&gt;
&lt;br /&gt;
UAF takes advantage of existing security technologies present on devices for authentication including fingerprint sensors, cameras(face biometrics), microphones(voice biometrics), Trusted Execution Environments(TEEs), Secure Elements(SEs) and others. The protocol is designed to plug-in these device capabilities into a common authentication framework. UAF works with both native applications and web applications.&lt;br /&gt;
&lt;br /&gt;
U2F augments password-based authentication using a hardware token (typically USB) that stores cryptographic authentication keys and uses them for signing. The user can use the same token as a second factor for multiple applications. U2F works with web applications. It provides '''protection against phishing''' by using the URL of the website to lookup the stored authentication key.&lt;br /&gt;
&lt;br /&gt;
== Session Management General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
Session management is directly related to authentication. The '''Session Management General Guidelines''' previously available on this OWASP Authentication Cheat Sheet have been integrated into the [[Session Management Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Password Managers ==&lt;br /&gt;
&lt;br /&gt;
Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. While use of password managers is subject to controversies and many organisations block their usage, their contribution to authentication security is positive, as pointed out by [https://www.ncsc.gov.uk/blog-post/what-does-ncsc-think-password-managers National Cyber Security Centre].&lt;br /&gt;
&lt;br /&gt;
Web applications should at least not make password managers job more difficult than necessary by observing the following recommendations:&lt;br /&gt;
&lt;br /&gt;
* use standard HTML forms for username and password input with appropriate `type` attributes,&lt;br /&gt;
* do not artificially limit user passwords to a length &amp;quot;reasonable for humans&amp;quot; and allow passwords lengths up to 128 characters,&lt;br /&gt;
* do not artificially prevent copy and paste on username and password fields,&lt;br /&gt;
* avoid plugin-based login pages (Flash, Silverlight etc)&lt;br /&gt;
&lt;br /&gt;
As of 2017 [https://w3c.github.io/webappsec-credential-management/ Credential Management Level 1] standard for web browsers is being developed that may further facilitate interaction between password managers and complex log-in schemes (e.g. single sign-on).&lt;br /&gt;
&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
A PDF of this cheatsheet has been created here. https://magic.piktochart.com/output/7003174-authentication-cheat-sheet&lt;br /&gt;
&lt;br /&gt;
== Authors and Primary Editors  ==&lt;br /&gt;
&lt;br /&gt;
Eoin Keary eoinkeary[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico&amp;lt;br/&amp;gt;&lt;br /&gt;
Timo Goosen&amp;lt;br/&amp;gt;&lt;br /&gt;
Pawel Krawczyk&amp;lt;br/&amp;gt;&lt;br /&gt;
Sven Neuhaus&amp;lt;br/&amp;gt;&lt;br /&gt;
Manuel Aude Morales &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228919</id>
		<title>Authentication Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=228919"/>
				<updated>2017-04-21T11:01:15Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Password Managers */ National Cyber Security Centre on password managers, update the recommendations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;English&amp;lt;/b&amp;gt; | [[Authentication_Cheat_Sheet_Español | Spanish]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
'''Authentication''' is the process of verification that an individual, entity  or website is who it claims to be. Authentication in the context of web applications 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.&lt;br /&gt;
&lt;br /&gt;
'''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.&lt;br /&gt;
&lt;br /&gt;
== Authentication General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
=== User IDs ===&lt;br /&gt;
&lt;br /&gt;
Make sure your usernames/userids are case insensitive. User 'smith' and user 'Smith' should be the same user. User names should also be unique. For high security applications usernames could be assigned and secret instead of user-defined public data.&lt;br /&gt;
&lt;br /&gt;
==== Email address as a User ID ====&lt;br /&gt;
&lt;br /&gt;
For information on validating email addresses, please visit the [https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet#Email_Address_Validation input validation cheatsheet email discussion].&lt;br /&gt;
&lt;br /&gt;
=== Implement Proper Password Strength Controls ===&lt;br /&gt;
&lt;br /&gt;
A key concern when using passwords for authentication is password strength. A &amp;quot;strong&amp;quot; password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password: &lt;br /&gt;
&lt;br /&gt;
==== Warning ====&lt;br /&gt;
&lt;br /&gt;
The following advice is disputed. Please view the OWASP presentation,  &amp;quot;[https://www.youtube.com/watch?v=zUM7i8fsf0g Your Password Complexity Requirements are Worthless - OWASP AppSecUSA 2014]&amp;quot; for more information.&lt;br /&gt;
&lt;br /&gt;
==== Password Length ====&lt;br /&gt;
&lt;br /&gt;
Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. &lt;br /&gt;
&lt;br /&gt;
* '''Minimum''' length of the passwords should be '''enforced''' by the application.&lt;br /&gt;
** Passwords '''shorter than 10 characters''' are considered to be weak ([http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf]).&lt;br /&gt;
&lt;br /&gt;
While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set ''passphrases'' (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.&lt;br /&gt;
&lt;br /&gt;
* '''Maximum''' password length should not be set '''too low''', as it will prevent users from creating passphrases. Typical maximum length is 128 characters.&lt;br /&gt;
** Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.&lt;br /&gt;
&lt;br /&gt;
==== Password Complexity ====&lt;br /&gt;
&lt;br /&gt;
Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.&lt;br /&gt;
&lt;br /&gt;
The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:&lt;br /&gt;
&lt;br /&gt;
*Password must meet at least 3 out of the following 4 complexity rules&lt;br /&gt;
**at least 1 uppercase character (A-Z) &lt;br /&gt;
**at least 1 lowercase character (a-z) &lt;br /&gt;
**at least 1 digit (0-9) &lt;br /&gt;
**at least 1 [[Password special characters|special character (punctuation)]] &amp;amp;mdash; do not forget to treat space as special characters too&lt;br /&gt;
*at least 10 characters &lt;br /&gt;
*at most 128 characters&lt;br /&gt;
*not more than 2 identical characters in a row (e.g., 111 not allowed)&lt;br /&gt;
&lt;br /&gt;
==== Password Topologies ====&lt;br /&gt;
&lt;br /&gt;
* Ban commonly used password topologies&lt;br /&gt;
* Force multiple users to use different password topologies&lt;br /&gt;
* Require a minimum topology change between old and new passwords&lt;br /&gt;
&lt;br /&gt;
==== Additional Information ====&lt;br /&gt;
&lt;br /&gt;
* Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).&lt;br /&gt;
* As application's require more complex password policies, they need to be very clear about what these policies are. The required policy needs to be explicitly stated on the password change page&lt;br /&gt;
* If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with.&lt;br /&gt;
&lt;br /&gt;
=== Implement Secure Password Recovery Mechanism ===&lt;br /&gt;
&lt;br /&gt;
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [[Forgot Password Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Store Passwords in a Secure Fashion ===&lt;br /&gt;
&lt;br /&gt;
It is critical for a application to store a password using the right cryptographic technique. Please see [[Password Storage Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
=== Transmit Passwords Only Over TLS or Other Strong Transport ===&lt;br /&gt;
&lt;br /&gt;
See: [[Transport Layer Protection Cheat Sheet]]&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS or other strong transport. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS or other strong transport. Failure to utilize TLS or other strong transport for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS or other strong transport for authenticated pages after login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.&lt;br /&gt;
&lt;br /&gt;
=== Require Re-authentication for Sensitive Features ===&lt;br /&gt;
&lt;br /&gt;
In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address.  Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials.  Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.&lt;br /&gt;
&lt;br /&gt;
=== Consider Strong Transaction Authentication ===&lt;br /&gt;
&lt;br /&gt;
Some applications should use a second factor to check whether a user may perform sensitive operations. For more information see the [https://www.owasp.org/index.php/Transaction_Authorization_Cheat_Sheet Transaction Authorization Cheat Sheet].&lt;br /&gt;
&lt;br /&gt;
==== TLS Client Authentication ====&lt;br /&gt;
&lt;br /&gt;
TLS Client Authentication, also known as two-way TLS authentication, consists of both, browser and server, sending their respective TLS certificates during the TLS handshake process. Just as you can validate the authenticity of a server by using the certificate and asking a well known Certificate Authority (CA) if the certificate is valid, the server can authenticate the user by receiving a certificate from the client and validating against a third party CA or its own CA. To do this, the server must provide the user with a certificate generated specifically for him, assigning values to the subject so that these can be used to determine what user the certificate should validate. The user installs the certificate on a browser and now uses it for the website.&lt;br /&gt;
&lt;br /&gt;
It is a good idea to do this when:&lt;br /&gt;
&lt;br /&gt;
*It is acceptable (or even preferred) that the user only has access to the website from only a single computer/browser.&lt;br /&gt;
*The user is not easily scared by the process of installing TLS certificates on his browser or there will be someone, probably from IT support, that will do this for the user.&lt;br /&gt;
*The website requires an extra step of security.&lt;br /&gt;
*It is also a good thing to use when the website is for an intranet of a company or organization.&lt;br /&gt;
&lt;br /&gt;
It is generally not a good idea to use this method for widely and publicly available websites that will have an average user. For example, it wouldn't be a good idea to implement this for a website like Facebook. While this technique can prevent the user from having to type a password (thus protecting against an average keylogger from stealing it), it is still considered a good idea to consider using both a password and TLS client authentication combined.&lt;br /&gt;
&lt;br /&gt;
For more information, see: [https://en.wikipedia.org/wiki/Transport_Layer_Security#Client-authenticated_TLS_handshake Client-authenticated TLS handshake]&lt;br /&gt;
&lt;br /&gt;
=== Authentication and Error Messages ===&lt;br /&gt;
&lt;br /&gt;
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.&lt;br /&gt;
&lt;br /&gt;
===== Authentication Responses =====&lt;br /&gt;
&lt;br /&gt;
An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.&lt;br /&gt;
&lt;br /&gt;
===== Incorrect Response Examples =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login for User foo: invalid password&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed, invalid user ID&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; account disabled&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; this user is not active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===== Correct Response Example =====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login failed; Invalid userID or password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID. &lt;br /&gt;
&lt;br /&gt;
===== Error Codes and URLs =====&lt;br /&gt;
&lt;br /&gt;
The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.&lt;br /&gt;
&lt;br /&gt;
=== Prevent Brute-Force Attacks ===&lt;br /&gt;
&lt;br /&gt;
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.  Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.  Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.  Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.&lt;br /&gt;
&lt;br /&gt;
Also, multi-factor authentication is a very powerful deterrent when trying to prevent brute force attacks since the credentials are a moving target. When multi-factor is implemented and active, account lockout may no longer be necessary.&lt;br /&gt;
&lt;br /&gt;
== Logging and Monitoring == &lt;br /&gt;
Enable logging and monitoring of authentication functions to detect attacks / failures on a real time basis&lt;br /&gt;
&lt;br /&gt;
*Ensure that all failures are logged and reviewed&lt;br /&gt;
*Ensure that all password failures are logged and reviewed&lt;br /&gt;
*Ensure that all account lockouts are logged and reviewed&lt;br /&gt;
&lt;br /&gt;
== Use of authentication protocols that require no password ==&lt;br /&gt;
&lt;br /&gt;
While authentication through a user/password combination and using multi-factor authentication is considered generally secure, there are use cases where it isn't considered the best option or even safe. Examples of this are third party applications that desire connecting to the web application, either from a mobile device, another website, desktop or other situations. When this happens, it is NOT considered safe to allow the third party application to store the user/password combo, since then it extends the attack surface into their hands, where it isn't in your control. For this, and other use cases, there are several authentication protocols that can protect you from exposing your users' data to attackers.&lt;br /&gt;
&lt;br /&gt;
=== OAuth ===&lt;br /&gt;
&lt;br /&gt;
Open Authorization (OAuth) is a protocol that allows an application to authenticate against a server as a user, without requiring passwords or any third party server that acts as an identity provider. It uses a token generated by the server, and provides how the authorization flows most occur, so that a client, such as a mobile application, can tell the server what user is using the service. &lt;br /&gt;
&lt;br /&gt;
The recommendation is to use and implement OAuth 1.0a or OAuth 2.0, since the very first version (OAuth1.0) has been found to be vulnerable to session fixation.&lt;br /&gt;
&lt;br /&gt;
OAuth 2.0 relies on HTTPS for security and is currently used and implemented by API's from companies such as Facebook, Google, Twitter and Microsoft. OAuth1.0a is more difficult to use because it requires the use of cryptographic libraries for digital signatures. However, since OAuth1.0a does not rely on HTTPS for security it can be more suited for higher risk transactions.&lt;br /&gt;
&lt;br /&gt;
=== OpenId ===&lt;br /&gt;
&lt;br /&gt;
OpenId is an HTTP-based protocol that uses identity providers to validate that a user is who he says he is. It is a very simple protocol which allows a service provider initiated way for single sign-on (SSO). This allows the user to re-use a single identity given to a trusted OpenId identity provider and be the same user in multiple websites, without the need to provide any website the password, except for the OpenId identity provider.&lt;br /&gt;
&lt;br /&gt;
Due to its simplicity and that it provides protection of passwords, OpenId has been well adopted. Some of the well known identity providers for OpenId are Stack Exchange, Google, Facebook and Yahoo!&lt;br /&gt;
&lt;br /&gt;
For non-enterprise environments, OpenId is considered a secure and often better choice, as long as the identity provider is of trust.&lt;br /&gt;
&lt;br /&gt;
=== SAML ===&lt;br /&gt;
&lt;br /&gt;
Security Assertion Markup Language (SAML) is often considered to compete with OpenId. The most recommended version is 2.0, since it is very feature complete and provides a strong security. Like OpenId, SAML uses identity providers, but unlike OpenId, it is XML-based and provides more flexibility. SAML is based on browser redirects which send XML data. Furthermore, SAML isn't only initiated by a service provider; it can also be initiated from the identity provider. This allows the user to navigate through different portals while still being authenticated without having to do anything, making the process transparent.&lt;br /&gt;
&lt;br /&gt;
While OpenId has taken most of the consumer market, SAML is often the choice for enterprise applications. The reason for this is often that there are few OpenId identity providers which are considered of enterprise class (meaning that the way they validate the user identity doesn't have high standards required for enterprise identity). It is more common to see SAML being used inside of intranet websites, sometimes even using a server from the intranet as the identity provider.&lt;br /&gt;
&lt;br /&gt;
In the past few years, applications like SAP ERP and SharePoint (SharePoint by using Active Directory Federation Services 2.0) have decided to use SAML 2.0 authentication as an often preferred method for single sign-on implementations whenever enterprise federation is required for web services and web applications.&lt;br /&gt;
&lt;br /&gt;
'''See also: [[SAML Security Cheat Sheet]]'''&lt;br /&gt;
&lt;br /&gt;
=== FIDO ===&lt;br /&gt;
The Fast Identity Online (FIDO) Alliance has created two protocols to facilitate online authentication : the Universal Authentication Framework (UAF) protocol and the Universal Second Factor (U2F) protocol. While UAF focuses on passwordless authentication, U2F allows the addition of a second factor to existing password-based authentication. Both protocols are based on a public key cryptography challenge-response model. &lt;br /&gt;
&lt;br /&gt;
UAF takes advantage of existing security technologies present on devices for authentication including fingerprint sensors, cameras(face biometrics), microphones(voice biometrics), Trusted Execution Environments(TEEs), Secure Elements(SEs) and others. The protocol is designed to plug-in these device capabilities into a common authentication framework. UAF works with both native applications and web applications.&lt;br /&gt;
&lt;br /&gt;
U2F augments password-based authentication using a hardware token (typically USB) that stores cryptographic authentication keys and uses them for signing. The user can use the same token as a second factor for multiple applications. U2F works with web applications. It provides '''protection against phishing''' by using the URL of the website to lookup the stored authentication key.&lt;br /&gt;
&lt;br /&gt;
== Session Management General Guidelines  ==&lt;br /&gt;
&lt;br /&gt;
Session management is directly related to authentication. The '''Session Management General Guidelines''' previously available on this OWASP Authentication Cheat Sheet have been integrated into the [[Session Management Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Password Managers ==&lt;br /&gt;
&lt;br /&gt;
Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. While use of password managers is subject to controversies and many organisations block their usage, their contribution to authentication security is positive, as pointed out by [https://www.ncsc.gov.uk/blog-post/what-does-ncsc-think-password-managers National Cyber Security Centre].&lt;br /&gt;
&lt;br /&gt;
Web applications should at least not make password managers job more difficult than necessary by observing the following recommendations:&lt;br /&gt;
&lt;br /&gt;
* use standard HTML forms for username and password input with appropriate `type` attributes,&lt;br /&gt;
* do not artificially limit user passwords to a length &amp;quot;reasonable for humans&amp;quot; and allow passwords lengths up to 128 characters,&lt;br /&gt;
* do not artificially prevent copy and paste on username and password fields,&lt;br /&gt;
* avoid plugin-based login pages (Flash, Silverlight etc)&lt;br /&gt;
&lt;br /&gt;
As of 2017 [https://w3c.github.io/webappsec-credential-management/ Credential Management Level 1] standard for web browsers is being developed that may further facilitate interaction between password managers and complex log-in schemes (e.g. single sign-on).&lt;br /&gt;
&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
A PDF of this cheatsheet has been created here. https://magic.piktochart.com/output/7003174-authentication-cheat-sheet&lt;br /&gt;
&lt;br /&gt;
== Authors and Primary Editors  ==&lt;br /&gt;
&lt;br /&gt;
Eoin Keary eoinkeary[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico&amp;lt;br/&amp;gt;&lt;br /&gt;
Timo Goosen&amp;lt;br/&amp;gt;&lt;br /&gt;
Pawel Krawczyk&amp;lt;br/&amp;gt;&lt;br /&gt;
Sven Neuhaus&amp;lt;br/&amp;gt;&lt;br /&gt;
Manuel Aude Morales &lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Pawel_Krawczyk&amp;diff=228149</id>
		<title>User:Pawel Krawczyk</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Pawel_Krawczyk&amp;diff=228149"/>
				<updated>2017-03-30T13:06:51Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Paweł Krawczyk'''&lt;br /&gt;
&lt;br /&gt;
* [https://www.linkedin.com/in/pawelkrawczyk my LinkedIn profile]&lt;br /&gt;
* [https://ipsec.pl/ IPSec.pl my application security and electronic signature articles]&lt;br /&gt;
* [https://webcookies.org/ free web application cookie and security scanner]&lt;br /&gt;
* [https://echelon.pl/ my articles in Polish]&lt;br /&gt;
&lt;br /&gt;
My draft articles:&lt;br /&gt;
&lt;br /&gt;
* [[User:Pawel_Krawczyk/List_of_useful_HTTP_headers]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Pawel_Krawczyk&amp;diff=223584</id>
		<title>User:Pawel Krawczyk</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Pawel_Krawczyk&amp;diff=223584"/>
				<updated>2016-11-22T06:52:07Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Paweł Krawczyk'''&lt;br /&gt;
&lt;br /&gt;
* [https://www.linkedin.com/in/pawelkrawczyk my LinkedIn profile]&lt;br /&gt;
* [https://ipsec.pl/ IPSec.pl my application security and electronic signature articles]&lt;br /&gt;
* [https://webcookies.org/ my tool for web application cookie inspection]&lt;br /&gt;
* [https://echelon.pl/ my articles in Polish]&lt;br /&gt;
&lt;br /&gt;
My draft articles:&lt;br /&gt;
&lt;br /&gt;
* [[User:Pawel_Krawczyk/List_of_useful_HTTP_headers]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Transport_Layer_Protection_Cheat_Sheet&amp;diff=195988</id>
		<title>Transport Layer Protection Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Transport_Layer_Protection_Cheat_Sheet&amp;diff=195988"/>
				<updated>2015-06-09T20:54:14Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Rule - REMOVED - Do Not Perform Redirects from Non-TLS Page to TLS Login Page */ if it's removed, it should be removed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides a simple model to follow when implementing transport layer protection for an application. Although the concept of SSL is known to many, the actual details and security specific decisions of implementation are often poorly understood and frequently result in insecure deployments. This article establishes clear rules which provide guidance on securely designing and configuring transport layer security for an application. This article is focused on the use of SSL/TLS between a web application and a web browser, but we also encourage the use of SSL/TLS or other network encryption technologies, such as VPN, on back end and other non-browser based connections.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Architectural Decision  ==&lt;br /&gt;
&lt;br /&gt;
An architectural decision must be made to determine the appropriate method to protect data when it is being transmitted.  The most common options available to corporations are Virtual Private Networks (VPN) or a SSL/TLS model commonly used by web applications. The selected model is determined by the business needs of the particular organization. For example, a VPN connection may be the best design for a partnership between two companies that includes mutual access to a shared server over a variety of protocols. Conversely, an Internet facing enterprise web application would likely be best served by a SSL/TLS model. &lt;br /&gt;
&lt;br /&gt;
This cheat sheet will focus on security considerations when the SSL/TLS model is selected. This is a frequently used model for publicly accessible web applications.&lt;br /&gt;
&lt;br /&gt;
= Providing Transport Layer Protection with SSL/TLS  =&lt;br /&gt;
&lt;br /&gt;
== Benefits  ==&lt;br /&gt;
&lt;br /&gt;
The primary benefit of transport layer security is the protection of web application data from unauthorized disclosure and modification when it is transmitted between clients (web browsers) and the web application server, and between the web application server and back end and other non-browser based enterprise components. &lt;br /&gt;
&lt;br /&gt;
The server validation component of TLS provides authentication of the server to the client.  If configured to require client side certificates, TLS can also play a role in client authentication to the server. However, in practice client side certificates are not often used in lieu of username and password based authentication models for clients.&lt;br /&gt;
&lt;br /&gt;
TLS also provides two additional benefits that are commonly overlooked; integrity guarantees and replay prevention. A TLS stream of communication contains built-in controls to prevent tampering with any portion of the encrypted data. In addition, controls are also built-in to prevent a captured stream of TLS data from being replayed at a later time.&lt;br /&gt;
&lt;br /&gt;
It should be noted that TLS provides the above guarantees to data during transmission. TLS does not offer any of these security benefits to data that is at rest. Therefore appropriate security controls must be added to protect data while at rest within the application or within data stores.&lt;br /&gt;
&lt;br /&gt;
== Basic Requirements ==&lt;br /&gt;
&lt;br /&gt;
The basic requirements for using TLS are: access to a Public Key Infrastructure (PKI) in order to obtain certificates, access to a directory or an Online Certificate Status Protocol (OCSP) responder in order to check certificate revocation status, and agreement/ability to support a minimum configuration of protocol versions and protocol options for each version.&lt;br /&gt;
&lt;br /&gt;
== SSL vs. TLS  ==&lt;br /&gt;
&lt;br /&gt;
The terms, Secure Socket Layer (SSL) and Transport Layer Security (TLS) are often used interchangeably. In fact, SSL v3.1 is equivalent to TLS v1.0. However, different versions of SSL and TLS are supported by modern web browsers and by most modern web frameworks and platforms. For the purposes of this cheat sheet we will refer to the technology generically as TLS. Recommendations regarding the use of SSL and TLS protocols, as well as browser support for TLS, can be found in the rule below titled [[Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Protocols| &amp;quot;Only Support Strong Protocols&amp;quot;]].&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs_cryptomodule.gif|thumb|350px|right|Cryptomodule Parts and Operation]]&lt;br /&gt;
&lt;br /&gt;
== When to Use a FIPS 140-2 Validated Cryptomodule ==&lt;br /&gt;
&lt;br /&gt;
If the web application may be the target of determined attackers (a common threat model for Internet accessible applications handling sensitive data), it is strongly advised to use TLS services that are provided by [http://csrc.nist.gov/groups/STM/cmvp/validation.html FIPS 140-2 validated cryptomodules]. &lt;br /&gt;
&lt;br /&gt;
A cryptomodule, whether it is a software library or a hardware device, basically consists of three parts:&lt;br /&gt;
&lt;br /&gt;
* Components that implement cryptographic algorithms (symmetric and asymmetric algorithms, hash algorithms, random number generator algorithms, and message authentication code algorithms) &lt;br /&gt;
* Components that call and manage cryptographic functions (inputs and outputs include cryptographic keys and so-called critical security parameters) &lt;br /&gt;
* A physical container around the components that implement cryptographic algorithms and the components that call and manage cryptographic functions&lt;br /&gt;
&lt;br /&gt;
The security of a cryptomodule and its services (and the web applications that call the cryptomodule) depend on the correct implementation and integration of each of these three parts. In addition, the cryptomodule must be used and accessed securely. The includes consideration for:&lt;br /&gt;
&lt;br /&gt;
* Calling and managing cryptographic functions&lt;br /&gt;
* Securely Handling inputs and output&lt;br /&gt;
* Ensuring the secure construction of the physical container around the components&lt;br /&gt;
&lt;br /&gt;
In order to leverage the benefits of TLS it is important to use a TLS service (e.g. library, web framework, web application server) which has been FIPS 140-2 validated. In addition, the cryptomodule must be installed, configured and operated in either an approved or an allowed mode to provide a high degree of certainty that the FIPS 140-2 validated cryptomodule is providing the expected security services in the expected manner.&lt;br /&gt;
&lt;br /&gt;
If the system is legally required to use FIPS 140-2 encryption (e.g., owned or operated by or on behalf of the U.S. Government) then TLS must be used and SSL disabled. Details on why SSL is unacceptable are described in Section 7.1 of [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf Implementation Guidance for FIPS PUB 140-2 and the Cryptographic Module Validation Program].&lt;br /&gt;
&lt;br /&gt;
Further reading on the use of TLS to protect highly sensitive data against determined attackers can be viewed in [http://csrc.nist.gov/publications/nistpubs/800-52/SP800-52.pdf SP800-52 Guidelines for the Selection and Use of Transport Layer Security (TLS) Implementations]&lt;br /&gt;
&lt;br /&gt;
== Secure Server Design  ==&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use TLS for All Login Pages and All Authenticated Pages  ===&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS. Failure to utilize TLS for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Use TLS on Any Networks (External and Internal) Transmitting Sensitive Data  ===&lt;br /&gt;
&lt;br /&gt;
All networks, both external and internal, which transmit sensitive data must utilize TLS or an equivalent transport layer security mechanism. It is not sufficient to claim that access to the internal network is &amp;quot;restricted to employees&amp;quot;. Numerous recent data compromises have shown that the internal network can be breached by attackers. In these attacks, sniffers have been installed to access unencrypted sensitive data sent on the internal network. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Provide Non-TLS Pages for Secure Content  ===&lt;br /&gt;
&lt;br /&gt;
All pages which are available over TLS must not be available over a non-TLS connection. A user may inadvertently bookmark or manually type a URL to a HTTP page (e.g. http://example.com/myaccount) within the authenticated portion of the application. If this request is processed by the application then the response, and any sensitive data, would be returned to the user over the clear text HTTP.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Mix TLS and Non-TLS Content  ===&lt;br /&gt;
&lt;br /&gt;
A page that is available over TLS must be comprised completely of content which is transmitted over TLS. The page must not contain any content that is transmitted over unencrypted HTTP. This includes content from unrelated third party sites. &lt;br /&gt;
&lt;br /&gt;
An attacker could intercept any of the data transmitted over the unencrypted HTTP and inject malicious content into the user's page. This malicious content would be included in the page even if the overall page is served over TLS. In addition, an attacker could steal the user's session cookie that is transmitted with any non-TLS requests. This is possible if the cookie's 'secure' flag is not set. See the rule 'Use &amp;quot;Secure&amp;quot; Cookie Flag'&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use &amp;quot;Secure&amp;quot; Cookie Flag  ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Secure&amp;quot; flag must be set for all user cookies. Failure to use the &amp;quot;secure&amp;quot; flag enables an attacker to access the session cookie by tricking the user's browser into submitting a request to an unencrypted page on the site. This attack is possible even if the server is not configured to offer HTTP content since the attacker is monitoring the requests and does not care if the server responds with a 404 or doesn't respond at all.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Keep Sensitive Data Out of the URL ===&lt;br /&gt;
&lt;br /&gt;
Sensitive data must not be transmitted via URL arguments. A more appropriate place is to store sensitive data in a server side repository or within the user's session.  When using TLS the URL arguments and values are encrypted during transit. However, there are two methods that the URL arguments and values could be exposed.&lt;br /&gt;
&lt;br /&gt;
1. The entire URL is cached within the local user's browser history. This may expose sensitive data to any other user of the workstation.&lt;br /&gt;
&lt;br /&gt;
2. The entire URL is exposed if the user clicks on a link to another HTTPS site. This may expose sensitive data within the referral field to the third party site. This exposure occurs in most browsers and will only occur on transitions between two TLS sites. &lt;br /&gt;
&lt;br /&gt;
For example, a user following a link on [http://owasp.org https://example.com] which leads to [http://owasp.org https://someOtherexample.com] would expose the full URL of [http://owasp.org https://example.com] (including URL arguments) in the referral header (within most browsers). This would not be the case if the user followed a link on [http://owasp.org https://example.com] to [http://owasp.org http://someHTTPexample.com]&lt;br /&gt;
&lt;br /&gt;
=== Rule - Prevent Caching of Sensitive Data ===&lt;br /&gt;
&lt;br /&gt;
The TLS protocol provides confidentiality only for data in transit but it does not help with potential data leakage issues at the client or intermediary proxies. As a result, it is frequently prudent to instruct these nodes not to cache or persist sensitive data. One option is to add anticaching headers to relevant HTTP responses, (for example, &amp;quot;Cache-Control: no-cache, no-store&amp;quot; and &amp;quot;Expires: 0&amp;quot; for coverage of many modern browsers as of 2013). For compatibility with HTTP/1.0 (i.e., when user agents are really old or the webserver works around quirks by forcing HTTP/1.0) the response should also include the header &amp;quot;Pragma: no-cache&amp;quot;. More information is available in [https://tools.ietf.org/html/rfc2616 HTTP 1.1 RFC 2616], section 14.9.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use HTTP Strict Transport Security ===&lt;br /&gt;
&lt;br /&gt;
See: [[HTTP Strict Transport Security]]&lt;br /&gt;
&lt;br /&gt;
===Rule - Use Public Key Pinning===&lt;br /&gt;
&lt;br /&gt;
See: [[Certificate and Public Key Pinning]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Server_Certificate_and_Protocol_Configuration&amp;quot;&amp;gt;&amp;lt;/span&amp;gt; &amp;lt;!-- backward compatible anchor --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Server Certificate ==&lt;br /&gt;
Note: If using a FIPS 140-2 cryptomodule disregard the following rules and defer to the recommended configuration for the particular cryptomodule. Nevertheless we recommend to use this rules to audit your configuration.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use Strong Keys &amp;amp; Protect Them ===&lt;br /&gt;
&lt;br /&gt;
The private key used to generate the cipher key must be sufficiently strong for the anticipated lifetime of the private key and corresponding certificate. The current best practice is to select a key size of at least 2048 bits. Additional information on key lifetimes and comparable key strengths can be found in [http://www.keylength.com/en/compare/], [http://csrc.nist.gov/publications/nistpubs/800-57/sp800-57_part1_rev3_general.pdf NIST SP 800-57]. In addition, the private key must be stored in a location that is protected from unauthorized access.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use a Certificate That Supports Required Domain Names ===&lt;br /&gt;
&lt;br /&gt;
A user should never be presented with a certificate error, including prompts to reconcile domain or hostname mismatches, or expired certificates. If the application is available at both [https://owasp.org https://www.example.com] and [https://owasp.org https://example.com] then an appropriate certificate, or certificates, must be presented to accommodate the situation. The presence of certificate errors desensitizes users to TLS error messages and increases the possibility an attacker could launch a convincing phishing or man-in-the-middle attack.&lt;br /&gt;
&lt;br /&gt;
For example, consider a web application accessible at [https://owasp.org https://abc.example.com] and [https://owasp.org https://xyz.example.com]. One certificate should be acquired for the host or server ''abc.example.com''; and a second certificate for host or server ''xyz.example.com''. In both cases, the hostname would be present in the Subject's Common Name (CN).&lt;br /&gt;
&lt;br /&gt;
Alternatively, the Subject Alternate Names (SANs) can be used to provide a specific listing of multiple names where the certificate is valid. In the example above, the certificate could list the Subject's CN as ''example.com'', and list two SANs: ''abc.example.com'' and ''xyz.example.com''. These certificates are sometimes referred to as &amp;quot;multiple domain certificates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use Fully Qualified Names in Certificates ===&lt;br /&gt;
&lt;br /&gt;
Use fully qualified names in the DNS name field, and do not use unqualifed names (e.g., 'www'), local names (e.g., 'localhost'), or private IP addresses (e.g., 192.168.1.1) in the DNS name field. Unqualifed names, local names, or private IP addresses violate the certificate specification.&lt;br /&gt;
 &lt;br /&gt;
=== Rule - Do Not Use Wildcard Certificates ===&lt;br /&gt;
&lt;br /&gt;
You should refrain from using wildcard certificates. Though they are expedient at circumventing annoying user prompts, they also [[Least_privilege|violate the principal of least privilege]] and asks the user to trust all machines, including developer's machines, the secretary's machine in the lobby and the sign-in kiosk. Obtaining access to the private key is left as an exercise for the attacker, but its made much easier when stored on the file system unprotected.&lt;br /&gt;
&lt;br /&gt;
Statistics gathered by Qualys for [http://media.blackhat.com/bh-us-10/presentations/Ristic/BlackHat-USA-2010-Ristic-Qualys-SSL-Survey-HTTP-Rating-Guide-slides.pdf Internet SSL Survey 2010] indicate wildcard certificates have a 4.4% share, so the practice is not standard for public facing hosts. Finally, wildcard certificates violate [https://www.cabforum.org/EV_Certificate_Guidelines.pdf EV Certificate Guidelines].&lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Use RFC 1918 Addresses in Certificates ===&lt;br /&gt;
&lt;br /&gt;
Certificates should not use private addresses. RFC 1918 is [https://tools.ietf.org/html/rfc1918 Address Allocation for Private Internets]. Private addresses are Internet Assigned Numbers Authority (IANA) reserved and include 192.168/16, 172.16/12, and 10/8.&lt;br /&gt;
&lt;br /&gt;
Certificates issued with private addresses violate [https://www.cabforum.org/EV_Certificate_Guidelines.pdf EV Certificate Guidelines]. In addition, Peter Gutmann writes in in [http://www.cs.auckland.ac.nz/~pgut001/pubs/book.pdf Engineering Security]: &amp;quot;This one is particularly troublesome because, in combination with the router-compromise attacks... and ...OSCP-defeating measures, it allows an attacker to spoof any EV-certificate site.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use an Appropriate Certification Authority for the Application's User Base  ===&lt;br /&gt;
&lt;br /&gt;
An application user must never be presented with a warning that the certificate was signed by an unknown or untrusted authority. The application's user population must have access to the public certificate of the certification authority which issued the server's certificate. For Internet accessible websites, the most effective method of achieving this goal is to purchase the TLS certificate from a recognize certification authority. Popular Internet browsers already contain the public certificates of these recognized certification authorities. &lt;br /&gt;
&lt;br /&gt;
Internal applications with a limited user population can use an internal certification authority provided its public certificate is securely distributed to all users. However, remember that all certificates issued by this certification authority will be trusted by the users. Therefore, utilize controls to protect the private key and ensure that only authorized individuals have the ability to sign certificates. &lt;br /&gt;
&lt;br /&gt;
The use of self signed certificates is never acceptable. Self signed certificates negate the benefit of end-point authentication and also significantly decrease the ability for an individual to detect a man-in-the-middle attack. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Always Provide All Needed Certificates ===&lt;br /&gt;
&lt;br /&gt;
Clients attempt to solve the problem of identifying a server or host using PKI and X509 certificate. When a user receives a server or host's certificate, the certificate must be validated back to a trusted root certification authority. This is known as path validation.&lt;br /&gt;
&lt;br /&gt;
There can be one or more intermediate certificates in between the end-entity (server or host) certificate and root certificate. In addition to validating both endpoints, the user will also have to validate all intermediate certificates. Validating all intermediate certificates can be tricky because the user may not have them locally. This is a well-known PKI issue called the “Which Directory?&amp;quot; problem.&lt;br /&gt;
&lt;br /&gt;
To avoid the “Which Directory?&amp;quot; problem, a server should provide the user with all required certificates used in a path validation.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Be aware of and have a plan for the SHA-1 deprecation plan  ===&lt;br /&gt;
&lt;br /&gt;
In order to avoid presenting end users with progressive certificate warnings, organizations must proactively address the browser vendor's upcoming SHA-1 deprecation plans. The Google Chrome plan is probably the most specific and aggressive at this point: [http://googleonlinesecurity.blogspot.com/2014/09/gradually-sunsetting-sha-1.html Gradually sunsetting SHA-1]&lt;br /&gt;
&lt;br /&gt;
If your organization has no [https://support.globalsign.com/customer/portal/articles/1499561-sha-256-compatibility SHA256 compatibility issues] then it may be appropriate to move your site to a SHA256 signed certificate/chain.  If there are, or may be, issues - you should ensure that your SHA-1 certificates expire before 1/1/2017. &lt;br /&gt;
&lt;br /&gt;
== Server Protocol and Cipher Configuration ==&lt;br /&gt;
Note: If using a FIPS 140-2 cryptomodule disregard the following rules and defer to the recommended configuration for the particular cryptomodule. Nevertheless we recommend to use this rules to audit your configuration.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Strong Protocols ===&lt;br /&gt;
&lt;br /&gt;
SSL/TLS is a collection of protocols. Weaknesses have been identified with earlier SSL protocols, including [http://www.schneier.com/paper-ssl-revised.pdf SSLv2] and [http://www.yaksman.org/~lweith/ssl.pdf SSLv3] hence SSL versions 1, 2 and 3 should not longer be used. The best practice for transport layer protection is to only provide support for the TLS protocols - TLS1.0, TLS 1.1 and TLS 1.2. This configuration will provide maximum protection against skilled and determined attackers and is appropriate for applications handling sensitive data or performing critical operations.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Transport_Layer_Security#Web_browsers Nearly all modern browsers support at least TLS 1.0]. As of February 2013, contemporary browsers (Chrome v20+, IE v8+, Opera v10+, and Safari v5+) [http://en.wikipedia.org/wiki/Transport_Layer_Security#Web_browsers support TLS 1.1 and TLS 1.2]. You should provide support for TLS 1.1 and TLS 1.2 to accommodate clients which support the protocols. The client and server (usually) negotiate the best protocol, that is supported on both sides.&lt;br /&gt;
&lt;br /&gt;
TLS 1.0 is still widely used as 'best' protocol by a lot of browsers, that are not patched to the very latest version. It suffers [http://www.yassl.com/yaSSL/Blog/Entries/2010/10/7_Differences_between_SSL_and_TLS_Protocol_Versions.html CBC Chaining attacks and Padding Oracle attacks]. TLSv1.0 should only be used only after risk analysis and acceptance.&lt;br /&gt;
&lt;br /&gt;
Under no circumstances neither SSLv2 nor SSLv3 should be enabled as a protocol selection:&lt;br /&gt;
* The [http://www.schneier.com/paper-ssl-revised.pdf SSLv2 protocol is broken] and does not provide adequate transport layer protection.&lt;br /&gt;
* [http://www.yaksman.org/~lweith/ssl.pdf SSLv3 had been known for weaknesses] which severely compromise the channel's security long before the [https://www.openssl.org/~bodo/ssl-poodle.pdf 'POODLE'-Bug] finally stopped to tolerate this protocol by October 2014. Switching off SSLv3 terminates the support of legacy browsers like [https://www.ssllabs.com/ssltest/viewClient.html?name=IE&amp;amp;version=6&amp;amp;platform=XP IE6/XP] and elder.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Prefer Ephemeral Key Exchanges ===&lt;br /&gt;
&lt;br /&gt;
Ephemeral key exchanges are based on Diffie-Hellman and use per-session, temporary keys during the initial SSL/TLS handshake. They provide perfect forward secrecy (PFS), which means a compromise of the server's long term signing key does not compromise the confidentiality of past session (see [[#Rule_-_Only_Support_Strong_Cryptographic_Ciphers | following rule]]). When the server uses an ephemeral key, the server will sign the temporary key with its long term key (the long term key is the customary key available in its certificate).&lt;br /&gt;
&lt;br /&gt;
Use cryptographic parameters (like DH-parameter) that use a secure length that match to the supported keylength of your certificate (&amp;gt;=2048 bits or equivalent Elliptic Curves). As some middleware had some issues with this, upgrade to the latest version.&lt;br /&gt;
&lt;br /&gt;
If you have a server farm and are providing forward secrecy, then you might have to disable session resumption. For example, Apache writes the session id's and master secrets to disk so all servers in the farm can participate in resuming a session (there is currently no in-memory mechanism to achieve the sharing). Writing the session id and master secret to disk undermines forward secrecy.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Strong Cryptographic Ciphers  ===&lt;br /&gt;
&lt;br /&gt;
Each protocol (TLSv1.0, TLSv1.1, TLSv1.2, etc) provides cipher suites. As of TLS 1.2, [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 there is support for over 300 suites (320+ and counting)], including [http://www.mail-archive.com/cryptography@randombit.net/msg03785.html national vanity cipher suites]. The strength of the encryption used within a TLS session is determined by the encryption cipher negotiated between the server and the browser. In order to ensure that only strong cryptographic ciphers are selected the server must be modified to disable the use of weak ciphers and to configure the ciphers in an adequate order. It is recommended to configure the server to only support strong ciphers and to use sufficiently large key sizes. In general, the following should be observed when selecting CipherSuites:&lt;br /&gt;
* Use the very latest recommendations, they may be volantile these days&lt;br /&gt;
* Setup your Policy to get a Whitelist for recommended Ciphers, e.g.:&lt;br /&gt;
** Activate to set the Cipher Order by the Server&lt;br /&gt;
** Highest Priority for Ciphers that support 'Forward Secrecy' (-&amp;gt; Support ephemeral Diffie-Hellman key exchange, see rule above) [http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html]&lt;br /&gt;
** Favor DHE over ECDHE (and monitor the CPU usage, see Notes below), ECDHE lacks now of really reliable Elliptic Curves, see discussion about secp{224,256,384,521}r1 and secp256k1, cf. [http://safecurves.cr.yp.to], [https://www.schneier.com/blog/archives/2013/09/the_nsa_is_brea.html#c1675929]. The solution might be to use [http://www.researchgate.net/profile/Johannes_Merkle/publication/260050106_Standardisierung_der_Brainpool-Kurven_fr_TLS_und_IPSec/file/60b7d52f36a0cc2fdd.pdf Brainpool Curves &amp;lt;nowiki&amp;gt;[German]&amp;lt;/nowiki&amp;gt;], defined for TLS in [https://tools.ietf.org/html/rfc7027 RFC 7027], or [http://eprint.iacr.org/2007/286 Edwards Curves]. The most promising candidates for the latter are [https://tools.ietf.org/html/draft-josefsson-tls-curve25519-06 'Curve25519'] and [http://sourceforge.net/p/ed448goldilocks/wiki/Home/ Ed448-Goldilocks] (see [https://tools.ietf.org/html/draft-irtf-cfrg-curves-02 DRAFT-irtf-cfrg-curves]), that is not yet defined for TLS, cf. [http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8 IANA] &amp;lt;!--- as at June 2014 ---&amp;gt;&lt;br /&gt;
** Use RSA-Keys (no DSA/DSS: they get very weak, if a bad entropy source is used during signing, cf. [https://projectbullrun.org/dual-ec/tls.html], [https://factorable.net/weakkeys12.conference.pdf]) &amp;lt;!--- as at June 2014 ---&amp;gt;&lt;br /&gt;
** Favor GCM over CBC regardless of the cipher size. In other words, use Authenticated Encryption with Associated Data (AEAD), e.g. AES-GCM, AES-CCM.&lt;br /&gt;
** Watch also for Stream Ciphers which XOR the key stream with plaintext (such as AES/CTR mode) &amp;lt;!--- Jim please check this ---&amp;gt;&lt;br /&gt;
** Priorize the ciphers by the sizes of the Cipher and the MAC&lt;br /&gt;
** Use SHA1 or above for digests, prefer SHA2 (or equivalent)&lt;br /&gt;
** Disable weak ciphers (which is implicitly done by this whitelist) without disabling legacy browsers and bots that have to be supported (find the best compromise), actually the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA (0xa) does this job.&lt;br /&gt;
*** Disable cipher suites that do not offer encryption (eNULL, NULL)&lt;br /&gt;
*** Disable cipher suites that do not offer authentication (aNULL). aNULL includes anonymous cipher suites ADH (Anonymous Diffie-Hellman) and AECDH (Anonymous Elliptic Curve Diffie Hellman).&lt;br /&gt;
*** Disable export level ciphers (EXP, eg. ciphers containing DES)&lt;br /&gt;
*** Disable key sizes smaller than 128 bits for encrypting payload traffic (see [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI: TR-02102 Part 2 (German)])&lt;br /&gt;
*** Disable the use of MD5 as a hashing mechanism for payload traffic&lt;br /&gt;
*** Disable the use of IDEA Cipher Suites (see [https://tools.ietf.org/html/rfc5469])&lt;br /&gt;
*** Disable RC4 cipher suites (see [https://tools.ietf.org/html/rfc7465], [http://www.isg.rhul.ac.uk/tls/])&lt;br /&gt;
** Ciphers should be usable for DH-Pamameters &amp;gt;= 2048 bits, without blocking legacy browsers (The cipher ‘DHE-RSA-AES128-SHA’ is suppressed as some browsers like to use it but are not capable to cope with DH-Params &amp;gt; 1024 bits.)&lt;br /&gt;
* Define a Cipher String that works with different Versions of your encryption tool, like openssl&lt;br /&gt;
* Verify your cipher string&lt;br /&gt;
** with an audit-tool, like [[O-Saft|OWASP 'O-Saft' (OWASP SSL audit for testers / OWASP SSL advanced forensic tool)]]&lt;br /&gt;
** listing it manually with your encryption software, e.g. openssl ciphers -v &amp;lt;cipher-string&amp;gt; (the result may differ by version), e.g.:&lt;br /&gt;
{{Top_10_2010:ExampleBeginTemplate|year=2013}} &lt;br /&gt;
openssl ciphers -v &amp;quot;EDH+aRSA+AESGCM:EDH+aRSA+AES:DHE-RSA-AES256-SHA:EECDH+aRSA+AESGCM:EECDH+aRSA+AES:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:RSA+AESGCM:RSA+AES+SHA:DES-CBC3-SHA:-DHE-RSA-AES128-SHA&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;add optionally ':!aNULL:!eNULL:!LOW:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:!ADH:!IDEA' to protect older Versions of OpenSSL&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;you may use openssl ciphers -V &amp;quot;...&amp;quot; for openssl &amp;gt;= 1.0.1:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 0x00,0x9F - DHE-RSA-AES256-GCM-SHA384   TLSv1.2 Kx=DH     Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0x00,0x9E - DHE-RSA-AES128-GCM-SHA256   TLSv1.2 Kx=DH     Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0x00,0x6B - DHE-RSA-AES256-SHA256       TLSv1.2 Kx=DH     Au=RSA  Enc=AES(256)    Mac=SHA256&lt;br /&gt;
 0x00,0x39 - DHE-RSA-AES256-SHA          SSLv3   Kx=DH     Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0x00,0x67 - DHE-RSA-AES128-SHA256       TLSv1.2 Kx=DH     Au=RSA  Enc=AES(128)    Mac=SHA256&lt;br /&gt;
 0xC0,0x30 - ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH   Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0xC0,0x2F - ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH   Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0xC0,0x28 - ECDHE-RSA-AES256-SHA384     TLSv1.2 Kx=ECDH   Au=RSA  Enc=AES(256)    Mac=SHA384&lt;br /&gt;
 0xC0,0x14 - ECDHE-RSA-AES256-SHA        SSLv3   Kx=ECDH   Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0xC0,0x27 - ECDHE-RSA-AES128-SHA256     TLSv1.2 Kx=ECDH   Au=RSA  Enc=AES(128)    Mac=SHA256&lt;br /&gt;
 0xC0,0x13 - ECDHE-RSA-AES128-SHA        SSLv3   Kx=ECDH   Au=RSA  Enc=AES(128)    Mac=SHA1&lt;br /&gt;
 0x00,0x9D - AES256-GCM-SHA384           TLSv1.2 Kx=RSA    Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0x00,0x9C - AES128-GCM-SHA256           TLSv1.2 Kx=RSA    Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0x00,0x35 - AES256-SHA                  SSLv3   Kx=RSA    Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0x00,0x2F - AES128-SHA                  SSLv3   Kx=RSA    Au=RSA  Enc=AES(128)    Mac=SHA1&lt;br /&gt;
 0x00,0x0A - DES-CBC3-SHA                SSLv3   Kx=RSA    Au=RSA  Enc=3DES(168)   Mac=SHA1&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
{{Top_10_2010:ExampleEndTemplate}}&lt;br /&gt;
&lt;br /&gt;
* Inform yourself how to securely configure the settings for your used services or hardware, e.g. [https://bettercrypto.org BetterCrypto.org: Applied Crypto Hardening (DRAFT)]&lt;br /&gt;
* Check new software and hardware versions for new security settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Notes:&amp;lt;/b&amp;gt;&lt;br /&gt;
* According to my researches the most common browsers should be supported with this setting, too (see also [https://www.ssllabs.com/ssltest/index.html SSL Labs: SSL Server Test -&amp;gt; SSL Report -&amp;gt; Handshake Simulation]).&lt;br /&gt;
* Monitor the performance of your server, e.g. the TLS handshake with DHE hinders the CPU abt 2.4 times more than ECDHE, cf. [http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html#some-benchmarks Vincent Bernat, 2011], [http://nmav.gnutls.org/2011/12/price-to-pay-for-perfect-forward.html nmav's Blog, 2011].&lt;br /&gt;
* Use of Ephemeral Diffie-Hellman key exchange will protect confidentiality of the transmitted plaintext data even if the corresponding RSA or DSS server private key got compromised. An attacker would have to perform active man-in-the-middle attack at the time of the key exchange to be able to extract the transmitted plaintext. All modern browsers support this key exchange with the notable exception of Internet Explorer prior to Windows Vista.&lt;br /&gt;
&lt;br /&gt;
Additional information can be obtained within the [https://tools.ietf.org/html/rfc5246 TLS 1.2 RFC 5246], [https://www.ssllabs.com/projects/best-practices/index.html SSL Labs: 'SSL/TLS Deployment Best Practices'], [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI: 'TR-02102 Part 2 (German)'], [http://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/algorithms-key-sizes-and-parameters-report ENISA: 'Algorithms, Key Sizes and Parameters Report'], [https://tools.ietf.org/html/rfc7525 RFC 7525: Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)] and [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf FIPS 140-2 IG].&lt;br /&gt;
&lt;br /&gt;
=== Rule - Support TLS-PSK and TLS-SRP for Mutual Authentication ===&lt;br /&gt;
&lt;br /&gt;
When using a shared secret or password offer TLS-PSK (Pre-Shared Key) or TLS-SRP (Secure Remote Password), which are known as Password Authenticated Key Exchange (PAKEs). TLS-PSK and TLS-SRP properly bind the channel, which refers to the cryptographic binding between the outer tunnel and the inner authentication protocol. IANA currently reserves [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 79 PSK cipehr suites] and [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 9 SRP cipher suites].&lt;br /&gt;
&lt;br /&gt;
Basic authentication places the user's password on the wire in the plain text after a server authenticates itself. Basic authentication only provides unilateral authentication. In contrast, both TLS-PSK and TLS-SRP provide mutual authentication, meaning each party proves it knows the password without placing the password on the wire in the plain text.&lt;br /&gt;
&lt;br /&gt;
Finally, using a PAKE removes the need to trust an outside party, such as a Certification Authority (CA).&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Secure Renegotiations  ===&lt;br /&gt;
&lt;br /&gt;
A design weakness in TLS, identified as [http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2009-3555 CVE-2009-3555], allows an attacker to inject a plaintext of his choice into a TLS session of a victim. In the HTTPS context the attacker might be able to inject his own HTTP requests on behalf of the victim. The issue can be mitigated either by disabling support for TLS renegotiations or by supporting only renegotiations compliant with [https://tools.ietf.org/html/rfc5746 RFC 5746]. All modern browsers have been updated to comply with this RFC.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Disable Compression ===&lt;br /&gt;
&lt;br /&gt;
Compression Ratio Info-leak Made Easy (CRIME) is an exploit against the data compression scheme used by the TLS and SPDY protocols. The exploit allows an adversary to recover user authentication cookies from HTTPS. The recovered cookie can be subsequently used for session hijacking attacks.&lt;br /&gt;
&lt;br /&gt;
== Test your overall TLS/SSL setup and your Certificate ==&lt;br /&gt;
This section shows the most common references only. For more tools and such, please refer to [[#Tools|Tools]].&lt;br /&gt;
&lt;br /&gt;
* [[Testing_for_SSL-TLS_%28OWASP-CM-001%29 | OWASP Testing Guide: Chapter on SSL/TLS Testing]]&lt;br /&gt;
* [[O-Saft|OWASP 'O-Saft' (OWASP SSL audit for testers / OWASP SSL advanced forensic tool)]]&lt;br /&gt;
* [https://www.ssllabs.com/ssltest SSL LABS Server Test]&lt;br /&gt;
* other Tools: [[Testing_for_Weak_SSL/TSL_Ciphers,_Insufficient_Transport_Layer_Protection_%28OWASP-EN-002%29#References| Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002) (DRAFT)]] - References - Tools&lt;br /&gt;
&lt;br /&gt;
== Client (Browser) Configuration  ==&lt;br /&gt;
&lt;br /&gt;
The validation procedures to ensure that a certificate is valid are complex and difficult to correctly perform.  In a typical web application model, these checks will be performed by the client's web browser in accordance with local browser settings and are out of the control of the application. However, these items do need to be addressed in the following scenarios:&lt;br /&gt;
&lt;br /&gt;
* The application server establishes connections to other applications over TLS for purposes such as web services or any exchange of data&lt;br /&gt;
* A thick client application is connecting to a server via TLS&lt;br /&gt;
&lt;br /&gt;
In these situations extensive certificate validation checks must occur in order to establish the validity of the certificate. Consult the following resources to assist in the design and testing of this functionality. The NIST PKI testing site includes a full test suite of certificates and expected outcomes of the test cases.&lt;br /&gt;
* [http://csrc.nist.gov/groups/ST/crypto_apps_infra/pki/pkitesting.html NIST PKI Testing]&lt;br /&gt;
* [https://tools.ietf.org/html/rfc5280 IETF RFC 5280]&lt;br /&gt;
&lt;br /&gt;
As specified in the above guidance, if the certificate can not be validated for any reason then the connection between the client and server must be dropped. Any data exchanged over a connection where the certificate has not properly been validated could be exposed to unauthorized access or modification.&lt;br /&gt;
&lt;br /&gt;
== Additional Controls  ==&lt;br /&gt;
&lt;br /&gt;
=== Extended Validation Certificates  ===&lt;br /&gt;
&lt;br /&gt;
Extended validation certificates (EV Certificates) proffer an enhanced investigation by the issuer into the requesting party due to the industry's race to the bottom. The purpose of EV certificates is to provide the user with greater assurance that the owner of the certificate is a verified legal entity for the site. Browsers with support for EV certificates distinguish an EV certificate in a variety of ways. Internet Explorer will color a portion of the URL in green, while Mozilla will add a green portion to the left of the URL indicating the company name. &lt;br /&gt;
&lt;br /&gt;
High value websites should consider the use of EV certificates to enhance customer confidence in the certificate. It should also be noted that EV certificates do not provide any greater technical security for the TLS. The purpose of the EV certificate is to increase user confidence that the target site is indeed who it claims to be.&lt;br /&gt;
&lt;br /&gt;
=== Client-Side Certificates  ===&lt;br /&gt;
&lt;br /&gt;
Client side certificates can be used with TLS to prove the identity of the client to the server. Referred to as &amp;quot;two-way TLS&amp;quot;, this configuration requires the client to provide their certificate to the server, in addition to the server providing their's to the client. If client certificates are used, ensure that the same validation of the client certificate is performed by the server, as indicated for the validation of server certificates above. In addition, the server should be configured to drop the TLS connection if the client certificate cannot be verified or is not provided. &lt;br /&gt;
&lt;br /&gt;
The use of client side certificates is relatively rare currently due to the complexities of certificate generation, safe distribution, client side configuration, certificate revocation and reissuance, and the fact that clients can only authenticate on machines where their client side certificate is installed. Such certificates are typically used for very high value connections that have small user populations.&lt;br /&gt;
&lt;br /&gt;
=== Certificate and Public Key Pinning ===&lt;br /&gt;
&lt;br /&gt;
Hybrid and native applications can take advantage of [[Certificate_and_Public_Key_Pinning|certificate and public key pinning]]. Pinning associates a host (for example, server) with an identity (for example, certificate or public key), and allows an application to leverage knowledge of the pre-existing relationship. At runtime, the application would inspect the certificate or public key received after connecting to the server. If the certificate or public key is expected, then the application would proceed as normal. If unexpected, the application would stop using the channel and close the connection since an adversary could control the channel or server.&lt;br /&gt;
&lt;br /&gt;
Pinning still requires customary X509 checks, such as revocation, since CRLs and OCSP provides real time status information. Otherwise, an application could possibly (1) accept a known bad certificate; or (2) require an out-of-band update, which could result in a lengthy App Store approval.&lt;br /&gt;
&lt;br /&gt;
Browser based applications are at a disadvantage since most browsers do not allow the user to leverage pre-existing relationships and ''a priori'' knowledge. In addition, Javascript and Websockets do not expose methods to for a web app to query the underlying secure connection information (such as the certificate or public key). It is noteworthy that Chromium based browsers perform pinning on selected sites, but the list is currently maintained by the vendor.&lt;br /&gt;
&lt;br /&gt;
For more information, please see the [[Pinning Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Providing Transport Layer Protection for Back End and Other Connections  =&lt;br /&gt;
&lt;br /&gt;
Although not the focus of this cheat sheet, it should be stressed that transport layer protection is necessary for back-end connections and any other connection where sensitive data is exchanged or where user identity is established. Failure to implement an effective and robust transport layer security will expose sensitive data and undermine the effectiveness of any authentication or access control mechanism. &lt;br /&gt;
&lt;br /&gt;
== Secure Internal Network Fallacy  ==&lt;br /&gt;
&lt;br /&gt;
The internal network of a corporation is not immune to attacks. Many recent high profile intrusions, where thousands of sensitive customer records were compromised, have been perpetrated by attackers that have gained internal network access and then used sniffers to capture unencrypted data as it traversed the internal network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Tools =&lt;br /&gt;
=== local/offline ===&lt;br /&gt;
* [[O-Saft|O-Saft - OWASP SSL advanced forensic tool)]]&lt;br /&gt;
* [http://sourceforge.net/projects/sslscan/ SSLScan - Fast SSL Scanner]&lt;br /&gt;
* [https://github.com/iSECPartners/sslyze SSLyze]&lt;br /&gt;
* [http://www.g-sec.lu/sslaudit/sslaudit.zip SSL Audit]&lt;br /&gt;
&lt;br /&gt;
=== Online ===&lt;br /&gt;
* [https://www.ssllabs.com/ssltest SSL LABS Server Test]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
* Mozilla – [https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations Mozilla Recommended Configurations]&lt;br /&gt;
* OWASP – [[Testing for SSL-TLS (OWASP-CM-001)|Testing for SSL-TLS]], and OWASP [[Guide to Cryptography]] &lt;br /&gt;
* OWASP – [http://www.owasp.org/index.php/ASVS Application Security Verification Standard (ASVS) – Communication Security Verification Requirements (V10)]&lt;br /&gt;
* OWASP – ASVS Article on [[Why you need to use a FIPS 140-2 validated cryptomodule]]&lt;br /&gt;
* SSL Labs – [https://www.ssllabs.com/projects/best-practices/index.html SSL/TLS Deployment Best Practices]&lt;br /&gt;
* SSL Labs – [http://www.ssllabs.com/projects/rating-guide/index.html SSL Server Rating Guide]&lt;br /&gt;
* ENISA – [http://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/algorithms-key-sizes-and-parameters-report Algorithms, Key Sizes and Parameters Report]&lt;br /&gt;
* BSI   – [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI TR-02102 Part 2 (German)]&lt;br /&gt;
* yaSSL – [http://www.yassl.com/yaSSL/Blog/Entries/2010/10/7_Differences_between_SSL_and_TLS_Protocol_Versions.html Differences between SSL and TLS Protocol Versions]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/PubsSPs.html#800-52 SP 800-52 Rev. 1 Guidelines for the Selection, Configuration, and Use of Transport Layer Security (TLS) Implementations]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/fips/fips140-2/fips1402.pdf FIPS 140-2 Security Requirements for Cryptographic Modules]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf Implementation Guidance for FIPS PUB 140-2 and the Cryptographic Module Validation Program]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/nistpubs/800-57/sp800-57_part1_rev3_general.pdf NIST SP 800-57 Recommendation for Key Management, Revision 3], [http://csrc.nist.gov/publications/PubsDrafts.html#SP-800-57-Part%203-Rev.1 Public DRAFT]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/drafts.html#sp800-95 SP 800-95 Guide to Secure Web Services] &lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc5280 RFC 5280 Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc2246 RFC 2246 The Transport Layer Security (TLS) Protocol Version 1.0 (JAN 1999)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc4346 RFC 4346 The Transport Layer Security (TLS) Protocol Version 1.1 (APR 2006)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc5246 RFC 5246 The Transport Layer Security (TLS) Protocol Version 1.2 (AUG 2008)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc7525 RFC 7525 Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)]&lt;br /&gt;
* bettercrypto - [https://bettercrypto.org Applied Crypto Hardening: HOWTO for secure crypto settings of the most common services (DRAFT)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Michael Coates - michael.coates[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Dave Wichers - dave.wichers[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Michael Boberski - boberski_michael[at]bah.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Tyler Reguly -treguly[at]sslfail.com&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;padding-left:25px;width:300px;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
[[Category:OWASP Best Practices]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=HTTP_Strict_Transport_Security&amp;diff=195987</id>
		<title>HTTP Strict Transport Security</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=HTTP_Strict_Transport_Security&amp;diff=195987"/>
				<updated>2015-06-09T20:53:11Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Links */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS. It also prevents HTTPS click through prompts on browsers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The specification has been released and published end of 2012 as RFC 6797 (HTTP Strict Transport Security (HSTS)) by the IETF. (Reference see in the links at the bottom.)&lt;br /&gt;
&lt;br /&gt;
== Examples  ==&lt;br /&gt;
&lt;br /&gt;
Simple example, using a long (1 year) max-age:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000&lt;br /&gt;
&lt;br /&gt;
If all present and future subdomains will be HTTPS:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000; includeSubDomains&lt;br /&gt;
&lt;br /&gt;
'''Recommended:''' If the site owner would like their domain to be included in the [https://hstspreload.appspot.com/ HSTS preload list] maintained by Chrome (and used by Firefox and Safari), then use:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;br /&gt;
&lt;br /&gt;
The `preload` flag indicates the site owner's consent to have their domain preloaded. The site owner still needs to then go and submit the domain to the list.&lt;br /&gt;
&lt;br /&gt;
== Excessively Strict STS ==&lt;br /&gt;
&lt;br /&gt;
Use caution when setting excessively strict STS policies. Including subdomains should only be used in environments where all sites within your organization for the given domain name require ssl. Max-age limits should be carefully considered as infrequent visitors may find your site inaccessible if you relax your policy.&lt;br /&gt;
&lt;br /&gt;
Before enabling includeSubDomains, also consider the impact of any existing DNS CNAME records for CDNs, email services, or other 3rd party services.  Since includeSubDomains will force such CNAME subdomains to https:// it's likely the browser will throw a domain-mismatch error, which is hard to reverse because of the browser caching nature of HSTS.&lt;br /&gt;
&lt;br /&gt;
== Browser Support ==&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;400&amp;quot; cellspacing=&amp;quot;1&amp;quot; cellpadding=&amp;quot;1&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| '''Browser'''&amp;lt;br&amp;gt;&lt;br /&gt;
| '''Support Introduced'''&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Internet Explorer &amp;lt;br&amp;gt;&lt;br /&gt;
| support expected starting with ie12[https://threatpost.com/ie-12-to-support-hsts-encryption-protocol/105266]&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Firefox&amp;lt;br&amp;gt;&lt;br /&gt;
| 4&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Opera&amp;lt;br&amp;gt;&lt;br /&gt;
| 12&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Safari&amp;lt;br&amp;gt;&lt;br /&gt;
| Mavericks (Mac OS X 10.9)&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Chrome&amp;lt;br&amp;gt;&lt;br /&gt;
| 4.0.211.0&amp;lt;br&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
A detailed overview of supporting browsers can be found at [http://caniuse.com/#feat=stricttransportsecurity caniuse.com].&lt;br /&gt;
== Server Side ==&lt;br /&gt;
&lt;br /&gt;
The web server side needs to inject the HSTS header. &lt;br /&gt;
&lt;br /&gt;
For HTTP sites on the same domain it is [http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec#section-6.1 not recommended] to add a HSTS header but to do a permanent redirect (301 status code) to the HTTPS site.&lt;br /&gt;
 &lt;br /&gt;
An Apache HTTPd example that will permanently redirect a URL to the identical URL with a HTTPS scheme, is as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerAlias *&lt;br /&gt;
        RewriteEngine On&lt;br /&gt;
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [redirect=301]&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the HTTPS site configuration the following is needed to add the header as [http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec#section-6.1 recommended by the standard]:&lt;br /&gt;
        Header always set Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following links show how to set response headers in other web servers:&lt;br /&gt;
* [http://wiki.nginx.org/HttpHeadersModule NGINX]&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModSetEnv#Options Lighttpd]&lt;br /&gt;
* [http://httpd.apache.org/docs/2.2/mod/mod_headers.html HTTPd]&lt;br /&gt;
&lt;br /&gt;
==== IIS ====&lt;br /&gt;
Whilst [http://technet.microsoft.com/en-us/library/cc753133(WS.10).aspx custom headers] can be configured in IIS without any extensions, it is not possible to restrict these headers to secure transport channels [http://tools.ietf.org/html/rfc6797#section-7.2 as per the HSTS specification]. This leaves the following options. &lt;br /&gt;
&lt;br /&gt;
===== Custom Module =====&lt;br /&gt;
HSTS has been implemented, per the specification, as an [http://hstsiis.codeplex.com/ open source IIS module].&lt;br /&gt;
&lt;br /&gt;
===== URL Rewrite =====&lt;br /&gt;
Install [http://www.iis.net/downloads/microsoft/url-rewrite Microsoft URL Rewrite] and use following rewrite rules.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.webServer&amp;gt;&lt;br /&gt;
    &amp;lt;rewrite&amp;gt;&lt;br /&gt;
      &amp;lt;rules&amp;gt;&lt;br /&gt;
        &amp;lt;rule name=&amp;quot;HTTPS_301_Redirect&amp;quot; stopProcessing=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;match url=&amp;quot;(.*)&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;conditions&amp;gt;&lt;br /&gt;
            &amp;lt;add input=&amp;quot;{HTTPS}&amp;quot; pattern=&amp;quot;^OFF$&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;/conditions&amp;gt;&lt;br /&gt;
          &amp;lt;action type=&amp;quot;Redirect&amp;quot; url=&amp;quot;https://{HTTP_HOST}{REQUEST_URI}&amp;quot; appendQueryString=&amp;quot;false&amp;quot; redirectType=&amp;quot;Permanent&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/rule&amp;gt;&lt;br /&gt;
      &amp;lt;/rules&amp;gt;&lt;br /&gt;
      &amp;lt;outboundRules&amp;gt;&lt;br /&gt;
        &amp;lt;rule name=&amp;quot;Add_HSTS_Header&amp;quot; preCondition=&amp;quot;USING_HTTPS&amp;quot; patternSyntax=&amp;quot;Wildcard&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;match serverVariable=&amp;quot;RESPONSE_Strict-Transport-Security&amp;quot; pattern=&amp;quot;*&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;action type=&amp;quot;Rewrite&amp;quot; value=&amp;quot;max-age=31536000&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/rule&amp;gt;&lt;br /&gt;
        &amp;lt;preConditions&amp;gt;&lt;br /&gt;
          &amp;lt;preCondition name=&amp;quot;USING_HTTPS&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;add input=&amp;quot;{HTTPS}&amp;quot; pattern=&amp;quot;^ON$&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;/preCondition&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
      &amp;lt;/outboundRules&amp;gt;&lt;br /&gt;
    &amp;lt;/rewrite&amp;gt;&lt;br /&gt;
  &amp;lt;/system.webServer&amp;gt;&lt;br /&gt;
 &amp;lt;/configuration&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Threats ==&lt;br /&gt;
&lt;br /&gt;
HSTS addresses the following threats:&lt;br /&gt;
* User bookmarks or manually types http://example.com and is subject to a man-in-the-middle attacker&lt;br /&gt;
** HSTS automatically redirects HTTP requests to HTTPS for the target domain&lt;br /&gt;
* Web application that is intended to be purely HTTPS inadvertently contains HTTP links or serves content over HTTP&lt;br /&gt;
** HSTS automatically redirects HTTP requests to HTTPS for the target domain&lt;br /&gt;
* A man-in-the-middle attacker attempts to intercept traffic from a victim user using an invalid certificate and hopes the user will accept the bad certificate&lt;br /&gt;
** HSTS does not allow a user to override the invalid certificate message&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* [http://www.youtube.com/watch?v=zEV3HOuM_Vw&amp;amp;feature=youtube_gdata AppSecTutorial Series - Episode 4]&lt;br /&gt;
* [http://dev.chromium.org/sts Chromium Projects/HSTS]&lt;br /&gt;
* [http://tools.ietf.org/html/rfc6797 HSTS Spec]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security Wikipedia]&lt;br /&gt;
* [https://developer.mozilla.org/en/Security/HTTP_Strict_Transport_Security Mozilla Developer Network]&lt;br /&gt;
* [https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet OWASP TLS Protection Cheat Sheet]&lt;br /&gt;
* [https://developer.mozilla.org/en/Security/HTTP_Strict_Transport_Security Firefox STS Support]&lt;br /&gt;
* [http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/1148.html Google Chrome STS Support]&lt;br /&gt;
* [http://www.thoughtcrime.org/software/sslstrip/ Moxie Marlinspike's Black Hat 2009 talk on sslstrip, that demonstrates why you need HSTS]&lt;br /&gt;
&lt;br /&gt;
[[Category:Control|Control]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Transport_Layer_Protection_Cheat_Sheet&amp;diff=195986</id>
		<title>Transport Layer Protection Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Transport_Layer_Protection_Cheat_Sheet&amp;diff=195986"/>
				<updated>2015-06-09T20:52:55Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Rule - Use HTTP Strict Transport Security */ link to appropriate articles on STS and PKP instead of duplicating content, add PKP&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides a simple model to follow when implementing transport layer protection for an application. Although the concept of SSL is known to many, the actual details and security specific decisions of implementation are often poorly understood and frequently result in insecure deployments. This article establishes clear rules which provide guidance on securely designing and configuring transport layer security for an application. This article is focused on the use of SSL/TLS between a web application and a web browser, but we also encourage the use of SSL/TLS or other network encryption technologies, such as VPN, on back end and other non-browser based connections.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Architectural Decision  ==&lt;br /&gt;
&lt;br /&gt;
An architectural decision must be made to determine the appropriate method to protect data when it is being transmitted.  The most common options available to corporations are Virtual Private Networks (VPN) or a SSL/TLS model commonly used by web applications. The selected model is determined by the business needs of the particular organization. For example, a VPN connection may be the best design for a partnership between two companies that includes mutual access to a shared server over a variety of protocols. Conversely, an Internet facing enterprise web application would likely be best served by a SSL/TLS model. &lt;br /&gt;
&lt;br /&gt;
This cheat sheet will focus on security considerations when the SSL/TLS model is selected. This is a frequently used model for publicly accessible web applications.&lt;br /&gt;
&lt;br /&gt;
= Providing Transport Layer Protection with SSL/TLS  =&lt;br /&gt;
&lt;br /&gt;
== Benefits  ==&lt;br /&gt;
&lt;br /&gt;
The primary benefit of transport layer security is the protection of web application data from unauthorized disclosure and modification when it is transmitted between clients (web browsers) and the web application server, and between the web application server and back end and other non-browser based enterprise components. &lt;br /&gt;
&lt;br /&gt;
The server validation component of TLS provides authentication of the server to the client.  If configured to require client side certificates, TLS can also play a role in client authentication to the server. However, in practice client side certificates are not often used in lieu of username and password based authentication models for clients.&lt;br /&gt;
&lt;br /&gt;
TLS also provides two additional benefits that are commonly overlooked; integrity guarantees and replay prevention. A TLS stream of communication contains built-in controls to prevent tampering with any portion of the encrypted data. In addition, controls are also built-in to prevent a captured stream of TLS data from being replayed at a later time.&lt;br /&gt;
&lt;br /&gt;
It should be noted that TLS provides the above guarantees to data during transmission. TLS does not offer any of these security benefits to data that is at rest. Therefore appropriate security controls must be added to protect data while at rest within the application or within data stores.&lt;br /&gt;
&lt;br /&gt;
== Basic Requirements ==&lt;br /&gt;
&lt;br /&gt;
The basic requirements for using TLS are: access to a Public Key Infrastructure (PKI) in order to obtain certificates, access to a directory or an Online Certificate Status Protocol (OCSP) responder in order to check certificate revocation status, and agreement/ability to support a minimum configuration of protocol versions and protocol options for each version.&lt;br /&gt;
&lt;br /&gt;
== SSL vs. TLS  ==&lt;br /&gt;
&lt;br /&gt;
The terms, Secure Socket Layer (SSL) and Transport Layer Security (TLS) are often used interchangeably. In fact, SSL v3.1 is equivalent to TLS v1.0. However, different versions of SSL and TLS are supported by modern web browsers and by most modern web frameworks and platforms. For the purposes of this cheat sheet we will refer to the technology generically as TLS. Recommendations regarding the use of SSL and TLS protocols, as well as browser support for TLS, can be found in the rule below titled [[Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Protocols| &amp;quot;Only Support Strong Protocols&amp;quot;]].&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs_cryptomodule.gif|thumb|350px|right|Cryptomodule Parts and Operation]]&lt;br /&gt;
&lt;br /&gt;
== When to Use a FIPS 140-2 Validated Cryptomodule ==&lt;br /&gt;
&lt;br /&gt;
If the web application may be the target of determined attackers (a common threat model for Internet accessible applications handling sensitive data), it is strongly advised to use TLS services that are provided by [http://csrc.nist.gov/groups/STM/cmvp/validation.html FIPS 140-2 validated cryptomodules]. &lt;br /&gt;
&lt;br /&gt;
A cryptomodule, whether it is a software library or a hardware device, basically consists of three parts:&lt;br /&gt;
&lt;br /&gt;
* Components that implement cryptographic algorithms (symmetric and asymmetric algorithms, hash algorithms, random number generator algorithms, and message authentication code algorithms) &lt;br /&gt;
* Components that call and manage cryptographic functions (inputs and outputs include cryptographic keys and so-called critical security parameters) &lt;br /&gt;
* A physical container around the components that implement cryptographic algorithms and the components that call and manage cryptographic functions&lt;br /&gt;
&lt;br /&gt;
The security of a cryptomodule and its services (and the web applications that call the cryptomodule) depend on the correct implementation and integration of each of these three parts. In addition, the cryptomodule must be used and accessed securely. The includes consideration for:&lt;br /&gt;
&lt;br /&gt;
* Calling and managing cryptographic functions&lt;br /&gt;
* Securely Handling inputs and output&lt;br /&gt;
* Ensuring the secure construction of the physical container around the components&lt;br /&gt;
&lt;br /&gt;
In order to leverage the benefits of TLS it is important to use a TLS service (e.g. library, web framework, web application server) which has been FIPS 140-2 validated. In addition, the cryptomodule must be installed, configured and operated in either an approved or an allowed mode to provide a high degree of certainty that the FIPS 140-2 validated cryptomodule is providing the expected security services in the expected manner.&lt;br /&gt;
&lt;br /&gt;
If the system is legally required to use FIPS 140-2 encryption (e.g., owned or operated by or on behalf of the U.S. Government) then TLS must be used and SSL disabled. Details on why SSL is unacceptable are described in Section 7.1 of [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf Implementation Guidance for FIPS PUB 140-2 and the Cryptographic Module Validation Program].&lt;br /&gt;
&lt;br /&gt;
Further reading on the use of TLS to protect highly sensitive data against determined attackers can be viewed in [http://csrc.nist.gov/publications/nistpubs/800-52/SP800-52.pdf SP800-52 Guidelines for the Selection and Use of Transport Layer Security (TLS) Implementations]&lt;br /&gt;
&lt;br /&gt;
== Secure Server Design  ==&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use TLS for All Login Pages and All Authenticated Pages  ===&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS. Failure to utilize TLS for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Use TLS on Any Networks (External and Internal) Transmitting Sensitive Data  ===&lt;br /&gt;
&lt;br /&gt;
All networks, both external and internal, which transmit sensitive data must utilize TLS or an equivalent transport layer security mechanism. It is not sufficient to claim that access to the internal network is &amp;quot;restricted to employees&amp;quot;. Numerous recent data compromises have shown that the internal network can be breached by attackers. In these attacks, sniffers have been installed to access unencrypted sensitive data sent on the internal network. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Provide Non-TLS Pages for Secure Content  ===&lt;br /&gt;
&lt;br /&gt;
All pages which are available over TLS must not be available over a non-TLS connection. A user may inadvertently bookmark or manually type a URL to a HTTP page (e.g. http://example.com/myaccount) within the authenticated portion of the application. If this request is processed by the application then the response, and any sensitive data, would be returned to the user over the clear text HTTP.&lt;br /&gt;
&lt;br /&gt;
=== Rule - REMOVED - Do Not Perform Redirects from Non-TLS Page to TLS Login Page  ===&lt;br /&gt;
&lt;br /&gt;
This recommendation has been removed. Ultimately, the below guidance will only provide user education and cannot provide any technical controls to protect the user against a man-in-the-middle attack.  &lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
A common practice is to redirect users that have requested a non-TLS version of the login page to the TLS version (e.g. http://example.com/login redirects to https://example.com/login). This practice creates an additional attack vector for a man in the middle attack. In addition, redirecting from non-TLS versions to the TLS version reinforces to the user that the practice of requesting the non-TLS page is acceptable and secure.&lt;br /&gt;
&lt;br /&gt;
In this scenario, the man-in-the-middle attack is used by the attacker to intercept the non-TLS to TLS redirect message. The attacker then injects the HTML of the actual login page and changes the form to post over unencrypted HTTP. This allows the attacker to view the user's credentials as they are transmitted in the clear.&lt;br /&gt;
&lt;br /&gt;
It is recommended to display a security warning message to the user whenever the non-TLS login page is requested. This security warning should urge the user to always type &amp;quot;HTTPS&amp;quot; into the browser or bookmark the secure login page.  This approach will help educate users on the correct and most secure method of accessing the application.&lt;br /&gt;
&lt;br /&gt;
Currently there are no controls that an application can enforce to entirely mitigate this risk. Ultimately, this issue is the responsibility of the user since the application cannot prevent the user from initially typing [http://owasp.org http://example.com/login] (versus HTTPS). &lt;br /&gt;
&lt;br /&gt;
Note: [http://www.w3.org/Security/wiki/Strict_Transport_Security Strict Transport Security] will address this issue and will provide a server side control to instruct supporting browsers that the site should only be accessed over HTTPS&lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Mix TLS and Non-TLS Content  ===&lt;br /&gt;
&lt;br /&gt;
A page that is available over TLS must be comprised completely of content which is transmitted over TLS. The page must not contain any content that is transmitted over unencrypted HTTP. This includes content from unrelated third party sites. &lt;br /&gt;
&lt;br /&gt;
An attacker could intercept any of the data transmitted over the unencrypted HTTP and inject malicious content into the user's page. This malicious content would be included in the page even if the overall page is served over TLS. In addition, an attacker could steal the user's session cookie that is transmitted with any non-TLS requests. This is possible if the cookie's 'secure' flag is not set. See the rule 'Use &amp;quot;Secure&amp;quot; Cookie Flag'&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use &amp;quot;Secure&amp;quot; Cookie Flag  ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Secure&amp;quot; flag must be set for all user cookies. Failure to use the &amp;quot;secure&amp;quot; flag enables an attacker to access the session cookie by tricking the user's browser into submitting a request to an unencrypted page on the site. This attack is possible even if the server is not configured to offer HTTP content since the attacker is monitoring the requests and does not care if the server responds with a 404 or doesn't respond at all.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Keep Sensitive Data Out of the URL ===&lt;br /&gt;
&lt;br /&gt;
Sensitive data must not be transmitted via URL arguments. A more appropriate place is to store sensitive data in a server side repository or within the user's session.  When using TLS the URL arguments and values are encrypted during transit. However, there are two methods that the URL arguments and values could be exposed.&lt;br /&gt;
&lt;br /&gt;
1. The entire URL is cached within the local user's browser history. This may expose sensitive data to any other user of the workstation.&lt;br /&gt;
&lt;br /&gt;
2. The entire URL is exposed if the user clicks on a link to another HTTPS site. This may expose sensitive data within the referral field to the third party site. This exposure occurs in most browsers and will only occur on transitions between two TLS sites. &lt;br /&gt;
&lt;br /&gt;
For example, a user following a link on [http://owasp.org https://example.com] which leads to [http://owasp.org https://someOtherexample.com] would expose the full URL of [http://owasp.org https://example.com] (including URL arguments) in the referral header (within most browsers). This would not be the case if the user followed a link on [http://owasp.org https://example.com] to [http://owasp.org http://someHTTPexample.com]&lt;br /&gt;
&lt;br /&gt;
=== Rule - Prevent Caching of Sensitive Data ===&lt;br /&gt;
&lt;br /&gt;
The TLS protocol provides confidentiality only for data in transit but it does not help with potential data leakage issues at the client or intermediary proxies. As a result, it is frequently prudent to instruct these nodes not to cache or persist sensitive data. One option is to add anticaching headers to relevant HTTP responses, (for example, &amp;quot;Cache-Control: no-cache, no-store&amp;quot; and &amp;quot;Expires: 0&amp;quot; for coverage of many modern browsers as of 2013). For compatibility with HTTP/1.0 (i.e., when user agents are really old or the webserver works around quirks by forcing HTTP/1.0) the response should also include the header &amp;quot;Pragma: no-cache&amp;quot;. More information is available in [https://tools.ietf.org/html/rfc2616 HTTP 1.1 RFC 2616], section 14.9.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use HTTP Strict Transport Security ===&lt;br /&gt;
&lt;br /&gt;
See: [[HTTP Strict Transport Security]]&lt;br /&gt;
&lt;br /&gt;
===Rule - Use Public Key Pinning===&lt;br /&gt;
&lt;br /&gt;
See: [[Certificate and Public Key Pinning]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Server_Certificate_and_Protocol_Configuration&amp;quot;&amp;gt;&amp;lt;/span&amp;gt; &amp;lt;!-- backward compatible anchor --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Server Certificate ==&lt;br /&gt;
Note: If using a FIPS 140-2 cryptomodule disregard the following rules and defer to the recommended configuration for the particular cryptomodule. Nevertheless we recommend to use this rules to audit your configuration.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use Strong Keys &amp;amp; Protect Them ===&lt;br /&gt;
&lt;br /&gt;
The private key used to generate the cipher key must be sufficiently strong for the anticipated lifetime of the private key and corresponding certificate. The current best practice is to select a key size of at least 2048 bits. Additional information on key lifetimes and comparable key strengths can be found in [http://www.keylength.com/en/compare/], [http://csrc.nist.gov/publications/nistpubs/800-57/sp800-57_part1_rev3_general.pdf NIST SP 800-57]. In addition, the private key must be stored in a location that is protected from unauthorized access.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use a Certificate That Supports Required Domain Names ===&lt;br /&gt;
&lt;br /&gt;
A user should never be presented with a certificate error, including prompts to reconcile domain or hostname mismatches, or expired certificates. If the application is available at both [https://owasp.org https://www.example.com] and [https://owasp.org https://example.com] then an appropriate certificate, or certificates, must be presented to accommodate the situation. The presence of certificate errors desensitizes users to TLS error messages and increases the possibility an attacker could launch a convincing phishing or man-in-the-middle attack.&lt;br /&gt;
&lt;br /&gt;
For example, consider a web application accessible at [https://owasp.org https://abc.example.com] and [https://owasp.org https://xyz.example.com]. One certificate should be acquired for the host or server ''abc.example.com''; and a second certificate for host or server ''xyz.example.com''. In both cases, the hostname would be present in the Subject's Common Name (CN).&lt;br /&gt;
&lt;br /&gt;
Alternatively, the Subject Alternate Names (SANs) can be used to provide a specific listing of multiple names where the certificate is valid. In the example above, the certificate could list the Subject's CN as ''example.com'', and list two SANs: ''abc.example.com'' and ''xyz.example.com''. These certificates are sometimes referred to as &amp;quot;multiple domain certificates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use Fully Qualified Names in Certificates ===&lt;br /&gt;
&lt;br /&gt;
Use fully qualified names in the DNS name field, and do not use unqualifed names (e.g., 'www'), local names (e.g., 'localhost'), or private IP addresses (e.g., 192.168.1.1) in the DNS name field. Unqualifed names, local names, or private IP addresses violate the certificate specification.&lt;br /&gt;
 &lt;br /&gt;
=== Rule - Do Not Use Wildcard Certificates ===&lt;br /&gt;
&lt;br /&gt;
You should refrain from using wildcard certificates. Though they are expedient at circumventing annoying user prompts, they also [[Least_privilege|violate the principal of least privilege]] and asks the user to trust all machines, including developer's machines, the secretary's machine in the lobby and the sign-in kiosk. Obtaining access to the private key is left as an exercise for the attacker, but its made much easier when stored on the file system unprotected.&lt;br /&gt;
&lt;br /&gt;
Statistics gathered by Qualys for [http://media.blackhat.com/bh-us-10/presentations/Ristic/BlackHat-USA-2010-Ristic-Qualys-SSL-Survey-HTTP-Rating-Guide-slides.pdf Internet SSL Survey 2010] indicate wildcard certificates have a 4.4% share, so the practice is not standard for public facing hosts. Finally, wildcard certificates violate [https://www.cabforum.org/EV_Certificate_Guidelines.pdf EV Certificate Guidelines].&lt;br /&gt;
&lt;br /&gt;
=== Rule - Do Not Use RFC 1918 Addresses in Certificates ===&lt;br /&gt;
&lt;br /&gt;
Certificates should not use private addresses. RFC 1918 is [https://tools.ietf.org/html/rfc1918 Address Allocation for Private Internets]. Private addresses are Internet Assigned Numbers Authority (IANA) reserved and include 192.168/16, 172.16/12, and 10/8.&lt;br /&gt;
&lt;br /&gt;
Certificates issued with private addresses violate [https://www.cabforum.org/EV_Certificate_Guidelines.pdf EV Certificate Guidelines]. In addition, Peter Gutmann writes in in [http://www.cs.auckland.ac.nz/~pgut001/pubs/book.pdf Engineering Security]: &amp;quot;This one is particularly troublesome because, in combination with the router-compromise attacks... and ...OSCP-defeating measures, it allows an attacker to spoof any EV-certificate site.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Rule - Use an Appropriate Certification Authority for the Application's User Base  ===&lt;br /&gt;
&lt;br /&gt;
An application user must never be presented with a warning that the certificate was signed by an unknown or untrusted authority. The application's user population must have access to the public certificate of the certification authority which issued the server's certificate. For Internet accessible websites, the most effective method of achieving this goal is to purchase the TLS certificate from a recognize certification authority. Popular Internet browsers already contain the public certificates of these recognized certification authorities. &lt;br /&gt;
&lt;br /&gt;
Internal applications with a limited user population can use an internal certification authority provided its public certificate is securely distributed to all users. However, remember that all certificates issued by this certification authority will be trusted by the users. Therefore, utilize controls to protect the private key and ensure that only authorized individuals have the ability to sign certificates. &lt;br /&gt;
&lt;br /&gt;
The use of self signed certificates is never acceptable. Self signed certificates negate the benefit of end-point authentication and also significantly decrease the ability for an individual to detect a man-in-the-middle attack. &lt;br /&gt;
&lt;br /&gt;
=== Rule - Always Provide All Needed Certificates ===&lt;br /&gt;
&lt;br /&gt;
Clients attempt to solve the problem of identifying a server or host using PKI and X509 certificate. When a user receives a server or host's certificate, the certificate must be validated back to a trusted root certification authority. This is known as path validation.&lt;br /&gt;
&lt;br /&gt;
There can be one or more intermediate certificates in between the end-entity (server or host) certificate and root certificate. In addition to validating both endpoints, the user will also have to validate all intermediate certificates. Validating all intermediate certificates can be tricky because the user may not have them locally. This is a well-known PKI issue called the “Which Directory?&amp;quot; problem.&lt;br /&gt;
&lt;br /&gt;
To avoid the “Which Directory?&amp;quot; problem, a server should provide the user with all required certificates used in a path validation.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Be aware of and have a plan for the SHA-1 deprecation plan  ===&lt;br /&gt;
&lt;br /&gt;
In order to avoid presenting end users with progressive certificate warnings, organizations must proactively address the browser vendor's upcoming SHA-1 deprecation plans. The Google Chrome plan is probably the most specific and aggressive at this point: [http://googleonlinesecurity.blogspot.com/2014/09/gradually-sunsetting-sha-1.html Gradually sunsetting SHA-1]&lt;br /&gt;
&lt;br /&gt;
If your organization has no [https://support.globalsign.com/customer/portal/articles/1499561-sha-256-compatibility SHA256 compatibility issues] then it may be appropriate to move your site to a SHA256 signed certificate/chain.  If there are, or may be, issues - you should ensure that your SHA-1 certificates expire before 1/1/2017. &lt;br /&gt;
&lt;br /&gt;
== Server Protocol and Cipher Configuration ==&lt;br /&gt;
Note: If using a FIPS 140-2 cryptomodule disregard the following rules and defer to the recommended configuration for the particular cryptomodule. Nevertheless we recommend to use this rules to audit your configuration.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Strong Protocols ===&lt;br /&gt;
&lt;br /&gt;
SSL/TLS is a collection of protocols. Weaknesses have been identified with earlier SSL protocols, including [http://www.schneier.com/paper-ssl-revised.pdf SSLv2] and [http://www.yaksman.org/~lweith/ssl.pdf SSLv3] hence SSL versions 1, 2 and 3 should not longer be used. The best practice for transport layer protection is to only provide support for the TLS protocols - TLS1.0, TLS 1.1 and TLS 1.2. This configuration will provide maximum protection against skilled and determined attackers and is appropriate for applications handling sensitive data or performing critical operations.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Transport_Layer_Security#Web_browsers Nearly all modern browsers support at least TLS 1.0]. As of February 2013, contemporary browsers (Chrome v20+, IE v8+, Opera v10+, and Safari v5+) [http://en.wikipedia.org/wiki/Transport_Layer_Security#Web_browsers support TLS 1.1 and TLS 1.2]. You should provide support for TLS 1.1 and TLS 1.2 to accommodate clients which support the protocols. The client and server (usually) negotiate the best protocol, that is supported on both sides.&lt;br /&gt;
&lt;br /&gt;
TLS 1.0 is still widely used as 'best' protocol by a lot of browsers, that are not patched to the very latest version. It suffers [http://www.yassl.com/yaSSL/Blog/Entries/2010/10/7_Differences_between_SSL_and_TLS_Protocol_Versions.html CBC Chaining attacks and Padding Oracle attacks]. TLSv1.0 should only be used only after risk analysis and acceptance.&lt;br /&gt;
&lt;br /&gt;
Under no circumstances neither SSLv2 nor SSLv3 should be enabled as a protocol selection:&lt;br /&gt;
* The [http://www.schneier.com/paper-ssl-revised.pdf SSLv2 protocol is broken] and does not provide adequate transport layer protection.&lt;br /&gt;
* [http://www.yaksman.org/~lweith/ssl.pdf SSLv3 had been known for weaknesses] which severely compromise the channel's security long before the [https://www.openssl.org/~bodo/ssl-poodle.pdf 'POODLE'-Bug] finally stopped to tolerate this protocol by October 2014. Switching off SSLv3 terminates the support of legacy browsers like [https://www.ssllabs.com/ssltest/viewClient.html?name=IE&amp;amp;version=6&amp;amp;platform=XP IE6/XP] and elder.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Prefer Ephemeral Key Exchanges ===&lt;br /&gt;
&lt;br /&gt;
Ephemeral key exchanges are based on Diffie-Hellman and use per-session, temporary keys during the initial SSL/TLS handshake. They provide perfect forward secrecy (PFS), which means a compromise of the server's long term signing key does not compromise the confidentiality of past session (see [[#Rule_-_Only_Support_Strong_Cryptographic_Ciphers | following rule]]). When the server uses an ephemeral key, the server will sign the temporary key with its long term key (the long term key is the customary key available in its certificate).&lt;br /&gt;
&lt;br /&gt;
Use cryptographic parameters (like DH-parameter) that use a secure length that match to the supported keylength of your certificate (&amp;gt;=2048 bits or equivalent Elliptic Curves). As some middleware had some issues with this, upgrade to the latest version.&lt;br /&gt;
&lt;br /&gt;
If you have a server farm and are providing forward secrecy, then you might have to disable session resumption. For example, Apache writes the session id's and master secrets to disk so all servers in the farm can participate in resuming a session (there is currently no in-memory mechanism to achieve the sharing). Writing the session id and master secret to disk undermines forward secrecy.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Strong Cryptographic Ciphers  ===&lt;br /&gt;
&lt;br /&gt;
Each protocol (TLSv1.0, TLSv1.1, TLSv1.2, etc) provides cipher suites. As of TLS 1.2, [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 there is support for over 300 suites (320+ and counting)], including [http://www.mail-archive.com/cryptography@randombit.net/msg03785.html national vanity cipher suites]. The strength of the encryption used within a TLS session is determined by the encryption cipher negotiated between the server and the browser. In order to ensure that only strong cryptographic ciphers are selected the server must be modified to disable the use of weak ciphers and to configure the ciphers in an adequate order. It is recommended to configure the server to only support strong ciphers and to use sufficiently large key sizes. In general, the following should be observed when selecting CipherSuites:&lt;br /&gt;
* Use the very latest recommendations, they may be volantile these days&lt;br /&gt;
* Setup your Policy to get a Whitelist for recommended Ciphers, e.g.:&lt;br /&gt;
** Activate to set the Cipher Order by the Server&lt;br /&gt;
** Highest Priority for Ciphers that support 'Forward Secrecy' (-&amp;gt; Support ephemeral Diffie-Hellman key exchange, see rule above) [http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html]&lt;br /&gt;
** Favor DHE over ECDHE (and monitor the CPU usage, see Notes below), ECDHE lacks now of really reliable Elliptic Curves, see discussion about secp{224,256,384,521}r1 and secp256k1, cf. [http://safecurves.cr.yp.to], [https://www.schneier.com/blog/archives/2013/09/the_nsa_is_brea.html#c1675929]. The solution might be to use [http://www.researchgate.net/profile/Johannes_Merkle/publication/260050106_Standardisierung_der_Brainpool-Kurven_fr_TLS_und_IPSec/file/60b7d52f36a0cc2fdd.pdf Brainpool Curves &amp;lt;nowiki&amp;gt;[German]&amp;lt;/nowiki&amp;gt;], defined for TLS in [https://tools.ietf.org/html/rfc7027 RFC 7027], or [http://eprint.iacr.org/2007/286 Edwards Curves]. The most promising candidates for the latter are [https://tools.ietf.org/html/draft-josefsson-tls-curve25519-06 'Curve25519'] and [http://sourceforge.net/p/ed448goldilocks/wiki/Home/ Ed448-Goldilocks] (see [https://tools.ietf.org/html/draft-irtf-cfrg-curves-02 DRAFT-irtf-cfrg-curves]), that is not yet defined for TLS, cf. [http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8 IANA] &amp;lt;!--- as at June 2014 ---&amp;gt;&lt;br /&gt;
** Use RSA-Keys (no DSA/DSS: they get very weak, if a bad entropy source is used during signing, cf. [https://projectbullrun.org/dual-ec/tls.html], [https://factorable.net/weakkeys12.conference.pdf]) &amp;lt;!--- as at June 2014 ---&amp;gt;&lt;br /&gt;
** Favor GCM over CBC regardless of the cipher size. In other words, use Authenticated Encryption with Associated Data (AEAD), e.g. AES-GCM, AES-CCM.&lt;br /&gt;
** Watch also for Stream Ciphers which XOR the key stream with plaintext (such as AES/CTR mode) &amp;lt;!--- Jim please check this ---&amp;gt;&lt;br /&gt;
** Priorize the ciphers by the sizes of the Cipher and the MAC&lt;br /&gt;
** Use SHA1 or above for digests, prefer SHA2 (or equivalent)&lt;br /&gt;
** Disable weak ciphers (which is implicitly done by this whitelist) without disabling legacy browsers and bots that have to be supported (find the best compromise), actually the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA (0xa) does this job.&lt;br /&gt;
*** Disable cipher suites that do not offer encryption (eNULL, NULL)&lt;br /&gt;
*** Disable cipher suites that do not offer authentication (aNULL). aNULL includes anonymous cipher suites ADH (Anonymous Diffie-Hellman) and AECDH (Anonymous Elliptic Curve Diffie Hellman).&lt;br /&gt;
*** Disable export level ciphers (EXP, eg. ciphers containing DES)&lt;br /&gt;
*** Disable key sizes smaller than 128 bits for encrypting payload traffic (see [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI: TR-02102 Part 2 (German)])&lt;br /&gt;
*** Disable the use of MD5 as a hashing mechanism for payload traffic&lt;br /&gt;
*** Disable the use of IDEA Cipher Suites (see [https://tools.ietf.org/html/rfc5469])&lt;br /&gt;
*** Disable RC4 cipher suites (see [https://tools.ietf.org/html/rfc7465], [http://www.isg.rhul.ac.uk/tls/])&lt;br /&gt;
** Ciphers should be usable for DH-Pamameters &amp;gt;= 2048 bits, without blocking legacy browsers (The cipher ‘DHE-RSA-AES128-SHA’ is suppressed as some browsers like to use it but are not capable to cope with DH-Params &amp;gt; 1024 bits.)&lt;br /&gt;
* Define a Cipher String that works with different Versions of your encryption tool, like openssl&lt;br /&gt;
* Verify your cipher string&lt;br /&gt;
** with an audit-tool, like [[O-Saft|OWASP 'O-Saft' (OWASP SSL audit for testers / OWASP SSL advanced forensic tool)]]&lt;br /&gt;
** listing it manually with your encryption software, e.g. openssl ciphers -v &amp;lt;cipher-string&amp;gt; (the result may differ by version), e.g.:&lt;br /&gt;
{{Top_10_2010:ExampleBeginTemplate|year=2013}} &lt;br /&gt;
openssl ciphers -v &amp;quot;EDH+aRSA+AESGCM:EDH+aRSA+AES:DHE-RSA-AES256-SHA:EECDH+aRSA+AESGCM:EECDH+aRSA+AES:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:RSA+AESGCM:RSA+AES+SHA:DES-CBC3-SHA:-DHE-RSA-AES128-SHA&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;add optionally ':!aNULL:!eNULL:!LOW:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:!ADH:!IDEA' to protect older Versions of OpenSSL&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;you may use openssl ciphers -V &amp;quot;...&amp;quot; for openssl &amp;gt;= 1.0.1:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 0x00,0x9F - DHE-RSA-AES256-GCM-SHA384   TLSv1.2 Kx=DH     Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0x00,0x9E - DHE-RSA-AES128-GCM-SHA256   TLSv1.2 Kx=DH     Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0x00,0x6B - DHE-RSA-AES256-SHA256       TLSv1.2 Kx=DH     Au=RSA  Enc=AES(256)    Mac=SHA256&lt;br /&gt;
 0x00,0x39 - DHE-RSA-AES256-SHA          SSLv3   Kx=DH     Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0x00,0x67 - DHE-RSA-AES128-SHA256       TLSv1.2 Kx=DH     Au=RSA  Enc=AES(128)    Mac=SHA256&lt;br /&gt;
 0xC0,0x30 - ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH   Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0xC0,0x2F - ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH   Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0xC0,0x28 - ECDHE-RSA-AES256-SHA384     TLSv1.2 Kx=ECDH   Au=RSA  Enc=AES(256)    Mac=SHA384&lt;br /&gt;
 0xC0,0x14 - ECDHE-RSA-AES256-SHA        SSLv3   Kx=ECDH   Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0xC0,0x27 - ECDHE-RSA-AES128-SHA256     TLSv1.2 Kx=ECDH   Au=RSA  Enc=AES(128)    Mac=SHA256&lt;br /&gt;
 0xC0,0x13 - ECDHE-RSA-AES128-SHA        SSLv3   Kx=ECDH   Au=RSA  Enc=AES(128)    Mac=SHA1&lt;br /&gt;
 0x00,0x9D - AES256-GCM-SHA384           TLSv1.2 Kx=RSA    Au=RSA  Enc=AESGCM(256) Mac=AEAD&lt;br /&gt;
 0x00,0x9C - AES128-GCM-SHA256           TLSv1.2 Kx=RSA    Au=RSA  Enc=AESGCM(128) Mac=AEAD&lt;br /&gt;
 0x00,0x35 - AES256-SHA                  SSLv3   Kx=RSA    Au=RSA  Enc=AES(256)    Mac=SHA1&lt;br /&gt;
 0x00,0x2F - AES128-SHA                  SSLv3   Kx=RSA    Au=RSA  Enc=AES(128)    Mac=SHA1&lt;br /&gt;
 0x00,0x0A - DES-CBC3-SHA                SSLv3   Kx=RSA    Au=RSA  Enc=3DES(168)   Mac=SHA1&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
{{Top_10_2010:ExampleEndTemplate}}&lt;br /&gt;
&lt;br /&gt;
* Inform yourself how to securely configure the settings for your used services or hardware, e.g. [https://bettercrypto.org BetterCrypto.org: Applied Crypto Hardening (DRAFT)]&lt;br /&gt;
* Check new software and hardware versions for new security settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Notes:&amp;lt;/b&amp;gt;&lt;br /&gt;
* According to my researches the most common browsers should be supported with this setting, too (see also [https://www.ssllabs.com/ssltest/index.html SSL Labs: SSL Server Test -&amp;gt; SSL Report -&amp;gt; Handshake Simulation]).&lt;br /&gt;
* Monitor the performance of your server, e.g. the TLS handshake with DHE hinders the CPU abt 2.4 times more than ECDHE, cf. [http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html#some-benchmarks Vincent Bernat, 2011], [http://nmav.gnutls.org/2011/12/price-to-pay-for-perfect-forward.html nmav's Blog, 2011].&lt;br /&gt;
* Use of Ephemeral Diffie-Hellman key exchange will protect confidentiality of the transmitted plaintext data even if the corresponding RSA or DSS server private key got compromised. An attacker would have to perform active man-in-the-middle attack at the time of the key exchange to be able to extract the transmitted plaintext. All modern browsers support this key exchange with the notable exception of Internet Explorer prior to Windows Vista.&lt;br /&gt;
&lt;br /&gt;
Additional information can be obtained within the [https://tools.ietf.org/html/rfc5246 TLS 1.2 RFC 5246], [https://www.ssllabs.com/projects/best-practices/index.html SSL Labs: 'SSL/TLS Deployment Best Practices'], [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI: 'TR-02102 Part 2 (German)'], [http://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/algorithms-key-sizes-and-parameters-report ENISA: 'Algorithms, Key Sizes and Parameters Report'], [https://tools.ietf.org/html/rfc7525 RFC 7525: Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)] and [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf FIPS 140-2 IG].&lt;br /&gt;
&lt;br /&gt;
=== Rule - Support TLS-PSK and TLS-SRP for Mutual Authentication ===&lt;br /&gt;
&lt;br /&gt;
When using a shared secret or password offer TLS-PSK (Pre-Shared Key) or TLS-SRP (Secure Remote Password), which are known as Password Authenticated Key Exchange (PAKEs). TLS-PSK and TLS-SRP properly bind the channel, which refers to the cryptographic binding between the outer tunnel and the inner authentication protocol. IANA currently reserves [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 79 PSK cipehr suites] and [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 9 SRP cipher suites].&lt;br /&gt;
&lt;br /&gt;
Basic authentication places the user's password on the wire in the plain text after a server authenticates itself. Basic authentication only provides unilateral authentication. In contrast, both TLS-PSK and TLS-SRP provide mutual authentication, meaning each party proves it knows the password without placing the password on the wire in the plain text.&lt;br /&gt;
&lt;br /&gt;
Finally, using a PAKE removes the need to trust an outside party, such as a Certification Authority (CA).&lt;br /&gt;
&lt;br /&gt;
=== Rule - Only Support Secure Renegotiations  ===&lt;br /&gt;
&lt;br /&gt;
A design weakness in TLS, identified as [http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2009-3555 CVE-2009-3555], allows an attacker to inject a plaintext of his choice into a TLS session of a victim. In the HTTPS context the attacker might be able to inject his own HTTP requests on behalf of the victim. The issue can be mitigated either by disabling support for TLS renegotiations or by supporting only renegotiations compliant with [https://tools.ietf.org/html/rfc5746 RFC 5746]. All modern browsers have been updated to comply with this RFC.&lt;br /&gt;
&lt;br /&gt;
=== Rule - Disable Compression ===&lt;br /&gt;
&lt;br /&gt;
Compression Ratio Info-leak Made Easy (CRIME) is an exploit against the data compression scheme used by the TLS and SPDY protocols. The exploit allows an adversary to recover user authentication cookies from HTTPS. The recovered cookie can be subsequently used for session hijacking attacks.&lt;br /&gt;
&lt;br /&gt;
== Test your overall TLS/SSL setup and your Certificate ==&lt;br /&gt;
This section shows the most common references only. For more tools and such, please refer to [[#Tools|Tools]].&lt;br /&gt;
&lt;br /&gt;
* [[Testing_for_SSL-TLS_%28OWASP-CM-001%29 | OWASP Testing Guide: Chapter on SSL/TLS Testing]]&lt;br /&gt;
* [[O-Saft|OWASP 'O-Saft' (OWASP SSL audit for testers / OWASP SSL advanced forensic tool)]]&lt;br /&gt;
* [https://www.ssllabs.com/ssltest SSL LABS Server Test]&lt;br /&gt;
* other Tools: [[Testing_for_Weak_SSL/TSL_Ciphers,_Insufficient_Transport_Layer_Protection_%28OWASP-EN-002%29#References| Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002) (DRAFT)]] - References - Tools&lt;br /&gt;
&lt;br /&gt;
== Client (Browser) Configuration  ==&lt;br /&gt;
&lt;br /&gt;
The validation procedures to ensure that a certificate is valid are complex and difficult to correctly perform.  In a typical web application model, these checks will be performed by the client's web browser in accordance with local browser settings and are out of the control of the application. However, these items do need to be addressed in the following scenarios:&lt;br /&gt;
&lt;br /&gt;
* The application server establishes connections to other applications over TLS for purposes such as web services or any exchange of data&lt;br /&gt;
* A thick client application is connecting to a server via TLS&lt;br /&gt;
&lt;br /&gt;
In these situations extensive certificate validation checks must occur in order to establish the validity of the certificate. Consult the following resources to assist in the design and testing of this functionality. The NIST PKI testing site includes a full test suite of certificates and expected outcomes of the test cases.&lt;br /&gt;
* [http://csrc.nist.gov/groups/ST/crypto_apps_infra/pki/pkitesting.html NIST PKI Testing]&lt;br /&gt;
* [https://tools.ietf.org/html/rfc5280 IETF RFC 5280]&lt;br /&gt;
&lt;br /&gt;
As specified in the above guidance, if the certificate can not be validated for any reason then the connection between the client and server must be dropped. Any data exchanged over a connection where the certificate has not properly been validated could be exposed to unauthorized access or modification.&lt;br /&gt;
&lt;br /&gt;
== Additional Controls  ==&lt;br /&gt;
&lt;br /&gt;
=== Extended Validation Certificates  ===&lt;br /&gt;
&lt;br /&gt;
Extended validation certificates (EV Certificates) proffer an enhanced investigation by the issuer into the requesting party due to the industry's race to the bottom. The purpose of EV certificates is to provide the user with greater assurance that the owner of the certificate is a verified legal entity for the site. Browsers with support for EV certificates distinguish an EV certificate in a variety of ways. Internet Explorer will color a portion of the URL in green, while Mozilla will add a green portion to the left of the URL indicating the company name. &lt;br /&gt;
&lt;br /&gt;
High value websites should consider the use of EV certificates to enhance customer confidence in the certificate. It should also be noted that EV certificates do not provide any greater technical security for the TLS. The purpose of the EV certificate is to increase user confidence that the target site is indeed who it claims to be.&lt;br /&gt;
&lt;br /&gt;
=== Client-Side Certificates  ===&lt;br /&gt;
&lt;br /&gt;
Client side certificates can be used with TLS to prove the identity of the client to the server. Referred to as &amp;quot;two-way TLS&amp;quot;, this configuration requires the client to provide their certificate to the server, in addition to the server providing their's to the client. If client certificates are used, ensure that the same validation of the client certificate is performed by the server, as indicated for the validation of server certificates above. In addition, the server should be configured to drop the TLS connection if the client certificate cannot be verified or is not provided. &lt;br /&gt;
&lt;br /&gt;
The use of client side certificates is relatively rare currently due to the complexities of certificate generation, safe distribution, client side configuration, certificate revocation and reissuance, and the fact that clients can only authenticate on machines where their client side certificate is installed. Such certificates are typically used for very high value connections that have small user populations.&lt;br /&gt;
&lt;br /&gt;
=== Certificate and Public Key Pinning ===&lt;br /&gt;
&lt;br /&gt;
Hybrid and native applications can take advantage of [[Certificate_and_Public_Key_Pinning|certificate and public key pinning]]. Pinning associates a host (for example, server) with an identity (for example, certificate or public key), and allows an application to leverage knowledge of the pre-existing relationship. At runtime, the application would inspect the certificate or public key received after connecting to the server. If the certificate or public key is expected, then the application would proceed as normal. If unexpected, the application would stop using the channel and close the connection since an adversary could control the channel or server.&lt;br /&gt;
&lt;br /&gt;
Pinning still requires customary X509 checks, such as revocation, since CRLs and OCSP provides real time status information. Otherwise, an application could possibly (1) accept a known bad certificate; or (2) require an out-of-band update, which could result in a lengthy App Store approval.&lt;br /&gt;
&lt;br /&gt;
Browser based applications are at a disadvantage since most browsers do not allow the user to leverage pre-existing relationships and ''a priori'' knowledge. In addition, Javascript and Websockets do not expose methods to for a web app to query the underlying secure connection information (such as the certificate or public key). It is noteworthy that Chromium based browsers perform pinning on selected sites, but the list is currently maintained by the vendor.&lt;br /&gt;
&lt;br /&gt;
For more information, please see the [[Pinning Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Providing Transport Layer Protection for Back End and Other Connections  =&lt;br /&gt;
&lt;br /&gt;
Although not the focus of this cheat sheet, it should be stressed that transport layer protection is necessary for back-end connections and any other connection where sensitive data is exchanged or where user identity is established. Failure to implement an effective and robust transport layer security will expose sensitive data and undermine the effectiveness of any authentication or access control mechanism. &lt;br /&gt;
&lt;br /&gt;
== Secure Internal Network Fallacy  ==&lt;br /&gt;
&lt;br /&gt;
The internal network of a corporation is not immune to attacks. Many recent high profile intrusions, where thousands of sensitive customer records were compromised, have been perpetrated by attackers that have gained internal network access and then used sniffers to capture unencrypted data as it traversed the internal network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Tools =&lt;br /&gt;
=== local/offline ===&lt;br /&gt;
* [[O-Saft|O-Saft - OWASP SSL advanced forensic tool)]]&lt;br /&gt;
* [http://sourceforge.net/projects/sslscan/ SSLScan - Fast SSL Scanner]&lt;br /&gt;
* [https://github.com/iSECPartners/sslyze SSLyze]&lt;br /&gt;
* [http://www.g-sec.lu/sslaudit/sslaudit.zip SSL Audit]&lt;br /&gt;
&lt;br /&gt;
=== Online ===&lt;br /&gt;
* [https://www.ssllabs.com/ssltest SSL LABS Server Test]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
* Mozilla – [https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations Mozilla Recommended Configurations]&lt;br /&gt;
* OWASP – [[Testing for SSL-TLS (OWASP-CM-001)|Testing for SSL-TLS]], and OWASP [[Guide to Cryptography]] &lt;br /&gt;
* OWASP – [http://www.owasp.org/index.php/ASVS Application Security Verification Standard (ASVS) – Communication Security Verification Requirements (V10)]&lt;br /&gt;
* OWASP – ASVS Article on [[Why you need to use a FIPS 140-2 validated cryptomodule]]&lt;br /&gt;
* SSL Labs – [https://www.ssllabs.com/projects/best-practices/index.html SSL/TLS Deployment Best Practices]&lt;br /&gt;
* SSL Labs – [http://www.ssllabs.com/projects/rating-guide/index.html SSL Server Rating Guide]&lt;br /&gt;
* ENISA – [http://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/algorithms-key-sizes-and-parameters-report Algorithms, Key Sizes and Parameters Report]&lt;br /&gt;
* BSI   – [https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102-2_pdf.html BSI TR-02102 Part 2 (German)]&lt;br /&gt;
* yaSSL – [http://www.yassl.com/yaSSL/Blog/Entries/2010/10/7_Differences_between_SSL_and_TLS_Protocol_Versions.html Differences between SSL and TLS Protocol Versions]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/PubsSPs.html#800-52 SP 800-52 Rev. 1 Guidelines for the Selection, Configuration, and Use of Transport Layer Security (TLS) Implementations]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/fips/fips140-2/fips1402.pdf FIPS 140-2 Security Requirements for Cryptographic Modules]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/groups/STM/cmvp/documents/fips140-2/FIPS1402IG.pdf Implementation Guidance for FIPS PUB 140-2 and the Cryptographic Module Validation Program]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/nistpubs/800-57/sp800-57_part1_rev3_general.pdf NIST SP 800-57 Recommendation for Key Management, Revision 3], [http://csrc.nist.gov/publications/PubsDrafts.html#SP-800-57-Part%203-Rev.1 Public DRAFT]&lt;br /&gt;
* NIST – [http://csrc.nist.gov/publications/drafts.html#sp800-95 SP 800-95 Guide to Secure Web Services] &lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc5280 RFC 5280 Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc2246 RFC 2246 The Transport Layer Security (TLS) Protocol Version 1.0 (JAN 1999)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc4346 RFC 4346 The Transport Layer Security (TLS) Protocol Version 1.1 (APR 2006)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc5246 RFC 5246 The Transport Layer Security (TLS) Protocol Version 1.2 (AUG 2008)]&lt;br /&gt;
* IETF – [https://tools.ietf.org/html/rfc7525 RFC 7525 Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)]&lt;br /&gt;
* bettercrypto - [https://bettercrypto.org Applied Crypto Hardening: HOWTO for secure crypto settings of the most common services (DRAFT)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Michael Coates - michael.coates[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Dave Wichers - dave.wichers[at]owasp.org &amp;lt;br/&amp;gt;&lt;br /&gt;
Michael Boberski - boberski_michael[at]bah.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Tyler Reguly -treguly[at]sslfail.com&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;padding-left:25px;width:300px;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
[[Category:OWASP Best Practices]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=HTTP_Strict_Transport_Security&amp;diff=195985</id>
		<title>HTTP Strict Transport Security</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=HTTP_Strict_Transport_Security&amp;diff=195985"/>
				<updated>2015-06-09T20:52:25Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Links */ add AppSec tutorials&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS. It also prevents HTTPS click through prompts on browsers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The specification has been released and published end of 2012 as RFC 6797 (HTTP Strict Transport Security (HSTS)) by the IETF. (Reference see in the links at the bottom.)&lt;br /&gt;
&lt;br /&gt;
== Examples  ==&lt;br /&gt;
&lt;br /&gt;
Simple example, using a long (1 year) max-age:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000&lt;br /&gt;
&lt;br /&gt;
If all present and future subdomains will be HTTPS:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000; includeSubDomains&lt;br /&gt;
&lt;br /&gt;
'''Recommended:''' If the site owner would like their domain to be included in the [https://hstspreload.appspot.com/ HSTS preload list] maintained by Chrome (and used by Firefox and Safari), then use:&lt;br /&gt;
&lt;br /&gt;
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;br /&gt;
&lt;br /&gt;
The `preload` flag indicates the site owner's consent to have their domain preloaded. The site owner still needs to then go and submit the domain to the list.&lt;br /&gt;
&lt;br /&gt;
== Excessively Strict STS ==&lt;br /&gt;
&lt;br /&gt;
Use caution when setting excessively strict STS policies. Including subdomains should only be used in environments where all sites within your organization for the given domain name require ssl. Max-age limits should be carefully considered as infrequent visitors may find your site inaccessible if you relax your policy.&lt;br /&gt;
&lt;br /&gt;
Before enabling includeSubDomains, also consider the impact of any existing DNS CNAME records for CDNs, email services, or other 3rd party services.  Since includeSubDomains will force such CNAME subdomains to https:// it's likely the browser will throw a domain-mismatch error, which is hard to reverse because of the browser caching nature of HSTS.&lt;br /&gt;
&lt;br /&gt;
== Browser Support ==&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;400&amp;quot; cellspacing=&amp;quot;1&amp;quot; cellpadding=&amp;quot;1&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| '''Browser'''&amp;lt;br&amp;gt;&lt;br /&gt;
| '''Support Introduced'''&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Internet Explorer &amp;lt;br&amp;gt;&lt;br /&gt;
| support expected starting with ie12[https://threatpost.com/ie-12-to-support-hsts-encryption-protocol/105266]&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Firefox&amp;lt;br&amp;gt;&lt;br /&gt;
| 4&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Opera&amp;lt;br&amp;gt;&lt;br /&gt;
| 12&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Safari&amp;lt;br&amp;gt;&lt;br /&gt;
| Mavericks (Mac OS X 10.9)&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Chrome&amp;lt;br&amp;gt;&lt;br /&gt;
| 4.0.211.0&amp;lt;br&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
A detailed overview of supporting browsers can be found at [http://caniuse.com/#feat=stricttransportsecurity caniuse.com].&lt;br /&gt;
== Server Side ==&lt;br /&gt;
&lt;br /&gt;
The web server side needs to inject the HSTS header. &lt;br /&gt;
&lt;br /&gt;
For HTTP sites on the same domain it is [http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec#section-6.1 not recommended] to add a HSTS header but to do a permanent redirect (301 status code) to the HTTPS site.&lt;br /&gt;
 &lt;br /&gt;
An Apache HTTPd example that will permanently redirect a URL to the identical URL with a HTTPS scheme, is as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerAlias *&lt;br /&gt;
        RewriteEngine On&lt;br /&gt;
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [redirect=301]&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the HTTPS site configuration the following is needed to add the header as [http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec#section-6.1 recommended by the standard]:&lt;br /&gt;
        Header always set Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following links show how to set response headers in other web servers:&lt;br /&gt;
* [http://wiki.nginx.org/HttpHeadersModule NGINX]&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModSetEnv#Options Lighttpd]&lt;br /&gt;
* [http://httpd.apache.org/docs/2.2/mod/mod_headers.html HTTPd]&lt;br /&gt;
&lt;br /&gt;
==== IIS ====&lt;br /&gt;
Whilst [http://technet.microsoft.com/en-us/library/cc753133(WS.10).aspx custom headers] can be configured in IIS without any extensions, it is not possible to restrict these headers to secure transport channels [http://tools.ietf.org/html/rfc6797#section-7.2 as per the HSTS specification]. This leaves the following options. &lt;br /&gt;
&lt;br /&gt;
===== Custom Module =====&lt;br /&gt;
HSTS has been implemented, per the specification, as an [http://hstsiis.codeplex.com/ open source IIS module].&lt;br /&gt;
&lt;br /&gt;
===== URL Rewrite =====&lt;br /&gt;
Install [http://www.iis.net/downloads/microsoft/url-rewrite Microsoft URL Rewrite] and use following rewrite rules.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.webServer&amp;gt;&lt;br /&gt;
    &amp;lt;rewrite&amp;gt;&lt;br /&gt;
      &amp;lt;rules&amp;gt;&lt;br /&gt;
        &amp;lt;rule name=&amp;quot;HTTPS_301_Redirect&amp;quot; stopProcessing=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;match url=&amp;quot;(.*)&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;conditions&amp;gt;&lt;br /&gt;
            &amp;lt;add input=&amp;quot;{HTTPS}&amp;quot; pattern=&amp;quot;^OFF$&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;/conditions&amp;gt;&lt;br /&gt;
          &amp;lt;action type=&amp;quot;Redirect&amp;quot; url=&amp;quot;https://{HTTP_HOST}{REQUEST_URI}&amp;quot; appendQueryString=&amp;quot;false&amp;quot; redirectType=&amp;quot;Permanent&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/rule&amp;gt;&lt;br /&gt;
      &amp;lt;/rules&amp;gt;&lt;br /&gt;
      &amp;lt;outboundRules&amp;gt;&lt;br /&gt;
        &amp;lt;rule name=&amp;quot;Add_HSTS_Header&amp;quot; preCondition=&amp;quot;USING_HTTPS&amp;quot; patternSyntax=&amp;quot;Wildcard&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;match serverVariable=&amp;quot;RESPONSE_Strict-Transport-Security&amp;quot; pattern=&amp;quot;*&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;action type=&amp;quot;Rewrite&amp;quot; value=&amp;quot;max-age=31536000&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/rule&amp;gt;&lt;br /&gt;
        &amp;lt;preConditions&amp;gt;&lt;br /&gt;
          &amp;lt;preCondition name=&amp;quot;USING_HTTPS&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;add input=&amp;quot;{HTTPS}&amp;quot; pattern=&amp;quot;^ON$&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;/preCondition&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
      &amp;lt;/outboundRules&amp;gt;&lt;br /&gt;
    &amp;lt;/rewrite&amp;gt;&lt;br /&gt;
  &amp;lt;/system.webServer&amp;gt;&lt;br /&gt;
 &amp;lt;/configuration&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Threats ==&lt;br /&gt;
&lt;br /&gt;
HSTS addresses the following threats:&lt;br /&gt;
* User bookmarks or manually types http://example.com and is subject to a man-in-the-middle attacker&lt;br /&gt;
** HSTS automatically redirects HTTP requests to HTTPS for the target domain&lt;br /&gt;
* Web application that is intended to be purely HTTPS inadvertently contains HTTP links or serves content over HTTP&lt;br /&gt;
** HSTS automatically redirects HTTP requests to HTTPS for the target domain&lt;br /&gt;
* A man-in-the-middle attacker attempts to intercept traffic from a victim user using an invalid certificate and hopes the user will accept the bad certificate&lt;br /&gt;
** HSTS does not allow a user to override the invalid certificate message&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* [[http://www.youtube.com/watch?v=zEV3HOuM_Vw&amp;amp;feature=youtube_gdata AppSecTutorial Series - Episode 4]&lt;br /&gt;
* [http://dev.chromium.org/sts Chromium Projects/HSTS]&lt;br /&gt;
* [http://tools.ietf.org/html/rfc6797 HSTS Spec]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security Wikipedia]&lt;br /&gt;
* [https://developer.mozilla.org/en/Security/HTTP_Strict_Transport_Security Mozilla Developer Network]&lt;br /&gt;
* [https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet OWASP TLS Protection Cheat Sheet]&lt;br /&gt;
* [https://developer.mozilla.org/en/Security/HTTP_Strict_Transport_Security Firefox STS Support]&lt;br /&gt;
* [http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/1148.html Google Chrome STS Support]&lt;br /&gt;
* [http://www.thoughtcrime.org/software/sslstrip/ Moxie Marlinspike's Black Hat 2009 talk on sslstrip, that demonstrates why you need HSTS]&lt;br /&gt;
&lt;br /&gt;
[[Category:Control|Control]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=195984</id>
		<title>Authentication Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Authentication_Cheat_Sheet&amp;diff=195984"/>
				<updated>2015-06-09T20:49:00Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* SAML */ reference SAML Security Cheat Sheet&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
'''Authentication''' is the process of verification that an individual, entity  or website is who it claims to be. Authentication in the context of web applications 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.&lt;br /&gt;
&lt;br /&gt;
'''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.&lt;br /&gt;
&lt;br /&gt;
= Authentication General Guidelines  =&lt;br /&gt;
&lt;br /&gt;
== User IDs ==&lt;br /&gt;
&lt;br /&gt;
Make sure your usernames/userids are case insensitive. User 'smith' and user 'Smith' should be the same user. &lt;br /&gt;
&lt;br /&gt;
=== Email address as a User ID ===&lt;br /&gt;
&lt;br /&gt;
Many sites use email addresses as a user id, which is a good mechanism for ensuring a unique identifier for each user without adding the burden of remembering a new username. However, many web applications do not treat email addresses correctly due to common misconceptions about what constitutes a valid address.&lt;br /&gt;
&lt;br /&gt;
Specifically, it is completely valid to have an mailbox address which:&lt;br /&gt;
* Is case sensitive in the local-part&lt;br /&gt;
* Has non-alphanumeric characters in the local-part (including + and '''@''')&lt;br /&gt;
* Has zero or more labels (though zero is admittedly not going to occur)&lt;br /&gt;
&lt;br /&gt;
The local-part is the part of the mailbox address to the left of the rightmost @ character.&lt;br /&gt;
The domain is the part of the mailbox address to the right of the rightmost @ character and consists of zero or more labels joined by a period character.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, RFC 5321 is the current standard defining SMTP and what constitutes a valid mailbox address.&lt;br /&gt;
&lt;br /&gt;
Please note, email addresses should be consider to be public data. For high security applications usernames could be assigned and secret instead of user-defined public data.&lt;br /&gt;
&lt;br /&gt;
==== Validation ====&lt;br /&gt;
Many web applications contain computationally expensive and inaccurate regular expressions that attempt to validate email addresses.&lt;br /&gt;
&lt;br /&gt;
Recent changes to the landscape mean that the number of false-negatives will increase, particularly due to:&lt;br /&gt;
* Increased popularity of sub-addressing by providers such as Gmail (commonly using &amp;lt;tt&amp;gt;+&amp;lt;/tt&amp;gt; as a token in the local-part to affect delivery)&lt;br /&gt;
* New gTLDs with long names (many regular expressions check the number and length of each label in the domain)&lt;br /&gt;
&lt;br /&gt;
Following RFC 5321, best practice for validating an email address would be to:&lt;br /&gt;
* Check for presence of at least one &amp;lt;tt&amp;gt;@&amp;lt;/tt&amp;gt; symbol in the address&lt;br /&gt;
* Ensure the local-part is no longer than 64 octets&lt;br /&gt;
* Ensure the domain is no longer than 255 octets&lt;br /&gt;
* Ensure the address is deliverable&lt;br /&gt;
&lt;br /&gt;
To ensure an address is deliverable, the only way to check this is to send the user an email and have the user take action to confirm receipt.&lt;br /&gt;
Beyond confirming that the email address is valid and deliverable, this also provides a positive acknowledgement that the user has access to the mailbox and is likely to be authorised to use it. This does not mean that other users cannot access this mailbox, for example when the user makes use of a service that generates a throw away email address.&lt;br /&gt;
&lt;br /&gt;
==== Address Normalisation ====&lt;br /&gt;
As the local-part of email addresses are, in fact - case sensitive, it is important to store and compare email addresses correctly.&lt;br /&gt;
To normalise an email address input, you would convert the domain part ONLY to lowercase.&lt;br /&gt;
&lt;br /&gt;
Unfortunately this does and will make input harder to normalise and correctly match to a users intent.&lt;br /&gt;
&lt;br /&gt;
It is reasonable to only accept one unique capitalisation of an otherwise identical address, however in this case it is critical to:&lt;br /&gt;
* Store the user-part as provided and verified by user verification&lt;br /&gt;
* Perform comparisons by &amp;lt;tt&amp;gt;lowercase(provided)==lowercase(persisted)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implement Proper Password Strength Controls ==&lt;br /&gt;
&lt;br /&gt;
A key concern when using passwords for authentication is password strength. A &amp;quot;strong&amp;quot; password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password: &lt;br /&gt;
&lt;br /&gt;
=== Password Length ===&lt;br /&gt;
&lt;br /&gt;
Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. &lt;br /&gt;
&lt;br /&gt;
* '''Minimum''' length of the passwords should be '''enforced''' by the application.&lt;br /&gt;
** Passwords '''shorter than 10 characters''' are considered to be weak ([http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf]).&lt;br /&gt;
&lt;br /&gt;
While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set ''passphrases'' (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.&lt;br /&gt;
&lt;br /&gt;
* '''Maximum''' password length should not be set '''too low''', as it will prevent users from creating passphrases. Typical maximum length is 128 characters.&lt;br /&gt;
** Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.&lt;br /&gt;
&lt;br /&gt;
* Every character counts!!&lt;br /&gt;
**Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).&lt;br /&gt;
**This is usually handled by setting the length of ALL password input fields to be exactly the same length as the maximum length password. This is particularly important if your max password length is short, like 20-30 characters.&lt;br /&gt;
&lt;br /&gt;
=== Password Complexity ===&lt;br /&gt;
&lt;br /&gt;
Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.&lt;br /&gt;
&lt;br /&gt;
The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:&lt;br /&gt;
&lt;br /&gt;
*Password must meet at least 3 out of the following 4 complexity rules&lt;br /&gt;
**at least 1 uppercase character (A-Z) &lt;br /&gt;
**at least 1 lowercase character (a-z) &lt;br /&gt;
**at least 1 digit (0-9) &lt;br /&gt;
**at least 1 [[Password special characters|special character (punctuation)]] &amp;amp;mdash; do not forget to treat space as special characters too&lt;br /&gt;
*at least 10 characters &lt;br /&gt;
*at most 128 characters&lt;br /&gt;
*not more than 2 identical characters in a row (e.g., 111 not allowed)&lt;br /&gt;
&lt;br /&gt;
As application's require more complex password policies, they need to be very clear about what these policies are.&lt;br /&gt;
*The required policy needs to be explicitly stated on the password change page&lt;br /&gt;
** be sure to list every special character you allow, so it's obvious to the user&lt;br /&gt;
&lt;br /&gt;
Recommendation:&lt;br /&gt;
* Ideally, the application would indicate to the user as they type in their new password how much of the complexity policy their new password meets&lt;br /&gt;
**In fact, the submit button should be grayed out until the new password meets the complexity policy and the 2nd copy of the new password matches the 1st. This will make it far easier for the user to understand and comply with your complexity policy.&lt;br /&gt;
&lt;br /&gt;
Regardless of how the UI behaves, when a user submits their password change request:&lt;br /&gt;
*If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with&lt;br /&gt;
&lt;br /&gt;
Changing passwords should be EASY, not a hunt in the dark.&lt;br /&gt;
&lt;br /&gt;
== Implement Secure Password Recovery Mechanism ==&lt;br /&gt;
&lt;br /&gt;
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [[Forgot Password Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
== Store Passwords in a Secure Fashion ==&lt;br /&gt;
&lt;br /&gt;
It is critical for a application to store a password using the right cryptographic technique. Please see [[Password Storage Cheat Sheet]] for details on this feature.&lt;br /&gt;
&lt;br /&gt;
== Transmit Passwords Only Over TLS or Other Strong Transport ==&lt;br /&gt;
&lt;br /&gt;
See: [[Transport Layer Protection Cheat Sheet]]&lt;br /&gt;
&lt;br /&gt;
The login page and all subsequent authenticated pages must be exclusively accessed over TLS or other strong transport. The initial login page, referred to as the &amp;quot;login landing page&amp;quot;, must be served over TLS or other strong transport. Failure to utilize TLS or other strong transport for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS  or other strong transport for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.&lt;br /&gt;
&lt;br /&gt;
== Require Re-authentication for Sensitive Features ==&lt;br /&gt;
&lt;br /&gt;
In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address.  Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials.  Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.&lt;br /&gt;
&lt;br /&gt;
== Utilize Multi-Factor Authentication ==&lt;br /&gt;
&lt;br /&gt;
Multi-factor authentication (MFA) is using more than one authentication factor to logon or process a transaction:&lt;br /&gt;
&lt;br /&gt;
*Something you know (account details or passwords) &lt;br /&gt;
*Something you have (tokens or mobile phones) &lt;br /&gt;
*Something you are (biometrics)&lt;br /&gt;
&lt;br /&gt;
Authentication schemes such as One Time Passwords (OTP) implemented using a hardware token can also be key in fighting attacks such as CSRF and client-side malware. A number of hardware tokens suitable for MFA are available in the market that allow good integration with web applications. See: [http://en.wikipedia.org/wiki/Security_token].&lt;br /&gt;
&lt;br /&gt;
=== TLS Client Authentication ===&lt;br /&gt;
&lt;br /&gt;
TLS Client Authentication, also known as two-way TLS authentication, consists of both, browser and server, sending their respective TLS certificates during the TLS handshake process. Just as you can validate the authenticity of a server by using the certificate and asking a well known Certificate Authority (CA) if the certificate is valid, the server can authenticate the user by receiving a certificate from the client and validating against a third party CA or its own CA. To do this, the server must provide the user with a certificate generated specifically for him, assigning values to the subject so that these can be used to determine what user the certificate should validate. The user installs the certificate on a browser and now uses it for the website.&lt;br /&gt;
&lt;br /&gt;
It is a good idea to do this when:&lt;br /&gt;
&lt;br /&gt;
*It is acceptable (or even preferred) that the user only has access to the website from only a single computer/browser.&lt;br /&gt;
*The user is not easily scared by the process of installing TLS certificates on his browser or there will be someone, probably from IT support, that will do this for the user.&lt;br /&gt;
*The website requires an extra step of security.&lt;br /&gt;
*It is also a good thing to use when the website is for an intranet of a company or organization.&lt;br /&gt;
&lt;br /&gt;
It is generally not a good idea to use this method for widely and publicly available websites that will have an average user. For example, it wouldn't be a good idea to implement this for a website like Facebook. While this technique can prevent the user from having to type a password (thus protecting against an average keylogger from stealing it), it is still considered a good idea to consider using both a password and SSL client authentication combined.&lt;br /&gt;
&lt;br /&gt;
For more information, see: [https://en.wikipedia.org/wiki/Transport_Layer_Security#Client-authenticated_TLS_handshake Client-authenticated TLS handshake]&lt;br /&gt;
&lt;br /&gt;
== Authentication and Error Messages ==&lt;br /&gt;
&lt;br /&gt;
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.&lt;br /&gt;
&lt;br /&gt;
==== Authentication Responses ====&lt;br /&gt;
&lt;br /&gt;
An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.&lt;br /&gt;
&lt;br /&gt;
==== Incorrect Response Examples ====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login for User foo: invalid password&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed, invalid user ID&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; account disabled&amp;quot; &lt;br /&gt;
*&amp;quot;Login failed; this user is not active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Correct Response Example ====&lt;br /&gt;
&lt;br /&gt;
*&amp;quot;Login failed; Invalid userID or password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID. &lt;br /&gt;
&lt;br /&gt;
==== Error Codes and URLs ====&lt;br /&gt;
&lt;br /&gt;
The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.&lt;br /&gt;
&lt;br /&gt;
== Prevent Brute-Force Attacks ==&lt;br /&gt;
&lt;br /&gt;
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.  Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.  Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.  Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.&lt;br /&gt;
&lt;br /&gt;
Also, multi-factor authentication is a very powerful deterrent when trying to prevent brute force attacks since the credentials are a moving target. When multi-factor is implemented and active, account lockout may no longer be necessary.&lt;br /&gt;
&lt;br /&gt;
= Use of authentication protocols that require no password =&lt;br /&gt;
&lt;br /&gt;
While authentication through a user/password combination and using multi-factor authentication is considered generally secure, there are use cases where it isn't considered the best option or even safe. An example of this are third party applications that desire connecting to the web application, either from a mobile device, another website, desktop or other situations. When this happens, it is NOT considered safe to allow the third party application to store the user/password combo, since then it extends the attack surface into their hands, where it isn't in your control. For this, and other use cases, there are several authentication protocols that can protect you from exposing your users' data to attackers.&lt;br /&gt;
&lt;br /&gt;
== OAuth ==&lt;br /&gt;
&lt;br /&gt;
Open Authorization (OAuth) is a protocol that allows an application to authenticate against a server as a user, without requiring passwords or any third party server that acts as an identity provider. It uses a token generated by the server, and provides how the authorization flows most occur, so that a client, such as a mobile application, can tell the server what user is using the service. &lt;br /&gt;
&lt;br /&gt;
The recommendation is to use and implement OAuth 1.0a or OAuth 2.0, since the very first version (OAuth1.0) has been found to be vulnerable to session fixation.&lt;br /&gt;
&lt;br /&gt;
OAuth 2.0 relies on HTTPS for security and is currently used and implemented by API's from companies such as Facebook, Google, Twitter and Microsoft. OAuth1.0a is more difficult to use because it requires the use of cryptographic libraries for digital signatures, however does not rely on HTTPS for security and can therefore be more suited for higher risk transactions.&lt;br /&gt;
&lt;br /&gt;
== OpenId ==&lt;br /&gt;
&lt;br /&gt;
OpenId is an HTTP-based protocol that uses identity providers to validate that a user is who he says he is. It is a very simple protocol which allows a service provider initiated way for single sign-on (SSO). This allows the user to re-use a single identity given to a trusted OpenId identity provider and be the same user in multiple websites, without the need to provide any website the password, except for the OpenId identity provider.&lt;br /&gt;
&lt;br /&gt;
Due to its simplicity and that it provides protection of passwords, OpenId has been well adopted. Some of the well known identity providers for OpenId are Stack Exchange, Google, Facebook and Yahoo!&lt;br /&gt;
&lt;br /&gt;
For non-enterprise environment, OpenId is considered a secure and often better choice, as long as the identity provider is of trust.&lt;br /&gt;
&lt;br /&gt;
== SAML ==&lt;br /&gt;
&lt;br /&gt;
Security Assertion Markup Language (SAML) is often considered to compete with OpenId. The most recommended version is 2.0, since it is very feature complete and provides a strong security. Like with OpenId, SAML uses identity providers, but unlike it, it is XML-based and provides more flexibility. SAML is based on browser redirects which send XML data. Unlike SAML, it isn't only initiated by a service provider, but it can also be initiated from the identity provider. This allows the user to navigate through different portals while still being authenticated without having to do anything, making the process transparent.&lt;br /&gt;
&lt;br /&gt;
While OpenId has taken most of the consumer market, SAML is often the choice for enterprise applications. The reason for this is often that there are few OpenId identity providers which are considered of enterprise class (meaning that the way they validate the user identity doesn't have high standards required for enterprise identity). It is more common to see SAML being used inside of intranet websites, sometimes even using a server from the intranet as the identity provider.&lt;br /&gt;
&lt;br /&gt;
In the past few years, applications like SAP ERP and SharePoint (SharePoint by using Active Directory Federation Services 2.0) have decided to use SAML 2.0 authentication as an often preferred method for single sign-on implementations whenever enterprise federation is required for web services and web applications.&lt;br /&gt;
&lt;br /&gt;
'''See also: [[SAML Security Cheat Sheet]]'''&lt;br /&gt;
&lt;br /&gt;
== FIDO ==&lt;br /&gt;
The Fast Identity Online (FIDO) Alliance has created two protocols to facilitate online authentication : the Universal Authentication Framework (UAF) protocol and the Universal Second Factor (U2F) protocol. While UAF focuses on passwordless authentication, U2F allows the addition of a second factor to existing password-based authentication. Both protocols are based on a public key cryptography challenge-response model. &lt;br /&gt;
&lt;br /&gt;
UAF takes advantage of existing security technologies present on devices for authentication including fingerprint sensors, cameras(face biometrics), microphones(voice biometrics), Trusted Execution Environments(TEEs), Secure Elements(SEs) and others. The protocol is designed to plug-in these device capabilities into a common authentication framework. UAF works with both native applications and web applications.&lt;br /&gt;
&lt;br /&gt;
U2F augments password-based authentication using a hardware token (typically USB) that stores cryptographic authentication keys and uses them for signing. The user can use the same token as a second factor for multiple applications. U2F works with web applications. It provides '''protection against phishing''' by using the URL of the website to lookup the stored authentication key.&lt;br /&gt;
&lt;br /&gt;
= Session Management General Guidelines  =&lt;br /&gt;
&lt;br /&gt;
Session management is directly related to authentication. The '''Session Management General Guidelines''' previously available on this OWASP Authentication Cheat Sheet have been integrated into the [[Session Management Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Password Managers =&lt;br /&gt;
&lt;br /&gt;
Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. The web application can help password managers by:&lt;br /&gt;
&lt;br /&gt;
* using standard HTML forms for username and password input,&lt;br /&gt;
* not disabling copy and paste on HTML form fields,&lt;br /&gt;
* allowing very long passwords,&lt;br /&gt;
* not using multi-stage login schemes (username on first screen, then password),&lt;br /&gt;
* not using highly scripted (JavaScript) authentication schemes.&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Eoin Keary eoinkeary[at]owasp.org &lt;br /&gt;
&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;padding-left:25px;width:300px;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195983</id>
		<title>SAML Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195983"/>
				<updated>2015-06-09T20:48:12Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Validate Protocol Usage */ further SAML validation recommendations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Web Browser SSO Profile with Redirect/POST bindings is the most common SSO implementation. The checklist will focus primarily on this profile.&lt;br /&gt;
&lt;br /&gt;
=Validate Message Confidentiality and Integrity=&lt;br /&gt;
&lt;br /&gt;
* [[Transport Layer Protection Cheat Sheet|TLS 1.2]] is the most common solution to guarantee message confidentiality and integrity. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
** Eavesdropping 7.1.1.1&lt;br /&gt;
** Theft of User Authentication Information 7.1.1.2&lt;br /&gt;
** Theft of the Bearer Token 7.1.1.3&lt;br /&gt;
** Message Deletion 7.1.1.6&lt;br /&gt;
** Message Modification 7.1.1.7&lt;br /&gt;
** Man-in-the-middle 7.1.1.8&lt;br /&gt;
*A digitally signed message with a certified key is the most common solution to guarantee message integrity and authentication. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
**Man-in-the-middle 6.4.2&lt;br /&gt;
**Forged Assertion 6.4.3&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Usage=&lt;br /&gt;
&lt;br /&gt;
This is a common area for security gaps - see [http://www.ai-lab.it/armando/pub/fmse9-armando.pdf Google SSO vulnerability] (AVANTSSAR 2008)  for a real life example.  Their SSO profile was vulnerable to a Man-in-the-middle attack from a malicious SP (Service Provider). The SSO Web Browser Profile is most susceptible to attacks from trusted partners. This particular security flaw was exposed because the SAML Response did not contain all of the required data elements necessary for a secure message exchange. Following the [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profile] usage requirements for AuthnRequest (4.1.4.1) and Response (4.1.4.2) will help counter this attack. The AVANTSSAR team suggested the following data elements should be required:&lt;br /&gt;
&lt;br /&gt;
* '''AuthnRequest(ID, SP);''' An AuthnRequest must contain and ID and SP. Where ID is a string uniquely identifying the request and an SP identifies the Service Provider that initiated the request. Furthermore, the request ID attribute must be returned in the response (InResponseTo=&amp;quot;&amp;lt;requestId&amp;gt;&amp;quot;). InResponseTo helps guarantee authenticity of the response from the trusted IdP. This was one of the missing attributes that left Google's SSO vulnerable.&lt;br /&gt;
* '''Response(ID, SP, IdP, {AA} K -1/IdP);''' A Response must contain all these elements. Where ID is a string uniquely identifying the response. SP identifies the recipient of the response. IdP identifies the identity provider authorizing the response. {AA} K -1/IdP is the assertion digitally signed with the private key of the IdP.&lt;br /&gt;
* '''AuthAssert(ID, C, IdP, SP);''' An authentication assertion must exist within the Response. It must contain an ID, a client (C), an identity provider (IdP), and a service provider (SP) identifier.&lt;br /&gt;
&lt;br /&gt;
Further vulnerabilities in SAML implementations were described in 2012 ([https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91-8-23-12.pdf On Breaking SAML: Be Whoever You Want to Be]). The following recommendations were proposed in response ([http://arxiv.org/pdf/1401.7483v1.pdf Secure SAML validation to prevent XML signature wrapping attacks]):&lt;br /&gt;
&lt;br /&gt;
* Always perform schema validation on the XML document prior to using it for any security-­related purposes.&lt;br /&gt;
** Always use local, trusted copies of schemas for validation.&lt;br /&gt;
** Never allow automatic download of schemas from third party locations.&lt;br /&gt;
** If possible, inspect schemas and perform schema hardening, to disable possible wildcard ­type or relaxed processing statements.&lt;br /&gt;
* Securely validate the digital signature.&lt;br /&gt;
** If you only expect only one signing key, use StaticKeySelector. Obtain the key directly from the identity provider, store it in local file and ignore any KeyInfo elements in the document.&lt;br /&gt;
** If you expect more than one signing key, use X509KeySelector (the JKS variant). Obtain these keys directly form the identity providers, store them in local JKS and ignore any KeyInfo elements in the document.&lt;br /&gt;
** If you expect a heterogenous signed documents (many certificates from many identity providers, multi­level validation paths), implement full trust establishment model based on PKIX and trusted root certificates.&lt;br /&gt;
* Avoid signature-wrapping attacks.&lt;br /&gt;
** Never used getElementsByTagName to select security related elements in an XML document without prior validation.&lt;br /&gt;
**Always use absolute XPath expressions to select elements, unless a hardened schema is used for validation.&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Processing Rules=&lt;br /&gt;
&lt;br /&gt;
This is another common area for security gaps simply because of the vast number of steps to assert. Processing a SAML response is an expensive operation but all steps must be validated.&lt;br /&gt;
*Validate AuthnRequest processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf SAML Core] (3.4.1.4) for all AuthnRequest processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
* Validate Response processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profiles] (4.1.4.3) for all Response processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Stolen Assertion (6.4.1)&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
** Forged Assertion (6.4.3)&lt;br /&gt;
** Browser State Exposure (6.4.4)&lt;br /&gt;
&lt;br /&gt;
=Validate Binding Implementation=&lt;br /&gt;
&lt;br /&gt;
*For an HTTP Redirect Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.4). To view an encoding example, you may want to reference RequestUtil.java found within [https://developers.google.com/google-apps/sso/saml_reference_implementation_web Google's reference implementation].&lt;br /&gt;
* For an HTTP POST Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.5). The caching considerations are also very important. If a SAML protocol message gets cached, it can subsequently be used as a Stolen Assertion (6.4.1) or Replay (6.4.5) attack.&lt;br /&gt;
&lt;br /&gt;
=Validate Security Countermeasures=&lt;br /&gt;
&lt;br /&gt;
Revisit each security threat that exists within the [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security] document and assert you have applied the appropriate countermeasures for threats that may exist for your particular implementation. Additional countermeasures considererd should include:&lt;br /&gt;
*Prefer IP Filtering when appropriate. For example, this countermeasure could have prevented Google's initial security flaw if Google provided each trusted partner with a separate endpoint and setup an IP filter for each endpoint. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Man-in-the-middle (6.4.2)&lt;br /&gt;
*Prefer short lifetimes on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
*Prefer OneTimeUse on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
**Replay (6.4.5)&lt;br /&gt;
&lt;br /&gt;
Need an architectural diagram? The [http://www.oasis-open.org/committees/download.php/11511/sstc-saml-tech-overview-2.0-draft-03.pdf SAML technical overview] contains the most complete diagrams. For the Web Browser SSO Profile with Redirect/POST bindings refer to the section 4.1.3. In fact, of all the SAML documentation, the technical overview is the most valuable from a high-level perspective.&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* [http://bradbroulik.blogspot.dk/2010/01/bulletproof-sso-with-saml-20.html Brad Broulik]&lt;br /&gt;
* [https://ipsec.pl/ Paweł Krawczyk]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195982</id>
		<title>SAML Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195982"/>
				<updated>2015-06-09T20:33:55Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Validate Protocol Processing Rules */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Web Browser SSO Profile with Redirect/POST bindings is the most common SSO implementation. The checklist will focus primarily on this profile.&lt;br /&gt;
&lt;br /&gt;
=Validate Message Confidentiality and Integrity=&lt;br /&gt;
&lt;br /&gt;
* [[Transport Layer Protection Cheat Sheet|TLS 1.2]] is the most common solution to guarantee message confidentiality and integrity. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
** Eavesdropping 7.1.1.1&lt;br /&gt;
** Theft of User Authentication Information 7.1.1.2&lt;br /&gt;
** Theft of the Bearer Token 7.1.1.3&lt;br /&gt;
** Message Deletion 7.1.1.6&lt;br /&gt;
** Message Modification 7.1.1.7&lt;br /&gt;
** Man-in-the-middle 7.1.1.8&lt;br /&gt;
*A digitally signed message with a certified key is the most common solution to guarantee message integrity and authentication. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
**Man-in-the-middle 6.4.2&lt;br /&gt;
**Forged Assertion 6.4.3&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Usage=&lt;br /&gt;
&lt;br /&gt;
This is a common area for security gaps - see [http://www.ai-lab.it/armando/pub/fmse9-armando.pdf Google SSO vulnerability] (AVANTSSAR 2008)  for a real life example.  Their SSO profile was vulnerable to a Man-in-the-middle attack from a malicious SP (Service Provider). The SSO Web Browser Profile is most susceptible to attacks from trusted partners. This particular security flaw was exposed because the SAML Response did not contain all of the required data elements necessary for a secure message exchange. Following the [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profile] usage requirements for AuthnRequest (4.1.4.1) and Response (4.1.4.2) will help counter this attack. The AVANTSSAR team suggested the following data elements should be required:&lt;br /&gt;
&lt;br /&gt;
* '''AuthnRequest(ID, SP);''' An AuthnRequest must contain and ID and SP. Where ID is a string uniquely identifying the request and an SP identifies the Service Provider that initiated the request. Furthermore, the request ID attribute must be returned in the response (InResponseTo=&amp;quot;&amp;lt;requestId&amp;gt;&amp;quot;). InResponseTo helps guarantee authenticity of the response from the trusted IdP. This was one of the missing attributes that left Google's SSO vulnerable.&lt;br /&gt;
* '''Response(ID, SP, IdP, {AA} K -1/IdP);''' A Response must contain all these elements. Where ID is a string uniquely identifying the response. SP identifies the recipient of the response. IdP identifies the identity provider authorizing the response. {AA} K -1/IdP is the assertion digitally signed with the private key of the IdP.&lt;br /&gt;
* '''AuthAssert(ID, C, IdP, SP);''' An authentication assertion must exist within the Response. It must contain an ID, a client (C), an identity provider (IdP), and a service provider (SP) identifier.&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Processing Rules=&lt;br /&gt;
&lt;br /&gt;
This is another common area for security gaps simply because of the vast number of steps to assert. Processing a SAML response is an expensive operation but all steps must be validated.&lt;br /&gt;
*Validate AuthnRequest processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf SAML Core] (3.4.1.4) for all AuthnRequest processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
* Validate Response processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profiles] (4.1.4.3) for all Response processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Stolen Assertion (6.4.1)&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
** Forged Assertion (6.4.3)&lt;br /&gt;
** Browser State Exposure (6.4.4)&lt;br /&gt;
&lt;br /&gt;
=Validate Binding Implementation=&lt;br /&gt;
&lt;br /&gt;
*For an HTTP Redirect Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.4). To view an encoding example, you may want to reference RequestUtil.java found within [https://developers.google.com/google-apps/sso/saml_reference_implementation_web Google's reference implementation].&lt;br /&gt;
* For an HTTP POST Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.5). The caching considerations are also very important. If a SAML protocol message gets cached, it can subsequently be used as a Stolen Assertion (6.4.1) or Replay (6.4.5) attack.&lt;br /&gt;
&lt;br /&gt;
=Validate Security Countermeasures=&lt;br /&gt;
&lt;br /&gt;
Revisit each security threat that exists within the [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security] document and assert you have applied the appropriate countermeasures for threats that may exist for your particular implementation. Additional countermeasures considererd should include:&lt;br /&gt;
*Prefer IP Filtering when appropriate. For example, this countermeasure could have prevented Google's initial security flaw if Google provided each trusted partner with a separate endpoint and setup an IP filter for each endpoint. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Man-in-the-middle (6.4.2)&lt;br /&gt;
*Prefer short lifetimes on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
*Prefer OneTimeUse on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
**Replay (6.4.5)&lt;br /&gt;
&lt;br /&gt;
Need an architectural diagram? The [http://www.oasis-open.org/committees/download.php/11511/sstc-saml-tech-overview-2.0-draft-03.pdf SAML technical overview] contains the most complete diagrams. For the Web Browser SSO Profile with Redirect/POST bindings refer to the section 4.1.3. In fact, of all the SAML documentation, the technical overview is the most valuable from a high-level perspective.&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* [http://bradbroulik.blogspot.dk/2010/01/bulletproof-sso-with-saml-20.html Brad Broulik]&lt;br /&gt;
* [https://ipsec.pl/ Paweł Krawczyk]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195981</id>
		<title>SAML Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195981"/>
				<updated>2015-06-09T20:33:35Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Validate Protocol Usage */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Web Browser SSO Profile with Redirect/POST bindings is the most common SSO implementation. The checklist will focus primarily on this profile.&lt;br /&gt;
&lt;br /&gt;
=Validate Message Confidentiality and Integrity=&lt;br /&gt;
&lt;br /&gt;
* [[Transport Layer Protection Cheat Sheet|TLS 1.2]] is the most common solution to guarantee message confidentiality and integrity. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
** Eavesdropping 7.1.1.1&lt;br /&gt;
** Theft of User Authentication Information 7.1.1.2&lt;br /&gt;
** Theft of the Bearer Token 7.1.1.3&lt;br /&gt;
** Message Deletion 7.1.1.6&lt;br /&gt;
** Message Modification 7.1.1.7&lt;br /&gt;
** Man-in-the-middle 7.1.1.8&lt;br /&gt;
*A digitally signed message with a certified key is the most common solution to guarantee message integrity and authentication. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
**Man-in-the-middle 6.4.2&lt;br /&gt;
**Forged Assertion 6.4.3&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Usage=&lt;br /&gt;
&lt;br /&gt;
This is a common area for security gaps - see [http://www.ai-lab.it/armando/pub/fmse9-armando.pdf Google SSO vulnerability] (AVANTSSAR 2008)  for a real life example.  Their SSO profile was vulnerable to a Man-in-the-middle attack from a malicious SP (Service Provider). The SSO Web Browser Profile is most susceptible to attacks from trusted partners. This particular security flaw was exposed because the SAML Response did not contain all of the required data elements necessary for a secure message exchange. Following the [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profile] usage requirements for AuthnRequest (4.1.4.1) and Response (4.1.4.2) will help counter this attack. The AVANTSSAR team suggested the following data elements should be required:&lt;br /&gt;
&lt;br /&gt;
* '''AuthnRequest(ID, SP);''' An AuthnRequest must contain and ID and SP. Where ID is a string uniquely identifying the request and an SP identifies the Service Provider that initiated the request. Furthermore, the request ID attribute must be returned in the response (InResponseTo=&amp;quot;&amp;lt;requestId&amp;gt;&amp;quot;). InResponseTo helps guarantee authenticity of the response from the trusted IdP. This was one of the missing attributes that left Google's SSO vulnerable.&lt;br /&gt;
* '''Response(ID, SP, IdP, {AA} K -1/IdP);''' A Response must contain all these elements. Where ID is a string uniquely identifying the response. SP identifies the recipient of the response. IdP identifies the identity provider authorizing the response. {AA} K -1/IdP is the assertion digitally signed with the private key of the IdP.&lt;br /&gt;
* '''AuthAssert(ID, C, IdP, SP);''' An authentication assertion must exist within the Response. It must contain an ID, a client (C), an identity provider (IdP), and a service provider (SP) identifier.&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Processing Rules=&lt;br /&gt;
&lt;br /&gt;
*This is another common area for security gaps simply because of the vast number of steps to assert. Processing a SAML response is an expensive operation but all steps must be validated.&lt;br /&gt;
Validate AuthnRequest processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf SAML Core] (3.4.1.4) for all AuthnRequest processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
* Validate Response processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profiles] (4.1.4.3) for all Response processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Stolen Assertion (6.4.1)&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
** Forged Assertion (6.4.3)&lt;br /&gt;
** Browser State Exposure (6.4.4)&lt;br /&gt;
&lt;br /&gt;
=Validate Binding Implementation=&lt;br /&gt;
&lt;br /&gt;
*For an HTTP Redirect Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.4). To view an encoding example, you may want to reference RequestUtil.java found within [https://developers.google.com/google-apps/sso/saml_reference_implementation_web Google's reference implementation].&lt;br /&gt;
* For an HTTP POST Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.5). The caching considerations are also very important. If a SAML protocol message gets cached, it can subsequently be used as a Stolen Assertion (6.4.1) or Replay (6.4.5) attack.&lt;br /&gt;
&lt;br /&gt;
=Validate Security Countermeasures=&lt;br /&gt;
&lt;br /&gt;
Revisit each security threat that exists within the [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security] document and assert you have applied the appropriate countermeasures for threats that may exist for your particular implementation. Additional countermeasures considererd should include:&lt;br /&gt;
*Prefer IP Filtering when appropriate. For example, this countermeasure could have prevented Google's initial security flaw if Google provided each trusted partner with a separate endpoint and setup an IP filter for each endpoint. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Man-in-the-middle (6.4.2)&lt;br /&gt;
*Prefer short lifetimes on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
*Prefer OneTimeUse on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
**Replay (6.4.5)&lt;br /&gt;
&lt;br /&gt;
Need an architectural diagram? The [http://www.oasis-open.org/committees/download.php/11511/sstc-saml-tech-overview-2.0-draft-03.pdf SAML technical overview] contains the most complete diagrams. For the Web Browser SSO Profile with Redirect/POST bindings refer to the section 4.1.3. In fact, of all the SAML documentation, the technical overview is the most valuable from a high-level perspective.&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* [http://bradbroulik.blogspot.dk/2010/01/bulletproof-sso-with-saml-20.html Brad Broulik]&lt;br /&gt;
* [https://ipsec.pl/ Paweł Krawczyk]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195980</id>
		<title>SAML Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SAML_Security_Cheat_Sheet&amp;diff=195980"/>
				<updated>2015-06-09T20:33:10Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: add initial version based on Brad Broulik article (used with author's written permission, wikified and updated)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Web Browser SSO Profile with Redirect/POST bindings is the most common SSO implementation. The checklist will focus primarily on this profile.&lt;br /&gt;
&lt;br /&gt;
=Validate Message Confidentiality and Integrity=&lt;br /&gt;
&lt;br /&gt;
* [[Transport Layer Protection Cheat Sheet|TLS 1.2]] is the most common solution to guarantee message confidentiality and integrity. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
** Eavesdropping 7.1.1.1&lt;br /&gt;
** Theft of User Authentication Information 7.1.1.2&lt;br /&gt;
** Theft of the Bearer Token 7.1.1.3&lt;br /&gt;
** Message Deletion 7.1.1.6&lt;br /&gt;
** Message Modification 7.1.1.7&lt;br /&gt;
** Man-in-the-middle 7.1.1.8&lt;br /&gt;
*A digitally signed message with a certified key is the most common solution to guarantee message integrity and authentication. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security (section 4)] for additional information. This step will help counter the following attacks:&lt;br /&gt;
**Man-in-the-middle 6.4.2&lt;br /&gt;
**Forged Assertion 6.4.3&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Usage=&lt;br /&gt;
&lt;br /&gt;
This is a common area for security gaps - see [http://www.ai-lab.it/armando/pub/fmse9-armando.pdf Google SSO vulnerability] (AVANTSSAR 2008)  for a real life example.  Their SSO profile was vulnerable to a Man-in-the-middle attack from a malicious SP (Service Provider). The SSO Web Browser Profile is most susceptible to attacks from trusted partners. This particular security flaw was exposed because the SAML Response did not contain all of the required data elements necessary for a secure message exchange. Following the [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profile] usage requirements for AuthnRequest (4.1.4.1) and Response (4.1.4.2) will help counter this attack. The AVANTSSAR team suggested the following data elements should be required:&lt;br /&gt;
&lt;br /&gt;
* '''AuthnRequest(ID, SP);''' An AuthnRequest must contain and ID and SP. Where ID is a string uniquely identifying the request and an SP identifies the Service Provider that initiated the request. Furthermore, the request ID attribute must be returned in the response (InResponseTo=&amp;quot;&amp;lt;requestId&amp;gt;&amp;quot;). InResponseTo helps guarantee authenticity of the response from the trusted IdP. This was one of the missing attributes that left Google's SSO vulnerable.&lt;br /&gt;
 * '''Response(ID, SP, IdP, {AA} K -1/IdP);''' A Response must contain all these elements. Where ID is a string uniquely identifying the response. SP identifies the recipient of the response. IdP identifies the identity provider authorizing the response. {AA} K -1/IdP is the assertion digitally signed with the private key of the IdP.&lt;br /&gt;
* '''AuthAssert(ID, C, IdP, SP);''' An authentication assertion must exist within the Response. It must contain an ID, a client (C), an identity provider (IdP), and a service provider (SP) identifier.&lt;br /&gt;
&lt;br /&gt;
=Validate Protocol Processing Rules=&lt;br /&gt;
&lt;br /&gt;
*This is another common area for security gaps simply because of the vast number of steps to assert. Processing a SAML response is an expensive operation but all steps must be validated.&lt;br /&gt;
Validate AuthnRequest processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf SAML Core] (3.4.1.4) for all AuthnRequest processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
* Validate Response processing rules. Refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf SAML Profiles] (4.1.4.3) for all Response processing rules. This step will help counter the following attacks:&lt;br /&gt;
** Stolen Assertion (6.4.1)&lt;br /&gt;
** Man-in-the-middle (6.4.2)&lt;br /&gt;
** Forged Assertion (6.4.3)&lt;br /&gt;
** Browser State Exposure (6.4.4)&lt;br /&gt;
&lt;br /&gt;
=Validate Binding Implementation=&lt;br /&gt;
&lt;br /&gt;
*For an HTTP Redirect Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.4). To view an encoding example, you may want to reference RequestUtil.java found within [https://developers.google.com/google-apps/sso/saml_reference_implementation_web Google's reference implementation].&lt;br /&gt;
* For an HTTP POST Binding refer to [http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf SAML Binding] (3.5). The caching considerations are also very important. If a SAML protocol message gets cached, it can subsequently be used as a Stolen Assertion (6.4.1) or Replay (6.4.5) attack.&lt;br /&gt;
&lt;br /&gt;
=Validate Security Countermeasures=&lt;br /&gt;
&lt;br /&gt;
Revisit each security threat that exists within the [http://docs.oasis-open.org/security/saml/v2.0/saml-sec-consider-2.0-os.pdf SAML Security] document and assert you have applied the appropriate countermeasures for threats that may exist for your particular implementation. Additional countermeasures considererd should include:&lt;br /&gt;
*Prefer IP Filtering when appropriate. For example, this countermeasure could have prevented Google's initial security flaw if Google provided each trusted partner with a separate endpoint and setup an IP filter for each endpoint. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Man-in-the-middle (6.4.2)&lt;br /&gt;
*Prefer short lifetimes on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Stolen Assertion (6.4.1)&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
*Prefer OneTimeUse on the SAML Response. This step will help counter the following attacks:&lt;br /&gt;
**Browser State Exposure (6.4.4)&lt;br /&gt;
**Replay (6.4.5)&lt;br /&gt;
&lt;br /&gt;
Need an architectural diagram? The [http://www.oasis-open.org/committees/download.php/11511/sstc-saml-tech-overview-2.0-draft-03.pdf SAML technical overview] contains the most complete diagrams. For the Web Browser SSO Profile with Redirect/POST bindings refer to the section 4.1.3. In fact, of all the SAML documentation, the technical overview is the most valuable from a high-level perspective.&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* [http://bradbroulik.blogspot.dk/2010/01/bulletproof-sso-with-saml-20.html Brad Broulik]&lt;br /&gt;
* [https://ipsec.pl/ Paweł Krawczyk]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy_Cheat_Sheet&amp;diff=195979</id>
		<title>Content Security Policy Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy_Cheat_Sheet&amp;diff=195979"/>
				<updated>2015-06-09T20:19:00Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* Removing unsafe-inline */ add more examples of refactoring inline code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Content Security Policy (CSP) is an important standard by the W3C that is aimed to prevent a broad range of content injection attacks such as cross-site scripting (XSS). &lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
Content Security Policy (CSP) is an effective &amp;quot;defense in depth&amp;quot; technique to be used against content injection attacks. It is a declarative policy that informs the user agent what are valid sources to load from.&lt;br /&gt;
&lt;br /&gt;
Since, it was introduced in Firefox version 4 by Mozilla, it has been adopted as a standard, and grown in adoption and capabilities.&lt;br /&gt;
&lt;br /&gt;
This document is meant to provide guidance on how to utilize CSP under a variety of situations to address a variety of concerns.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Specifications of the CSP standard can be found the following locations:&lt;br /&gt;
* Latest Revision - https://w3c.github.io/webappsec/specs/content-security-policy/&lt;br /&gt;
* Latest Version (CSP2) - http://www.w3.org/TR/CSP2/&lt;br /&gt;
* CSP 1.0 - http://www.w3.org/TR/2012/CR-CSP-20121115/&lt;br /&gt;
&lt;br /&gt;
= CSP Basics =&lt;br /&gt;
&lt;br /&gt;
CSP consists of a series of directives. CSP has also evolved over two major revisions. Most browsers support 1.0, and adoption of CSP2 has been incremental.&lt;br /&gt;
&lt;br /&gt;
== HTTP Headers ==&lt;br /&gt;
&lt;br /&gt;
The following are headers for CSP.&lt;br /&gt;
&lt;br /&gt;
* '''Content-Security-Policy''' : W3C Spec standard header. Supported by Firefox 23+, Chrome 25+ and Opera 19+&lt;br /&gt;
* '''Content-Security-Policy-Report-Only''' : W3C Spec standard header. Supported by Firefox 23+, Chrome 25+ and Opera 19+, whereby the policy is non-blocking (&amp;quot;fail open&amp;quot;) and a report is sent to the URL designated by the '''report-uri''' directive. This is often used as a precursor to utilizing CSP in blocking mode (&amp;quot;fail closed&amp;quot;)&lt;br /&gt;
* '''DO NOT''' use X-Content-Security-Policy or X-WebKit-CSP. Their implementations are obsolete (since Firefox 23, Chrome 25), limited, inconsistent, and incredibly buggy.&lt;br /&gt;
&lt;br /&gt;
== Directives == &lt;br /&gt;
&lt;br /&gt;
The following is a listing of directives, and a brief description.&lt;br /&gt;
&lt;br /&gt;
=== CSP 1.0 Spec ===&lt;br /&gt;
* '''connect-src''' (d) - restricts which URLs the protected resource can load using script interfaces. (e.g.  send() method of an XMLHttpRequest object) &lt;br /&gt;
* '''font-src''' (d) - restricts from where the protected resource can load fonts&lt;br /&gt;
* '''img-src''' (d) - restricts from where the protected resource can load images&lt;br /&gt;
* '''media-src''' (d) -  restricts from where the protected resource can load video, audio, and associated text tracks&lt;br /&gt;
* '''object-src''' (d) - restricts from where the protected resource can load plugins&lt;br /&gt;
* '''script-src''' (d) -  restricts which scripts the protected resource can execute. Additional restrictions against, inline scripts, and eval. Additional directives in CSP2 for hash and nonce support&lt;br /&gt;
* '''style-src''' (d) - restricts which styles the user may applies to the protected resource. Additional restrictions against inline and eval.&lt;br /&gt;
* '''default-src''' - Covers any directive with ''(d)''&lt;br /&gt;
* '''frame-src''' - restricts from where the protected resource can embed frames. Note, deprecated in CSP2&lt;br /&gt;
* '''report-uri''' - specifies a URL to which the user agent sends reports about policy violation&lt;br /&gt;
* '''sandbox''' - specifies an HTML sandbox policy that the user agent applies to the protected resource. Optional in 1.0&lt;br /&gt;
&lt;br /&gt;
=== New in CSP2 ===&lt;br /&gt;
* '''form-action''' - retricts which URLs can be used as the action of HTML form elements&lt;br /&gt;
* '''frame-ancestors''' - indicates whether the user agent should allow embedding the resource using a frame, iframe, object, embed or applet element, or equivalent functionality in non-HTML resources&lt;br /&gt;
* '''plugin-types''' - restricts the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded&lt;br /&gt;
* '''base-uri''' -  restricts the URLs that can be used to specify the document base URL&lt;br /&gt;
* '''child-src''' (d) -  governs the creation of nested browsing contexts as well as Worker execution contexts&lt;br /&gt;
&lt;br /&gt;
= CSP Sample Policies =&lt;br /&gt;
&lt;br /&gt;
== Basic CSP Policy ==&lt;br /&gt;
&lt;br /&gt;
This policy will only allow resources from the originating domain for all the default level directives, and will not allow inline scripts/styles to execute. If your application and function with these restrictions, it drastically reduces your attack surface having this policy in place, and will work with most modern browsers.&lt;br /&gt;
&lt;br /&gt;
The most basic policy assumes:&lt;br /&gt;
* all resources are hosted by the same domain of the document&lt;br /&gt;
* there are no inlines or evals for scripts and style resources&lt;br /&gt;
&lt;br /&gt;
  Content-Security-Policy: default-src 'self' &lt;br /&gt;
&lt;br /&gt;
To tighten further, one can do the following:&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';&lt;br /&gt;
&lt;br /&gt;
This policy allows images, scripts, AJAX, and CSS from the same origin, and does not allow any other resources to load (eg. object, frame, media, etc). (see http://content-security-policy.com/)&lt;br /&gt;
&lt;br /&gt;
== Mixed Content Policy ==&lt;br /&gt;
&lt;br /&gt;
In order to prevent mixed content (resources being loaded over http, from a document loaded over https), one can use the value &amp;quot;https:&amp;quot; as a directive value.&lt;br /&gt;
&lt;br /&gt;
For instance:&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: default-src https:; connect-src https:; font-src https: data:; frame-src https:; &lt;br /&gt;
 img-src https: data:; media-src https:;  object-src https:; script-src 'unsafe-inline' 'unsafe-eval' https:; &lt;br /&gt;
 style-src 'unsafe-inline' https:;&lt;br /&gt;
&lt;br /&gt;
This is what was used at Twitter, Oct 2014. The policy prevents mixed content, allows for scheme &amp;quot;data:&amp;quot; in font-src and img-src, allows for unsafe-inline and unsafe-eval for script-src, and unsafe-inline for style-src. (see: https://twittercommunity.com/t/blocking-mixed-content-with-content-security-policy/26375)&lt;br /&gt;
&lt;br /&gt;
Mixed Content has two categories: Active and Passive. Passive content consists of &amp;quot;resources which cannot directly interact with or modify other resources on a page: images, fonts, audio, and video for example&amp;quot;, whereas active content is &amp;quot;content which can in some way directly manipulate the resource with which a user is interacting.&amp;quot;  (http://www.w3.org/TR/2014/WD-mixed-content-20140722)&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: img-src https: data:; font-src https: data:; media-src https:;&lt;br /&gt;
&lt;br /&gt;
This is an example to block only passive mixed content.&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: script-src https:; style-src https:; object-src https:; connect-src https:; frame-src https:; &lt;br /&gt;
&lt;br /&gt;
This is an example to block only active mixed content.&lt;br /&gt;
&lt;br /&gt;
== Preventing Clickjacking ==&lt;br /&gt;
&lt;br /&gt;
The established way of preventing clickjacking involves the use of the header &amp;lt;code&amp;gt;X-Frame-Options&amp;lt;/code&amp;gt; (see: [[Clickjacking_Defense_Cheat_Sheet]]). However, CSP 2.0 has a new directive &amp;lt;code&amp;gt;frame-ancestors&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To prevent all framing of your content use:&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: frame-ancestors 'none'&lt;br /&gt;
&lt;br /&gt;
To allow for your site only, use:&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: frame-ancestors 'self'&lt;br /&gt;
&lt;br /&gt;
To allow for trusted domain (my-trusty-site.com), do the following:&lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: frame-ancestors my-trusty-site.com &lt;br /&gt;
&lt;br /&gt;
A word about support. Not supported in all browsers yet, Chrome 40+ and FF 35+ support, but will also default to X-Frame-Options if it exists. Spec says, CSP should take precedence. https://w3c.github.io/webappsec/specs/content-security-policy/#frame-ancestors-and-frame-options&lt;br /&gt;
&lt;br /&gt;
Also, keep in mind the following (from the [https://w3c.github.io/webappsec/specs/content-security-policy/#frame-ancestors-and-frame-options CSP Spec]):&lt;br /&gt;
&lt;br /&gt;
 The frame-ancestors directive MUST be ignored when monitoring a policy, and when a contained in a policy defined via a meta element.&lt;br /&gt;
&lt;br /&gt;
In otherwords, this will not work when CSP is in a &amp;lt;meta&amp;gt; tag, and will not work when using Content-Security-Policy-Report-Only.&lt;br /&gt;
&lt;br /&gt;
When a report is generated, the blocked-uri will only have a value if it is the same origin as the page.&lt;br /&gt;
&lt;br /&gt;
= Refactoring inline code =&lt;br /&gt;
By default CSP disables any unsigned JavaScript code placed inline in the HTML source, such as this:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;script&amp;gt;var foo = &amp;quot;314&amp;quot;&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The inline code can be enabled by '''specifying its SHA256 hash''' in the CSP header:&lt;br /&gt;
&lt;br /&gt;
     Content-Security-Policy: script-src 'sha256-gPMJwWBMWDx0Cm7ZygJKZIU2vZpiYvzUQjl5Rh37hKs='&lt;br /&gt;
&lt;br /&gt;
This particular script's hash can be calculated using the following command:&lt;br /&gt;
&lt;br /&gt;
    echo -n 'var foo = &amp;quot;314&amp;quot;' | openssl sha256 -binary | openssl base64&lt;br /&gt;
&lt;br /&gt;
Some browsers (e.g. Chrome) will also display the hash of the script in JavaScript console warning when blocking an unsigned script.&lt;br /&gt;
&lt;br /&gt;
The inline code can be also simply moved to a separate JavaScript file:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;script&amp;gt;var foo = &amp;quot;314&amp;quot;&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
becomes:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;script src=&amp;quot;app.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
with `app.js` containing the `var foo = &amp;quot;314&amp;quot;` code.&lt;br /&gt;
&lt;br /&gt;
The inline code restriction also applies to '''inline event handlers''', so that the following construct will be blocked under CSP:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;button id=&amp;quot;button1&amp;quot; onclick=&amp;quot;doSomething()&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should be replaced by `addEventListener' calls:&lt;br /&gt;
&lt;br /&gt;
    document.getElementById(&amp;quot;button1&amp;quot;).addEventListener('click', doSomething);&lt;br /&gt;
&lt;br /&gt;
Variable assignment in inline scripts. Rather than do this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;script&amp;gt;var foo = &amp;quot;314&amp;quot;;&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leverage HTML5's custom data attributes by setting the value as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;body data-foo=&amp;quot;314”&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
 &amp;lt;/body&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And access the value by doing:&lt;br /&gt;
&lt;br /&gt;
   var itemID = document.body.getAttribute(&amp;quot;data-foo”);&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
* Neil Mattatall - neil[at]owasp.org&lt;br /&gt;
* Denis Mello - ddtaxe&lt;br /&gt;
* Boris Chen&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Certificate_and_Public_Key_Pinning&amp;diff=193599</id>
		<title>Certificate and Public Key Pinning</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Certificate_and_Public_Key_Pinning&amp;diff=193599"/>
				<updated>2015-04-17T20:49:29Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* HTTP pinning */ RFC 7469&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Certificate and Public Key Pinning]] is a technical guide to implementing certificate and public key pinning as discussed at the ''[https://www.owasp.org/index.php/Virginia Virginia chapter's]'' presentation [[Media:Securing-Wireless-Channels-in-the-Mobile-Space.ppt|Securing Wireless Channels in the Mobile Space]]. This guide is focused on providing clear, simple, actionable guidance for securing the channel in a hostile environment where actors could be malicious and the conference of trust a liability. Additional presentation material included [[Media:pubkey-pin-supplement.pdf|supplement with code excerpts]], [[Media:pubkey-pin-android.zip|Android sample program]], [[Media:pubkey-pin-ios.zip|iOS sample program]], [[Media:pubkey-pin-dotnet.zip|.Net sample program]], and [[Media:pubkey-pin-openssl.zip|OpenSSL sample program]].&lt;br /&gt;
&lt;br /&gt;
A cheat sheet is available at [[Pinning_Cheat_Sheet|Pinning Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
Secure channels are a cornerstone to users and employees working remotely and on the go. Users and developers expect end-to-end security when sending and receiving data - especially sensitive data on channels protected by VPN, SSL, or TLS. While organizations which control DNS and CA have likely reduced risk to trivial levels under most threat models, users and developers subjugated to other's DNS and a public CA hierarchy are exposed to non-trivial amounts of risk. In fact, history has shown those relying on outside services have suffered chronic breaches in their secure channels.&lt;br /&gt;
&lt;br /&gt;
The pandemic abuse of trust has resulted in users, developers and applications making security related decisions on untrusted input. The situation is somewhat of a paradox: entities such as DNS and CAs are trusted and supposed to supply trusted input; yet their input cannot be trusted. Relying on untrusted input for security related decisions is not only bad karma, it violates a number of secure coding principals (see, for example, OWASP's [[Injection Theory]] and [[Data Validation]]).&lt;br /&gt;
&lt;br /&gt;
Pinning effectively removes the &amp;quot;conference of trust&amp;quot;. An application which pins a certificate or public key no longer needs to depend on others - such as DNS or CAs - when making security decisions relating to a peer's identity. For those familiar with SSH, you should realize that public key pinning is nearly identical to SSH's &amp;lt;tt&amp;gt;StrictHostKeyChecking&amp;lt;/tt&amp;gt; option. SSH had it right the entire time, and the rest of the world is beginning to realize the virtues of directly identifying a host or service by its public key.&lt;br /&gt;
&lt;br /&gt;
Others who actively engage in pinning include Google and its browser Chrome. Chrome was successful in detecting the DigiNotar compromise which uncovered suspected interception by the Iranian government on its citizens. The initial report of the compromise can be found at ''[https://productforums.google.com/d/topic/gmail/3J3r2JqFNTw/discussion Is This MITM Attack to Gmail's SSL?]''; and Google Security's immediate response at ''[https://googleonlinesecurity.blogspot.com/2011/08/update-on-attempted-man-in-middle.html An update on attempted man-in-the-middle attacks]''.&lt;br /&gt;
&lt;br /&gt;
== What's the problem? ==&lt;br /&gt;
&lt;br /&gt;
Users, developers, and applications expect end-to-end security on their secure channels, but some secure channels are not meeting the expectation. Specifically, channels built using well known protocols such as VPN, SSL, and TLS can be vulnerable to a number of attacks.&lt;br /&gt;
&lt;br /&gt;
Examples of past failures are listed on the discussion tab for this article. This cheat sheet does not attempt to catalogue the failures in the industry, investigate the design flaws in the scaffolding, justify the lack of accountability or liability with the providers, explain the race to the bottom in services, or demystify the collusion between, for example, Browsers and CAs. For additional reading, please visit ''[http://www.cs.auckland.ac.nz/~pgut001/pubs/pkitutorial.pdf PKI is Broken]'' and ''[http://blog.cryptographyengineering.com/2012/02/how-to-fix-internet.html The Internet is Broken]''.&lt;br /&gt;
&lt;br /&gt;
=== Patient 0 ===&lt;br /&gt;
&lt;br /&gt;
The original problem was the ''Key Distribution Problem''. Insecure communications can be transformed into a secure communication problem with encryption. Encrypted communications can be transformed into an identity problem with signatures. The identity problem terminates at the key distribution problem. They are the same problem.&lt;br /&gt;
&lt;br /&gt;
=== The Cures ===&lt;br /&gt;
&lt;br /&gt;
There are three cures for the key distribution problem. First is to have first hand knowledge of your partner or peer (i.e., a peer, server or service). This could be solved with SneakerNet. Unfortunately, SneakerNet does not scale and cannot be used to solve the key distribution problem.&lt;br /&gt;
&lt;br /&gt;
The second is to rely on others, and it has two variants: (1) web of trust, and (2) hierarchy of trust. Web of Trust and Hierarchy of Trust solve the key distribution problem in a sterile environment. However, Web of Trust and Hierarchy of Trust each requires us to rely on others - or '''confer trust'''. In practice, trusting others is showing to be problematic.&lt;br /&gt;
&lt;br /&gt;
== What Is Pinning? ==&lt;br /&gt;
&lt;br /&gt;
Pinning is the process of associating a host with their ''expected'' X509 certificate or public key. Once a certificate or public key is known or seen for a host, the certificate or public key is associated or 'pinned' to the host. If more than one certificate or public key is acceptable, then the program holds a ''pinset'' (taking from [https://developers.google.com/events/io/sessions/gooio2012/107/ Jon Larimer and Kenny Root Google I/O talk]). In this case, the advertised identity must match one of the elements in the pinset.&lt;br /&gt;
&lt;br /&gt;
A host or service's certificate or public key can be added to an application at development time, or it can be added upon first encountering the certificate or public key. The former - adding at development time - is preferred since ''preloading'' the certificate or public key ''out of band'' usually means the attacker cannot taint the pin. If the certificate or public key is added upon first encounter, you will be using ''key continuity''. Key continuity can fail if the attacker has a privileged position during the first first encounter.&lt;br /&gt;
&lt;br /&gt;
Pinning leverages knowledge of the pre-existing relationship between the user and an organization or service to help make better security related decisions. Because you already have information on the server or service, you don't need to rely on generalized mechanisms meant to solve the ''key distribution'' problem. That is, you don't need to turn to DNS for name/address mappings or CAs for bindings and status. Once exception is revocation and it is discussed below in [[#Pinning_Gaps|Pinning Gaps]].&lt;br /&gt;
&lt;br /&gt;
It is also worth mention that Pinning is not Stapling. Stapling sends both the certificate and  OCSP responder information in the same request to avoid the additional fetches the client should perform during path validations.&lt;br /&gt;
&lt;br /&gt;
=== When Do You Pin? ===&lt;br /&gt;
&lt;br /&gt;
You should pin anytime you want to be relatively certain of the remote host's identity or when operating in a hostile environment. Since one or both are almost always true, you should probably pin all the time.&lt;br /&gt;
&lt;br /&gt;
A perfect case in point: during the two weeks or so of preparation for the presentation and cheat sheet, we've observed three relevant and related failures. First was [http://gaurangkp.wordpress.com/2013/01/09/nokia-https-mitm/ Nokia/Opera willfully breaking the secure channel]; second was [http://blog.malwarebytes.org/intelligence/2013/02/digital-certificates-and-malware-a-dangerous-mix/ DigiCert issuing a code signing certificate for malware]; and third was [http://krebsonsecurity.com/2013/02/security-firm-bit9-hacked-used-to-spread-malware/ Bit9's loss of its root signing key]. The environment is not only hostile, its toxic.&lt;br /&gt;
&lt;br /&gt;
=== When Do You Whitelist? ===&lt;br /&gt;
&lt;br /&gt;
If you are working for an organization which practices &amp;quot;egress filtering&amp;quot; as part of a Data Loss Prevention (DLP) strategy, you will likely encounter ''Interception Proxies''. I like to refer to these things as '''&amp;quot;good&amp;quot; bad guys''' (as opposed to '''&amp;quot;bad&amp;quot; bad guys''') since both break end-to-end security and we can't tell them apart. In this case, '''do not''' offer to whitelist the interception proxy since it defeats your security goals. Add the interception proxy's public key to your pinset after being '''instructed''' to do so by the folks in Risk Acceptance.&lt;br /&gt;
&lt;br /&gt;
Note: if you whitelist a certificate or public key for a different host (for example, to accommodate an interception proxy), you are no longer pinning the expected certificates and keys for the host. Security and integrity on the channel could suffer, and it surely breaks end-to-end security expectations of users and organizations.&lt;br /&gt;
&lt;br /&gt;
For more reading on interception proxies, the additional risk they bestow, and how they fail, see Dr. Matthew Green's ''[http://blog.cryptographyengineering.com/2012/03/how-do-interception-proxies-fail.html How do Interception Proxies fail?]'' and Jeff Jarmoc's BlackHat talk ''[https://www.blackhat.com/html/bh-eu-12/bh-eu-12-archives.html#jarmoc SSL/TLS Interception Proxies and Transitive Trust]''.&lt;br /&gt;
&lt;br /&gt;
=== How Do You Pin? ===&lt;br /&gt;
&lt;br /&gt;
The idea is to re-use the exiting protocols and infrastructure, but use them in a hardened manner. For re-use, a program would keep doing the things it used to do when establishing a secure connection.&lt;br /&gt;
&lt;br /&gt;
To harden the channel, the program would take advantage of the &amp;lt;tt&amp;gt;OnConnect&amp;lt;/tt&amp;gt; callback offered by a library, framework or platform. In the callback, the program would verify the remote host's identity by validating its certificate or public key. While pinning does not have to occur in an &amp;lt;tt&amp;gt;OnConnect&amp;lt;/tt&amp;gt; callback, its often most convenient because the underlying connection information is readily available.&lt;br /&gt;
&lt;br /&gt;
== What Should Be Pinned? ==&lt;br /&gt;
&lt;br /&gt;
The first thing to decide is what should be pinned. For this choice, you have two options: you can (1) pin  the certificate; or (2) pin the public key. If you choose public keys, you have two additional choices: (a) pin the &amp;lt;tt&amp;gt;subjectPublicKeyInfo&amp;lt;/tt&amp;gt;; or (b) pin one of the concrete types such as &amp;lt;tt&amp;gt;RSAPublicKey&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;DSAPublicKey&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The three choices are explained below in more detail. I would encourage you to pin the &amp;lt;tt&amp;gt;subjectPublicKeyInfo&amp;lt;/tt&amp;gt; because it has the public parameters (such as &amp;lt;tt&amp;gt;{e,n}&amp;lt;/tt&amp;gt; for an RSA public key) '''and''' contextual information such as an algorithm and OID. The context will help you keep your bearings at times, and Figure 1 below shows the additional information available.&lt;br /&gt;
&lt;br /&gt;
=== Encodings/Formats ===&lt;br /&gt;
&lt;br /&gt;
For the purposes of this article, the objects are in X509-compatible presentation format (PKCS#1 defers to X509, both of which use ASN.1). If you have a PEM encoded object (for example, &amp;lt;tt&amp;gt;-----BEGIN CERTIFICATE-----&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;-----END CERTIFICATE-----&amp;lt;/tt&amp;gt;), then convert the object to DER encoding. Conversion using OpenSSL is offered below in [[#Format_Conversions|Format Conversions]].&lt;br /&gt;
&lt;br /&gt;
A certificate is an object which binds an entity (such as a person or organization) to a public key via a signature. The certificate is DER encoded, and has associated data or attributes such as ''Subject'' (who is identified or bound), ''Issuer'' (who signed it), ''Validity'' (''NotBefore'' and ''NotAfter''), and a ''Public Key''.&lt;br /&gt;
&lt;br /&gt;
A certificate has a ''subjectPublicKeyInfo''. The subjectPublicKeyInfo is a key with additional information. The ASN.1 type includes an ''Algorithm ID'', a ''Version'', and an extensible format to hold a concrete public key. Figures 1 and 2 below show different views of the same RSA key, which is the subjectPublicKeyInfo. The key is for the site [https://www.random.org random.org], and it is used in the sample programs and listings below.&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;center&amp;quot;&lt;br /&gt;
| [[File:random-org-der-dump.png|thumb|375px|Figure 1: subjectPublicKeyInfo dumped with dumpans1]]&lt;br /&gt;
| [[File:random-org-der-hex.png|thumb|375px|Figure 2: subjectPublicKeyInfo under a hex editor]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The concrete public key is an encoded public key. The key format will usually be specified elsewhere - for example, PKCS#1 in the case of RSA Public Keys. In the case of an RSA public key, the type is ''RSAPublicKey'' and the parameters &amp;lt;tt&amp;gt;{e,n}&amp;lt;/tt&amp;gt; will be ASN.1 encoded. Figures 1 and 2 above clearly show the modulus (''n'' at line 28) and exponent (''e'' at line 289). For DSA, the concrete type is DSAPublicKey and the ASN.1 encoded parameters would be &amp;lt;tt&amp;gt;{p,q,g,y}&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Final takeaways: (1) a certificate binds an entity to a public key; (2) a certificate has a subjectPublicKeyInfo; and (3) a subjectPublicKeyInfo has an concrete public key. For those who want to learn more, a more in-depth discussion from a programmer's perspective can be found at the Code Project's article ''[http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys Cryptographic Interoperability: Keys]''.&lt;br /&gt;
&lt;br /&gt;
=== Certificate ===&lt;br /&gt;
&lt;br /&gt;
[[File:pin-cert.png|thumb|right|100px|Certificate]] The certificate is easiest to pin. You can fetch the certificate out of band for the website, have the IT folks email your company certificate to you, use &amp;lt;tt&amp;gt;openssl s_client&amp;lt;/tt&amp;gt; to retrieve the certificate etc. When the certificate expires, you would update your application. Assuming your application has no bugs or security defects, the application would be updated every year or two.&lt;br /&gt;
&lt;br /&gt;
At runtime, you retrieve the website or server's certificate in the callback. Within the callback, you compare the retrieved certificate with the certificate embedded within the program. If the comparison fails, then fail the method or function. &lt;br /&gt;
&lt;br /&gt;
There is a downside to pinning a certificate. If the site rotates its certificate on a regular basis, then your application would need to be updated regularly. For example, Google rotates its certificates, so you will need to update your application about once a month (if it depended on Google services). Even though Google rotates its certificates, the underlying public keys (within the certificate) remain static.&lt;br /&gt;
&lt;br /&gt;
=== Public Key ===&lt;br /&gt;
&lt;br /&gt;
[[File:pin-pubkey.png|thumb|right|100px|Public Key]] Public key pinning is more flexible but a little trickier due to the extra steps necessary to extract the public key from a certificate. As with a certificate, the program checks the extracted public key with its embedded copy of the public key.&lt;br /&gt;
&lt;br /&gt;
There are two downsides two public key pinning. First, its harder to work with keys (versus certificates) since you usually must extract the key from the certificate. Extraction is a minor inconvenience in Java and .Net, buts its uncomfortable in Cocoa/CocoaTouch and OpenSSL. Second, the key is static and may violate key rotation policies.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
&lt;br /&gt;
While the three choices above used DER encoding, its also acceptable to use a hash of the information (or other transforms). In fact, the original sample programs were written using digested certificates and public keys. The samples were changed to allow a programmer to inspect the objects with tools like &amp;lt;tt&amp;gt;dumpasn1&amp;lt;/tt&amp;gt; and other ASN.1 decoders.&lt;br /&gt;
&lt;br /&gt;
Hashing also provides three additional benefits. First, hashing allows you to anonymize a certificate or public key. This might be important if you application is concerned about leaking information during decompilation and re-engineering.&lt;br /&gt;
&lt;br /&gt;
Second, a digested certificate fingerprint is often available as a native API for many libraries, so its convenient to use.&lt;br /&gt;
&lt;br /&gt;
Finally, an organization might want to supply a reserve (or back-up) identity in case the primary identity is compromised. Hashing ensures your adversaries do not see the reserved certificate or public key in advance of its use. In fact, Google's IETF draft ''websec-key-pinning'' uses the technique.&lt;br /&gt;
&lt;br /&gt;
== What About X509? ==&lt;br /&gt;
&lt;br /&gt;
PKI{X} and the Internet form an intersection. What Internet users expect and what they receive from CAs could vary wildly. For example, an Internet user has security goals, while a CA has revenue goals and legal goals. Many are surprised to learn that the user is often required to perform host identity verification even though the CA issued the certificate (the details are buried in CA warranties on their certificates and their Certification Practice Statement (CPS)).&lt;br /&gt;
&lt;br /&gt;
There are a number of PKI profiles available. For the Internet, &amp;quot;Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL)&amp;quot;, also known as [http://tools.ietf.org/rfc/rfc5280.txt RFC 5280], is of interest. Since a certificate is specified in the ITU's X509 standard, there are lots of mandatory and optional fields available for validation from both bodies. Because of the disjoint goals among groups, the next section provides guidance.&lt;br /&gt;
&lt;br /&gt;
=== Mandatory Checks ===&lt;br /&gt;
&lt;br /&gt;
All X509 verifications must include:&lt;br /&gt;
&lt;br /&gt;
* A path validation check. The check verifies all the signatures on certificates in the chain are valid under a given PKI. The check begins at the server or service's certificate (the leaf), and proceeds back to a trusted root certificate (the root).&lt;br /&gt;
&lt;br /&gt;
* A validity check, or the &amp;lt;tt&amp;gt;notBefore&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;notAfter&amp;lt;/tt&amp;gt; fields. The &amp;lt;tt&amp;gt;notAfter&amp;lt;/tt&amp;gt; field is especially important since a CA will not warrant the certificate after the date, and it does not have to provide CRL/OCSP updates after the date.&lt;br /&gt;
&lt;br /&gt;
* Revocation status. As with &amp;lt;tt&amp;gt;notAfter&amp;lt;/tt&amp;gt;, revocation is important because the CA will not warrant a certificate once it is listed as revoked. The IETF approved way of checking a certificate's revocation is OCSP and specified in [http://tools.ietf.org/rfc/rfc2560.txt RFC 2560].&lt;br /&gt;
&lt;br /&gt;
=== Optional Checks ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;[Mulling over what else to present, and the best way to present it. Subject name? DNS lookups? Key Usage? Algorithms? Geolocation based on IP? Check back soon.]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
In the model which pre-dated PKIX RFC-5280, X.509v1 there was strong binding of the certificate Subject name to the X.500 Directory.  With the update to X.509v3, the Directory is  still the standard for authentication of caCertificate attributes, versus accepting a self signed root. Geo-location is important, the fake certificate for Google was given a location of Florida, instead of Mountain View, CA. The binding of the certificate to the Directory can anchor the root caCertificate, in effect &amp;quot;pin&amp;quot; it, to a valid entity that can have demonstrable attributes such as location.  This is detailed in RFC-1255.  Additional fields specified, such as the subject alternative field, for example a RFC-822 email address, or DNS name, can be located in the DNS, but the actual heavy lifting is done by the X.500 Directory, which is used currently as a cross-certificate trust conduit at the Federal Bridge between major communities of interest, that are not Internet focused. While those cross-certificates are valuable in validation between trust communities, a self-signed root, still needs to be either pinned, curated in trust bundle such as in  web browser software secure storage or represented by a federated community. The Directory can play a role to fill in gaps to validate caCertificates, either locally, or nationally under an administrative domain such as c=US. By divorcing the subject from the Directory entry, problems begin to arise in which pinning plays a key role to ensure that client and server have the same reference points.&lt;br /&gt;
&lt;br /&gt;
=== Public Key Checks ===&lt;br /&gt;
&lt;br /&gt;
''Quod vide'' (''q.v.''). Verifying the identity of a host with knowledge of its associated/expected public key is pinning.&lt;br /&gt;
&lt;br /&gt;
== Examples of Pinning ==&lt;br /&gt;
&lt;br /&gt;
This section demonstrates certificate and public key pinning in Android Java, iOS, .Net, and OpenSSL. All programs attempt to connect to [https://www.random.org random.org] and fetch bytes (Dr. Mads Haahr participates in AOSP's pinning program, so the site should have a static key). The programs enjoy a pre-existing relationship with the site (more correctly, ''a priori'' knowledge), so they include a copy of the site's public key and pin the identity on the key.&lt;br /&gt;
&lt;br /&gt;
Parameter validation, return value checking, and error checking have been omitted in the code below, but is present in the sample programs. So the sample code is ready for copy/paste. By far, the most uncomfortable languages are C-based: iOS and OpenSSL.&lt;br /&gt;
&lt;br /&gt;
===HTTP pinning===&lt;br /&gt;
[http://www.rfc-editor.org/rfc/rfc7469.txt RFC 7469] introduced a new HTTP header that allows SSL servers to declare hashes of their certificates with time scope in which these certificates should not be changed. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
       Public-Key-Pins: max-age=2592000;&lt;br /&gt;
       pin-sha256=&amp;quot;E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=&amp;quot;;&lt;br /&gt;
       pin-sha256=&amp;quot;LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=&amp;quot;;&lt;br /&gt;
       report-uri=&amp;quot;http://example.com/pkp-report&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Android ===&lt;br /&gt;
&lt;br /&gt;
Pinning in Android is accomplished through a custom &amp;lt;tt&amp;gt;X509TrustManager&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;X509TrustManager&amp;lt;/tt&amp;gt; should perform the customary X509 checks in addition to performing the pin.&lt;br /&gt;
&lt;br /&gt;
Download: [[Media:pubkey-pin-android.zip|Android sample program]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public final class PubKeyManager implements X509TrustManager&lt;br /&gt;
{&lt;br /&gt;
  private static String PUB_KEY = &amp;quot;30820122300d06092a864886f70d0101&amp;quot; +&lt;br /&gt;
    &amp;quot;0105000382010f003082010a0282010100b35ea8adaf4cb6db86068a836f3c85&amp;quot; +&lt;br /&gt;
    &amp;quot;5a545b1f0cc8afb19e38213bac4d55c3f2f19df6dee82ead67f70a990131b6bc&amp;quot; +&lt;br /&gt;
    &amp;quot;ac1a9116acc883862f00593199df19ce027c8eaaae8e3121f7f329219464e657&amp;quot; +&lt;br /&gt;
    &amp;quot;2cbf66e8e229eac2992dd795c4f23df0fe72b6ceef457eba0b9029619e0395b8&amp;quot; +&lt;br /&gt;
    &amp;quot;609851849dd6214589a2ceba4f7a7dcceb7ab2a6b60c27c69317bd7ab2135f50&amp;quot; +&lt;br /&gt;
    &amp;quot;c6317e5dbfb9d1e55936e4109b7b911450c746fe0d5d07165b6b23ada7700b00&amp;quot; +&lt;br /&gt;
    &amp;quot;33238c858ad179a82459c4718019c111b4ef7be53e5972e06ca68a112406da38&amp;quot; +&lt;br /&gt;
    &amp;quot;cf60d2f4fda4d1cd52f1da9fd6104d91a34455cd7b328b02525320a35253147b&amp;quot; +&lt;br /&gt;
    &amp;quot;e0b7a5bc860966dc84f10d723ce7eed5430203010001&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException&lt;br /&gt;
  {&lt;br /&gt;
    if (chain == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;checkServerTrusted: X509Certificate array is null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    if (!(chain.length &amp;gt; 0)) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;checkServerTrusted: X509Certificate is empty&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    if (!(null != authType &amp;amp;&amp;amp; authType.equalsIgnoreCase(&amp;quot;RSA&amp;quot;))) {&lt;br /&gt;
      throw new CertificateException(&amp;quot;checkServerTrusted: AuthType is not RSA&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Perform customary SSL/TLS checks&lt;br /&gt;
    try {&lt;br /&gt;
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(&amp;quot;X509&amp;quot;);&lt;br /&gt;
      tmf.init((KeyStore) null);&lt;br /&gt;
      &lt;br /&gt;
      for (TrustManager trustManager : tmf.getTrustManagers()) {&lt;br /&gt;
        ((X509TrustManager) trustManager).checkServerTrusted(chain, authType);&lt;br /&gt;
      }&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      throw new CertificateException(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Hack ahead: BigInteger and toString(). We know a DER encoded Public Key begins&lt;br /&gt;
    // with 0x30 (ASN.1 SEQUENCE and CONSTRUCTED), so there is no leading 0x00 to drop.&lt;br /&gt;
    RSAPublicKey pubkey = (RSAPublicKey) chain[0].getPublicKey();&lt;br /&gt;
    String encoded = new BigInteger(1 /* positive */, pubkey.getEncoded()).toString(16);&lt;br /&gt;
&lt;br /&gt;
    // Pin it!&lt;br /&gt;
    final boolean expected = PUB_KEY.equalsIgnoreCase(encoded);&lt;br /&gt;
    if (!expected) {&lt;br /&gt;
      throw new CertificateException(&amp;quot;checkServerTrusted: Expected public key: &amp;quot;&lt;br /&gt;
                + PUB_KEY + &amp;quot;, got public key:&amp;quot; + encoded);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PubKeyManager&amp;lt;/tt&amp;gt; would be used in code similar to below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;TrustManager tm[] = { new PubKeyManager() };&lt;br /&gt;
&lt;br /&gt;
SSLContext context = SSLContext.getInstance(&amp;quot;TLS&amp;quot;);&lt;br /&gt;
context.init(null, tm, null);&lt;br /&gt;
&lt;br /&gt;
URL url = new URL( &amp;quot;https://www.random.org/integers/?&amp;quot; +&lt;br /&gt;
                   &amp;quot;num=16&amp;amp;min=0&amp;amp;max=255&amp;amp;col=16&amp;amp;base=10&amp;amp;format=plain&amp;amp;rnd=new&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();&lt;br /&gt;
connection.setSSLSocketFactory(context.getSocketFactory());&lt;br /&gt;
&lt;br /&gt;
InputStreamReader instream = new InputStreamReader(connection.getInputStream());&lt;br /&gt;
StreamTokenizer tokenizer = new StreamTokenizer(instream);&lt;br /&gt;
...&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== iOS ===&lt;br /&gt;
&lt;br /&gt;
iOS pinning is performed through a &amp;lt;tt&amp;gt;NSURLConnectionDelegate&amp;lt;/tt&amp;gt;. The delegate must implement &amp;lt;tt&amp;gt;connection:canAuthenticateAgainstProtectionSpace:&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;connection:didReceiveAuthenticationChallenge:&amp;lt;/tt&amp;gt;. Within &amp;lt;tt&amp;gt;connection:didReceiveAuthenticationChallenge:&amp;lt;/tt&amp;gt;, the delegate must call &amp;lt;tt&amp;gt;SecTrustEvaluate&amp;lt;/tt&amp;gt; to perform customary X509 checks.&lt;br /&gt;
&lt;br /&gt;
Download: [[Media:pubkey-pin-ios.zip|iOS sample program]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-(IBAction)fetchButtonTapped:(id)sender&lt;br /&gt;
{&lt;br /&gt;
    NSString* requestString = @&amp;quot;https://www.random.org/integers/?&lt;br /&gt;
        num=16&amp;amp;min=0&amp;amp;max=255&amp;amp;col=16&amp;amp;base=16&amp;amp;format=plain&amp;amp;rnd=new&amp;quot;;&lt;br /&gt;
    NSURL* requestUrl = [NSURL URLWithString:requestString];&lt;br /&gt;
&lt;br /&gt;
    NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl&lt;br /&gt;
                                             cachePolicy:NSURLRequestReloadIgnoringLocalCacheData&lt;br /&gt;
                                         timeoutInterval:10.0f];&lt;br /&gt;
&lt;br /&gt;
    NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:&lt;br /&gt;
                  (NSURLProtectionSpace*)space&lt;br /&gt;
{&lt;br /&gt;
    return [[space authenticationMethod] isEqualToString: NSURLAuthenticationMethodServerTrust];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:&lt;br /&gt;
                   (NSURLAuthenticationChallenge *)challenge&lt;br /&gt;
{&lt;br /&gt;
  if ([[[challenge protectionSpace] authenticationMethod] isEqualToString: NSURLAuthenticationMethodServerTrust])&lt;br /&gt;
  {&lt;br /&gt;
    do&lt;br /&gt;
    {&lt;br /&gt;
      SecTrustRef serverTrust = [[challenge protectionSpace] serverTrust];&lt;br /&gt;
      if(nil == serverTrust)&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      OSStatus status = SecTrustEvaluate(serverTrust, NULL);&lt;br /&gt;
      if(!(errSecSuccess == status))&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      SecCertificateRef serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0);&lt;br /&gt;
      if(nil == serverCertificate)&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      CFDataRef serverCertificateData = SecCertificateCopyData(serverCertificate);&lt;br /&gt;
      [(id)serverCertificateData autorelease];&lt;br /&gt;
      if(nil == serverCertificateData)&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      const UInt8* const data = CFDataGetBytePtr(serverCertificateData);&lt;br /&gt;
      const CFIndex size = CFDataGetLength(serverCertificateData);&lt;br /&gt;
      NSData* cert1 = [NSData dataWithBytes:data length:(NSUInteger)size];&lt;br /&gt;
&lt;br /&gt;
      NSString *file = [[NSBundle mainBundle] pathForResource:@&amp;quot;random-org&amp;quot; ofType:@&amp;quot;der&amp;quot;];&lt;br /&gt;
      NSData* cert2 = [NSData dataWithContentsOfFile:file];&lt;br /&gt;
&lt;br /&gt;
      if(nil == cert1 || nil == cert2)&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      const BOOL equal = [cert1 isEqualToData:cert2];&lt;br /&gt;
      if(!equal)&lt;br /&gt;
        break; /* failed */&lt;br /&gt;
&lt;br /&gt;
      // The only good exit point&lt;br /&gt;
      return [[challenge sender] useCredential: [NSURLCredential credentialForTrust: serverTrust]&lt;br /&gt;
                    forAuthenticationChallenge: challenge];&lt;br /&gt;
    } while(0);&lt;br /&gt;
&lt;br /&gt;
    // Bad dog&lt;br /&gt;
    return [[challenge sender] cancelAuthenticationChallenge: challenge];&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .Net ===&lt;br /&gt;
&lt;br /&gt;
.Net pinning can be achieved by using &amp;lt;tt&amp;gt;ServicePointManager&amp;lt;/tt&amp;gt; as shown below.&lt;br /&gt;
&lt;br /&gt;
Download: [[Media:pubkey-pin-dotnet.zip|.Net sample program]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;// Encoded RSAPublicKey&lt;br /&gt;
private static String PUB_KEY = &amp;quot;30818902818100C4A06B7B52F8D17DC1CCB47362&amp;quot; +&lt;br /&gt;
    &amp;quot;C64AB799AAE19E245A7559E9CEEC7D8AA4DF07CB0B21FDFD763C63A313A668FE9D764E&amp;quot; +&lt;br /&gt;
    &amp;quot;D913C51A676788DB62AF624F422C2F112C1316922AA5D37823CD9F43D1FC54513D14B2&amp;quot; +&lt;br /&gt;
    &amp;quot;9E36991F08A042C42EAAEEE5FE8E2CB10167174A359CEBF6FACC2C9CA933AD403137EE&amp;quot; +&lt;br /&gt;
    &amp;quot;2C3F4CBED9460129C72B0203010001&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
public static void Main(string[] args)&lt;br /&gt;
{&lt;br /&gt;
  ServicePointManager.ServerCertificateValidationCallback = PinPublicKey;&lt;br /&gt;
  WebRequest wr = WebRequest.Create(&amp;quot;https://encrypted.google.com/&amp;quot;);&lt;br /&gt;
  wr.GetResponse();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static bool PinPublicKey(object sender, X509Certificate certificate, X509Chain chain,&lt;br /&gt;
                                SslPolicyErrors sslPolicyErrors)&lt;br /&gt;
{&lt;br /&gt;
  if (null == certificate)&lt;br /&gt;
    return false;&lt;br /&gt;
&lt;br /&gt;
  String pk = certificate.GetPublicKeyString();&lt;br /&gt;
  if (pk.Equals(PUB_KEY))&lt;br /&gt;
    return true;&lt;br /&gt;
&lt;br /&gt;
  // Bad dog&lt;br /&gt;
  return false;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OpenSSL ===&lt;br /&gt;
&lt;br /&gt;
Pinning can occur at one of two places with OpenSSL. First is the user supplied &amp;lt;tt&amp;gt;verify_callback&amp;lt;/tt&amp;gt;. Second is after the connection is established via &amp;lt;tt&amp;gt;SSL_get_peer_certificate&amp;lt;/tt&amp;gt;. Either method will allow you to access the peer's certificate.&lt;br /&gt;
&lt;br /&gt;
Though OpenSSL performs the X509 checks, you must fail the connection and tear down the socket on error. By design, a server that does not supply a certificate will result in &amp;lt;tt&amp;gt;X509_V_OK&amp;lt;/tt&amp;gt; with a '''NULL''' certificate. To check the result of the customary verification: (1) you must call &amp;lt;tt&amp;gt;SSL_get_verify_result&amp;lt;/tt&amp;gt; and verify the return code is &amp;lt;tt&amp;gt;X509_V_OK&amp;lt;/tt&amp;gt;; and (2) you must call &amp;lt;tt&amp;gt;SSL_get_peer_certificate&amp;lt;/tt&amp;gt; and verify the certificate is '''non-NULL'''.&lt;br /&gt;
&lt;br /&gt;
Download: [[Media:pubkey-pin-openssl.zip|OpenSSL sample program]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;int pkp_pin_peer_pubkey(SSL* ssl)&lt;br /&gt;
{&lt;br /&gt;
    if(NULL == ssl) return FALSE;&lt;br /&gt;
    &lt;br /&gt;
    X509* cert = NULL;&lt;br /&gt;
    FILE* fp = NULL;&lt;br /&gt;
    &lt;br /&gt;
    /* Scratch */&lt;br /&gt;
    int len1 = 0, len2 = 0;&lt;br /&gt;
    unsigned char *buff1 = NULL, *buff2 = NULL;&lt;br /&gt;
    &lt;br /&gt;
    /* Result is returned to caller */&lt;br /&gt;
    int ret = 0, result = FALSE;&lt;br /&gt;
    &lt;br /&gt;
    do&lt;br /&gt;
    {&lt;br /&gt;
        /* http://www.openssl.org/docs/ssl/SSL_get_peer_certificate.html */&lt;br /&gt;
        cert = SSL_get_peer_certificate(ssl);&lt;br /&gt;
        if(!(cert != NULL))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Begin Gyrations to get the subjectPublicKeyInfo       */&lt;br /&gt;
        /* Thanks to Viktor Dukhovni on the OpenSSL mailing list */&lt;br /&gt;
        &lt;br /&gt;
        /* http://groups.google.com/group/mailing.openssl.users/browse_thread/thread/d61858dae102c6c7 */&lt;br /&gt;
        len1 = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(cert), NULL);&lt;br /&gt;
        if(!(len1 &amp;gt; 0))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* scratch */&lt;br /&gt;
        unsigned char* temp = NULL;&lt;br /&gt;
        &lt;br /&gt;
        /* http://www.openssl.org/docs/crypto/buffer.html */&lt;br /&gt;
        buff1 = temp = OPENSSL_malloc(len1);&lt;br /&gt;
        if(!(buff1 != NULL))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* http://www.openssl.org/docs/crypto/d2i_X509.html */&lt;br /&gt;
        len2 = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(cert), &amp;amp;temp);&lt;br /&gt;
&lt;br /&gt;
        /* These checks are verifying we got back the same values as when we sized the buffer.      */&lt;br /&gt;
        /* Its pretty weak since they should always be the same. But it gives us something to test. */&lt;br /&gt;
        if(!((len1 == len2) &amp;amp;&amp;amp; (temp != NULL) &amp;amp;&amp;amp; ((temp - buff1) == len1)))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* End Gyrations */&lt;br /&gt;
        &lt;br /&gt;
        /* See the warning above!!!                                            */&lt;br /&gt;
        /* http://pubs.opengroup.org/onlinepubs/009696699/functions/fopen.html */&lt;br /&gt;
        fp = fopen(&amp;quot;random-org.der&amp;quot;, &amp;quot;rx&amp;quot;);&lt;br /&gt;
        if(NULL ==fp) {&lt;br /&gt;
            fp = fopen(&amp;quot;random-org.der&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
        &lt;br /&gt;
        if(!(NULL != fp))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Seek to eof to determine the file's size                            */&lt;br /&gt;
        /* http://pubs.opengroup.org/onlinepubs/009696699/functions/fseek.html */&lt;br /&gt;
        ret = fseek(fp, 0, SEEK_END);&lt;br /&gt;
        if(!(0 == ret))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Fetch the file's size                                               */&lt;br /&gt;
        /* http://pubs.opengroup.org/onlinepubs/009696699/functions/ftell.html */&lt;br /&gt;
        long size = ftell(fp);&lt;br /&gt;
&lt;br /&gt;
        /* Arbitrary size, but should be relatively small (less than 1K or 2K) */&lt;br /&gt;
        if(!(size != -1 &amp;amp;&amp;amp; size &amp;gt; 0 &amp;amp;&amp;amp; size &amp;lt; 2048))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Rewind to beginning to perform the read                             */&lt;br /&gt;
        /* http://pubs.opengroup.org/onlinepubs/009696699/functions/fseek.html */&lt;br /&gt;
        ret = fseek(fp, 0, SEEK_SET);&lt;br /&gt;
        if(!(0 == ret))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Re-use buff2 and len2 */&lt;br /&gt;
        buff2 = NULL; len2 = (int)size;&lt;br /&gt;
        &lt;br /&gt;
        /* http://www.openssl.org/docs/crypto/buffer.html */&lt;br /&gt;
        buff2 = OPENSSL_malloc(len2);&lt;br /&gt;
        if(!(buff2 != NULL))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* http://pubs.opengroup.org/onlinepubs/009696699/functions/fread.html */&lt;br /&gt;
        /* Returns number of elements read, which should be 1 */&lt;br /&gt;
        ret = (int)fread(buff2, (size_t)len2, 1, fp);&lt;br /&gt;
        if(!(ret == 1))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* Re-use size. MIN and MAX macro below... */&lt;br /&gt;
        size = len1 &amp;lt; len2 ? len1 : len2;&lt;br /&gt;
        &lt;br /&gt;
        /*************************/&lt;br /&gt;
        /*****    PAYDIRT    *****/&lt;br /&gt;
        /*************************/&lt;br /&gt;
        if(len1 != (int)size || len2 != (int)size || 0 != memcmp(buff1, buff2, (size_t)size))&lt;br /&gt;
            break; /* failed */&lt;br /&gt;
        &lt;br /&gt;
        /* The one good exit point */&lt;br /&gt;
        result = TRUE;&lt;br /&gt;
        &lt;br /&gt;
    } while(0);&lt;br /&gt;
    &lt;br /&gt;
    if(fp != NULL)&lt;br /&gt;
        fclose(fp);&lt;br /&gt;
    &lt;br /&gt;
    /* http://www.openssl.org/docs/crypto/buffer.html */&lt;br /&gt;
    if(NULL != buff2)&lt;br /&gt;
        OPENSSL_free(buff2);&lt;br /&gt;
    &lt;br /&gt;
    /* http://www.openssl.org/docs/crypto/buffer.html */&lt;br /&gt;
    if(NULL != buff1)&lt;br /&gt;
        OPENSSL_free(buff1);&lt;br /&gt;
    &lt;br /&gt;
    /* http://www.openssl.org/docs/crypto/X509_new.html */&lt;br /&gt;
    if(NULL != cert)&lt;br /&gt;
        X509_free(cert);&lt;br /&gt;
    &lt;br /&gt;
    return result;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pinning Alternatives ==&lt;br /&gt;
&lt;br /&gt;
Not all applications use split key cryptography. Fortunately, there are protocols which allow you to set up a secure channel based on knowledge of passwords and pre-shared secrets (rather than putting the secret on the wire in a basic authentication scheme). Two are listed below - SRP and PSK. SRP and PSK have [http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-3 88 cipher suites assigned to them by IANA for TLS], so there's no shortage of choices.&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;center&amp;quot;&lt;br /&gt;
| [[File:pin-iana-assigned.png|thumb|450px|Figure 3: IANA reserved cipher suites for SRP and PSK]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== SRP ===&lt;br /&gt;
&lt;br /&gt;
Secure Remote Password (SRP) is a Password Authenticated Key Exchange (PAKE) by Thomas Wu based upon Diffie-Hellman. The protocol is standardized in [https://tools.ietf.org/rfc/rfc5054.txt RFC 5054] and available in the OpenSSL library (among others). In the SRP scheme, the server uses a verifier which consists of a &amp;lt;tt&amp;gt;{salt, hash(password)}&amp;lt;/tt&amp;gt; pair. The user has the password and receives the salt from the server. With lots of hand waving, both parties select per-instance random values (nonces) and execute the protocol using ''g&amp;lt;sup&amp;gt;{(salt + password)|verifier} + nonces&amp;lt;/sup&amp;gt;'' rather than traditional Diffie-Hellman using ''g&amp;lt;sup&amp;gt;ab&amp;lt;/sup&amp;gt;''.&lt;br /&gt;
&lt;br /&gt;
[[File:homer-p-np.jpg|thumb|right|150px|P=NP!!!]]Diffie-Hellman based schemes are part of a family of problems based on Discrete Logs (DL), which are logarithms over a finite field. DL schemes are appealing because they are known to be hard (unless ''P=NP'', which would cause computational number theorists to have a cow).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== PSK ===&lt;br /&gt;
&lt;br /&gt;
PSK is Pre-Shared Key and specified in [https://tools.ietf.org/rfc/rfc4279.txt RFC 4279] and [https://tools.ietf.org/rfc/rfc4764.txt RFC 4764]. The shared secret is used as a pre-master secret in TLS-PSK for SSL/TLS; or used to key a block cipher in EAP-PSK. EAP-PSK is designed for authentication over insecure networks such as IEEE 802.11.&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
This sections covers administrivia and miscellaneous items related to pinning.&lt;br /&gt;
&lt;br /&gt;
=== Ephemeral Keys ===&lt;br /&gt;
&lt;br /&gt;
Ephemeral keys are temporary keys used for one instance of a protocol execution and then thrown away. An ephemeral key has the benefit of providing forward secrecy, meaning a compromise of the site or service's long term (static) signing key does not facilitate decrypting past messages because the key was temporary and discarded (once the session terminated).&lt;br /&gt;
&lt;br /&gt;
Ephemeral keys do not affect pinning because the Ephemeral key is delivered in a separate &amp;lt;tt&amp;gt;ServerKeyExchange&amp;lt;/tt&amp;gt; message. In addition, the ephemeral key is a key and not a certificate, so it does not change the construction of the certificate chain. That is, the certificate of interest will still be located at &amp;lt;tt&amp;gt;certificates[0]&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Pinning Gaps ===&lt;br /&gt;
&lt;br /&gt;
There are two gaps when pinning due to reuse of the existing infrastructure and protocols. First, an explicit challenge is '''not''' sent by the program to the peer server based on the server's public information. So the program never knows if the peer can actually decrypt messages. However, the shortcoming is usually academic in practice since an adversary will receive messages it can't decrypt.&lt;br /&gt;
&lt;br /&gt;
Second is revocation. Clients don't usually engage in revocation checking, so it could be possible to use a known bad certificate or key in a pinset. Even if revocation is active, Certificate Revocation Lists (CRLs) and Online Certificate Status Protocol (OCSP) can be defeated in a hostile environment. An application can take steps to remediate, with the primary means being freshness. That is, an application should be updated and distributed immediately when a critical security parameter changes.&lt;br /&gt;
&lt;br /&gt;
=== No Relationship ^@$! ===&lt;br /&gt;
&lt;br /&gt;
If you don't have a pre-existing relationship, all is not lost. First, you can pin a host or server's certificate or public key the first time you encounter it. If the bad guy was not active when you encountered the certificate or public key, he or she will not be successful with future funny business.&lt;br /&gt;
&lt;br /&gt;
Second, bad certificates are being spotted quicker in the field due to projects like [http://www.chromium.org Chromium] and [https://addons.mozilla.org/en-us/firefox/addon/certificate-patrol/ Certificate Patrol], and initiatives like the EFF's [https://www.eff.org/observatory SSL Observatory].&lt;br /&gt;
&lt;br /&gt;
Third, help is on its way, and there are a number of futures that will assist with the endeavors:&lt;br /&gt;
&lt;br /&gt;
* Public Key Pinning (http://www.ietf.org/id/draft-ietf-websec-key-pinning-09.txt) – an extension to the HTTP protocol allowing web host operators to instruct user agents (UAs) to remember (&amp;quot;pin&amp;quot;) the hosts' cryptographic identities for a given period of time.&lt;br /&gt;
* DNS-based Authentication of Named Entities (DANE) (https://datatracker.ietf.org/doc/rfc6698/) - uses Secure DNS to associate Certificates with Domain Names For S/MIME, SMTP with TLS, DNSSEC and TLSA records.&lt;br /&gt;
* Sovereign Keys (http://www.eff.org/sovereign-keys) - operates by providing an optional and secure way of associating domain names with public keys via DNSSEC. PKI (hierarchical) is still used. Semi-centralized with append only logging.&lt;br /&gt;
* Convergence (http://convergence.io) – different [geographical] views of a site and its associated data (certificates and public keys). Web of Trust is used. Semi-centralized.&lt;br /&gt;
&lt;br /&gt;
While Sovereign Keys and Convergence still require us to confer trust to outside parties, the parties involved do not serve share holders or covet revenue streams. Their interests are industry transparency and user security.&lt;br /&gt;
&lt;br /&gt;
=== More Information? ===&lt;br /&gt;
&lt;br /&gt;
Pinning is an ''old new thing'' that has been shaken, stirred, and repackaged. While &amp;quot;pinning&amp;quot; and &amp;quot;pinsets&amp;quot; are relatively new terms for old things, Jon Larimer and Kenny Root spent time on the subject at Google I/O 2012 with their talk ''[https://developers.google.com/events/io/sessions/gooio2012/107/ Security and Privacy in Android Apps]''.&lt;br /&gt;
&lt;br /&gt;
=== Format Conversions ===&lt;br /&gt;
&lt;br /&gt;
As a convenience to readers, the following with convert between PEM and DER format using OpenSSL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Public key, X509&lt;br /&gt;
$ openssl genrsa -out rsa-openssl.pem 3072&lt;br /&gt;
$ openssl rsa -in rsa-openssl.pem -pubout -outform DER -out rsa-openssl.der&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Private key, PKCS#8&lt;br /&gt;
$ openssl genrsa -out rsa-openssl.pem 3072&lt;br /&gt;
$ openssl pkcs8 -nocrypt -in rsa-openssl.pem -inform PEM -topk8 -outform DER -out rsa-openssl.der&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* OWASP [[Injection_Theory|Injection Theory]]&lt;br /&gt;
* OWASP [[Data_Validation|Data Validation]]&lt;br /&gt;
* OWASP [[Transport_Layer_Protection_Cheat_Sheet|Transport Layer Protection Cheat Sheet]]&lt;br /&gt;
* IETF [http://www.ietf.org/id/draft-ietf-websec-key-pinning-09.txt Public Key Pinning]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc5054.txt RFC 5054 (SRP)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc4764.txt RFC 4764 (EAP-PSK)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc1421.txt RFC 1421 (PEM Encoding)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc5280.txt RFC 5280 (Internet X.509, PKIX)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc4648.txt RFC 4648 (Base16, Base32, and Base64 Encodings)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc3279.txt RFC 3279 (PKI, X509 Algorithms and CRL Profiles)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc4055.txt RFC 4055 (PKI, X509 Additional Algorithms and CRL Profiles)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc2246.txt RFC 2246 (TLS 1.0)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc4346.txt RFC 4346 (TLS 1.1)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc5246.txt RFC 5246 (TLS 1.2)]&lt;br /&gt;
* IETF [http://www.ietf.org/rfc/rfc6698.txt RFC 6698, Draft (DANE)]&lt;br /&gt;
* EFF [http://www.eff.org/sovereign-keys Sovereign Keys]&lt;br /&gt;
* Thoughtcrime Labs [http://convergence.io/ Convergence]&lt;br /&gt;
* RSA Laboratories [http://www.rsa.com/rsalabs/node.asp?id=2125 PKCS#1, RSA Encryption Standard]&lt;br /&gt;
* RSA Laboratories [http://www.rsa.com/rsalabs/node.asp?id=2128 PKCS#6, Extended-Certificate Syntax Standard]&lt;br /&gt;
* ITU [http://www.itu.int/rec/T-REC-X.690-200811-I/en Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)]&lt;br /&gt;
* TOR Project [https://blog.torproject.org/blog/detecting-certificate-authority-compromises-and-web-browser-collusion Detecting Certificate Authority Compromises and Web Browser Collusion]&lt;br /&gt;
* Code Project [http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys Cryptographic Interoperability: Keys]&lt;br /&gt;
* Google I/O [https://developers.google.com/events/io/sessions/gooio2012/107/ Security and Privacy in Android Apps]&lt;br /&gt;
* Trevor Perrin [https://crypto.stanford.edu/RealWorldCrypto/slides/perrin.pdf Transparency, Trust Agility, Pinning (Recent Developments in Server Authentication)]&lt;br /&gt;
* Dr. Peter Gutmann's [http://www.cs.auckland.ac.nz/~pgut001/pubs/pkitutorial.pdf PKI is Broken]&lt;br /&gt;
* Dr. Matthew Green's [http://blog.cryptographyengineering.com/2012/02/how-to-fix-internet.html The Internet is Broken]&lt;br /&gt;
* Dr. Matthew Green's [http://blog.cryptographyengineering.com/2012/03/how-do-interception-proxies-fail.html How do Interception Proxies fail?]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
* Jeffrey Walton - jeffrey, owasp.org&lt;br /&gt;
* JohnSteven - john, owasp.org&lt;br /&gt;
* Jim Manico - jim, owasp.org&lt;br /&gt;
* Kevin Wall - kevin, owasp.org&lt;br /&gt;
&lt;br /&gt;
[[Category:Control]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Upload_of_Malicious_Files_(OTG-BUSLOGIC-009)&amp;diff=192174</id>
		<title>Test Upload of Malicious Files (OTG-BUSLOGIC-009)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Upload_of_Malicious_Files_(OTG-BUSLOGIC-009)&amp;diff=192174"/>
				<updated>2015-03-25T15:40:10Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: /* How to Test */ EICAR anti-malware test file&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Many application’s business processes allow for the upload of data/information. We regularly check the validity and security of text but accepting files can introduce even more risk. To reduce the risk we may only accept certain file extensions, but attackers are able to encapsulate malicious code into inert file types. Testing for malicious files verifies that the application/system is able to correctly protect against attackers uploading malicious files.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vulnerabilities related to the uploading of malicious files is unique in that these “malicious” files can easily be rejected through including business logic that will scan files during the upload process and reject those perceived as malicious. Additionally, this is different from uploading unexpected files in that while the file type may be accepted the file may still be malicious to the system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, &amp;quot;malicious&amp;quot; means different things to different systems, for example Malicious files that may exploit SQL server vulnerabilities may not be considered a &amp;quot;malicious&amp;quot; to a main frame flat file environment.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The application may allow the upload of malicious files that include exploits or shellcode without submitting them to malicious file scanning. Malicious files could be detected and stopped at various points of the application architecture such as: IPS/IDS, application server anti-virus software or anti-virus scanning by application as files are uploaded (perhaps offloading the scanning using SCAP).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
Suppose a picture sharing application allows users to upload their .gif or .jpg graphic files to the web site. What if an attacker is able to upload a PHP shell, or exe file, or virus? The attacker may then upload the file that may be saved on the system and the virus may spread itself or through remote processes exes or shell code can be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test==&lt;br /&gt;
&lt;br /&gt;
Generic Testing Method&lt;br /&gt;
&lt;br /&gt;
• Review the project documentation and use exploratory testing looking at the application/system to identify what constitutes and &amp;quot;malicious&amp;quot; file in your environment. &lt;br /&gt;
&lt;br /&gt;
• Develop or acquire a known “malicious” file. An [http://www.eicar.org/85-0-Download.html EICAR anti-malware test file] can be used as harmless, but widely detected by antivirus software.&lt;br /&gt;
&lt;br /&gt;
• Try to upload the malicious file to the application/system and verify that it is correctly rejected.   &lt;br /&gt;
&lt;br /&gt;
• If multiple files can be uploaded at once, there must be tests in place to verify that each file is properly evaluated. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specific Testing Method 1&lt;br /&gt;
&lt;br /&gt;
•	Using the Metasploit payload generation functionality generates a shellcode as a Windows executable using the Metasploit &amp;quot;msfpayload&amp;quot; command.&lt;br /&gt;
&lt;br /&gt;
•	Submit the executable via the application’s upload functionality and see if it is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specific Testing Method 2&lt;br /&gt;
&lt;br /&gt;
•	Develop or create a file that should fail the application malware detection process. There are many available on the Internet such as ducklin.htm or ducklin-html.htm.  &lt;br /&gt;
&lt;br /&gt;
•	Submit the executable via the application’s upload functionality and see if it is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specific Testing Method 3&lt;br /&gt;
&lt;br /&gt;
•	Set up the intercepting proxy to capture the “valid” request for an accepted file.&lt;br /&gt;
&lt;br /&gt;
•	Send an “invalid” request through with a valid/acceptable file extension and see if the  request is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
== Related Test Cases ==&lt;br /&gt;
&lt;br /&gt;
[[Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003)| Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003) ]] &lt;br /&gt;
&lt;br /&gt;
[[Test Upload of Unexpected File Types (OTG-BUSLOGIC-008)| Test Upload of Unexpected File Types (OTG-BUSLOGIC-008)]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
• Metasploit's payload generation functionality &lt;br /&gt;
&lt;br /&gt;
• Intercepting proxy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==  &lt;br /&gt;
&lt;br /&gt;
OWASP - Unrestricted File Upload - https://www.owasp.org/index.php/Unrestricted_File_Upload&lt;br /&gt;
&lt;br /&gt;
Why File Upload Forms are a Major Security Threat - http://www.acunetix.com/websitesecurity/upload-forms-threat/&lt;br /&gt;
&lt;br /&gt;
File upload security best practices: Block a malicious file upload - http://www.computerweekly.com/answer/File-upload-security-best-practices-Block-a-malicious-file-upload&lt;br /&gt;
&lt;br /&gt;
Overview of Malicious File Upload Attacks - http://securitymecca.com/article/overview-of-malicious-file-upload-attacks/&lt;br /&gt;
&lt;br /&gt;
Stop people uploading malicious PHP files via forms - http://stackoverflow.com/questions/602539/stop-people-uploading-malicious-php-files-via-forms&lt;br /&gt;
&lt;br /&gt;
How to Tell if a File is Malicious - http://www.techsupportalert.com/content/how-tell-if-file-malicious.htm&lt;br /&gt;
&lt;br /&gt;
CWE-434: Unrestricted Upload of File with Dangerous Type - http://cwe.mitre.org/data/definitions/434.html&lt;br /&gt;
&lt;br /&gt;
Implementing Secure File Upload - http://infosecauditor.wordpress.com/tag/malicious-file-upload/&lt;br /&gt;
&lt;br /&gt;
Watchful File Upload - http://palizine.plynt.com/issues/2011Apr/file-upload/&lt;br /&gt;
&lt;br /&gt;
Matasploit Generating Payloads - http://www.offensive-security.com/metasploit-unleashed/Generating_Payloads&lt;br /&gt;
&lt;br /&gt;
Project Shellcode – Shellcode Tutorial 9: Generating Shellcode Using Metasploit&lt;br /&gt;
http://www.projectshellcode.com/?q=node/29&lt;br /&gt;
&lt;br /&gt;
Anti-Malware Test file - http://www.eicar.org/86-0-Intended-use.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Remediation ==&lt;br /&gt;
&lt;br /&gt;
While safeguards such as black or white listing of file extensions, using “Content-Type” from the header, or using a file type recognizer may not always be protections against this type of vulnerability. Every application that accepts files from users must have a mechanism to verify that the uploaded file does not contain malicious code. Uploaded files should never be stored where the users or attackers can directly access them.&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:OWASP_Speakers_Project&amp;diff=189214</id>
		<title>Category:OWASP Speakers Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:OWASP_Speakers_Project&amp;diff=189214"/>
				<updated>2015-02-09T13:40:29Z</updated>
		
		<summary type="html">&lt;p&gt;Pawel Krawczyk: Pawel Krawczyk&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Main=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:OWASP_Project_Header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
==OWASP Speakers Project==&lt;br /&gt;
&lt;br /&gt;
OWASP Speakers Project is...&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This program helps local chapters or application security conferences to find OWASP related speakers to have OWASP presenters on site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
This program allows two parties to find each other:&lt;br /&gt;
*Local chapters or application security events that want to attract an OWASP speaker.&lt;br /&gt;
*OWASP speakers to entertain OWASP presentations and that want to see the world.&lt;br /&gt;
&lt;br /&gt;
For sponsorship, see the [[:Category:OWASP_on_the_Move_Project|OWASP on the Move Project]] page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Licensing==&lt;br /&gt;
OWASP XXX is free to use. It is licensed under the http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution-ShareAlike 3.0 license], so you can copy, distribute and transmit the work, and you can adapt it, and use it commercially, but all provided that you attribute the work and if you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;padding-left:25px;width:200px;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
== What is OWASP Speakers Project? ==&lt;br /&gt;
&lt;br /&gt;
OWASP Speakers Project provides:&lt;br /&gt;
*OWASP related speakers for local chapter and conferences.&lt;br /&gt;
&lt;br /&gt;
== Presentation ==&lt;br /&gt;
&lt;br /&gt;
== Project Leader ==&lt;br /&gt;
[mailto:Martin.knoblock@owasp.org Martin Knobloch]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Related Projects ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;padding-left:25px;width:200px;&amp;quot; | &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== News and Events ==&lt;br /&gt;
&lt;br /&gt;
==Classifications==&lt;br /&gt;
&lt;br /&gt;
   {| width=&amp;quot;200&amp;quot; cellpadding=&amp;quot;2&amp;quot;&lt;br /&gt;
   |-&lt;br /&gt;
   | align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot; rowspan=&amp;quot;2&amp;quot;| [[File:Owasp-incubator-trans-85.png|link=https://www.owasp.org/index.php/OWASP_Project_Stages#tab=Incubator_Projects]]&lt;br /&gt;
   | align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot;| [[File:Owasp-builders-small.png|link=]]  &lt;br /&gt;
   |-&lt;br /&gt;
   | align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot;| [[File:Owasp-defenders-small.png|link=]]&lt;br /&gt;
   |-&lt;br /&gt;
   | colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;  | [[File:Cc-button-y-sa-small.png|link=http://creativecommons.org/licenses/by-sa/3.0/]]&lt;br /&gt;
   |-&lt;br /&gt;
   | colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot;  | [[File:Project_Type_Files_CODE.jpg|link=]]&lt;br /&gt;
   |}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Available Speakers =&lt;br /&gt;
If you want to (re)do an OWASP related presentation, propose them here with your availability boundaries (timing/geographical) &lt;br /&gt;
&lt;br /&gt;
*Add your name, contact and bio information to become available as OWASP Speaker!&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name &lt;br /&gt;
! Introduction &lt;br /&gt;
! Available Area &lt;br /&gt;
! Bios&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:Robert(at)ZakonGroup.com Robert H'obbes' Zakon] &lt;br /&gt;
| Presenter on Web Application Security, OWASP Top 10, PHP Security, and assorted other topics.  Training sessions taught at events such as [http://www.zakongroup.com/technology/services-training.shtml OWASP, ACSAC, and CCS].  Based in New Hampshire, and available for travel worldwide.  Fluent in English, and able to converse in Portuguese.  A developer and consultant for the past decade, formerly a Principal Engineer with MITRE's InfoSec Group. &lt;br /&gt;
| Global (USA/NH-based) &lt;br /&gt;
| [http://www.zakon.org/robert/vitae.html BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:jmcgovern@virtusa.com James McGovern] &lt;br /&gt;
| Presenter on Enterprise Architecture and Web Application Security, SOA Web Services Security and Federated Identity.   &lt;br /&gt;
| Global (USA/CT-based) &lt;br /&gt;
| [http://www.linkedin.com/in/jamesmcgovern BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:chuck(at)McCulloughAssociates.com Chuck McCullough] &lt;br /&gt;
| Chuck provides training sessions to developers on the Top 10. Chuck welcomes speaking opportunities to any group. Chuck is available in the Texas area and at various other locations in the USA. &lt;br /&gt;
| USA/Texas &lt;br /&gt;
| [http://www.linkedin.com/in/chuckmccullough BIO]&lt;br /&gt;
|-&lt;br /&gt;
| Marc Curphey &lt;br /&gt;
| Marc will happily speak about the WebAppSec industry, SDLC etc. around Europe. You can see him in action at [http://video.hitb.org/2006.html HITB with John Viega] (big download) &lt;br /&gt;
| Europe &lt;br /&gt;
| [http://www.linkedin.com/in/curphey BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:tomb@proactiverisk.com Tom Brennan] &lt;br /&gt;
| Tom is based in Northern New Jersey and leads the NYC Metro Chapters of OWASP Foundation since 2004. Tom served the community for (7) years as a member of the Global Board of Directors (2007-2014) and as a active project contributor.  Tom is available for events worldwide to educate audiences about the OWASP Foundation core mission, how it works and various projects related to software security.  He has a background as a Builder, Breaker and Defender [https://www.owasp.org/index.php/User:Brennan BIO]&lt;br /&gt;
| Global &lt;br /&gt;
| [http://www.linkedin.com/in/tombrennan BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:thesp0nge@owasp.org Paolo Perego] &lt;br /&gt;
| Paolo is available to talk about [http://www.owasp.org/index.php/Category:OWASP_Orizon_Project Orizon project], safe coding and code review issues around Europe in the near October-December. &lt;br /&gt;
| Europe &lt;br /&gt;
| [http://www.linkedin.com/in/thesp0nge BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:marc.m.morana@gmail.org Marco Morana] &lt;br /&gt;
| Marco is available to talk about [http://iac.dtic.mil/iatac/download/security.pdf Software Security Frameworks]and Secure Code Reviews [https://www.cmpevents.com/CSI33/a.asp?option=G&amp;amp;V=3&amp;amp;id=443342 see 07 CSI conference as reference] in USA around November-December and in Europe around January-February &lt;br /&gt;
| Europe &lt;br /&gt;
| [http://www.linkedin.com/pub/2/a7a/59b BIO]&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:amro@owasp.org Amro Alolaqi] &lt;br /&gt;
| Amro is leading the OWASP Saudi Arabia and UAE chapters, futhermore a contributor for the OWASP Testing Guide v4, OWASP Zed Attack Proxy (ZAP) and OWASP Web Application Security Testing Cheat Sheet. He is a frequent speaker at various industry conferences and events; topics of interest include Web App Critical Vulnerabilities, OWASP Zed Attack Proxy (ZAP), OWASP Testing Guide, Web Application Security Testing and Threat Modeling.&lt;br /&gt;
| Global (Middle East-based)&lt;br /&gt;
| [https://www.owasp.org/index.php/User:Amro_Ahmed BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:sebastien.gioria@owasp.fr Sébastien Gioria] &lt;br /&gt;
| Sebastien is available to talk about WebAppSec, educational purpose on AppSec in French or at least in english around France/Europe/Canada from middle of March 08. You can find some Talk on the [http://www.owasp.fr Owasp France Chapter] &lt;br /&gt;
| France/Europe/Canada &lt;br /&gt;
| [http://www.linkedin.com/in/gioria BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:mordecai.kraushar@owasp.org Mordecai Kraushar] &lt;br /&gt;
| Mordecai is available to talk about different topics within the Web application security space. Discussions typically involve either the Broken Web Application project or the Vicnum project,  [http://www.owasp.org/index.php/Category:OWASP_Vicnum_Project], a flexible vulnerable web application that can be used in many scenarios including 'capture the flag' exercises. &lt;br /&gt;
| Global &lt;br /&gt;
| [http://www.linkedin.com/in/mkraushar BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:michael.coates@owasp.org Michael Coates] &lt;br /&gt;
| Michael is available to talk on a variety of web application security topics. Talks are interactive and include live demos and code examples. Michael has spoken at multiple OWASP conferences and University security courses on topics such as Introduction to Application Security, Automated Defense Systems in Applications, Real Time Detection and Prevention of Application Worms, and security risks in SSL/TLS.  &lt;br /&gt;
| USA/San Francisco &amp;amp; Virtual Presentations&lt;br /&gt;
| [http://www.linkedin.com/in/mcoates BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:tobias.gondrom@owasp.org Tobias Gondrom] &lt;br /&gt;
| Tobias is on the London chapter board (and previously Germany chapter lead) and currently member of the OWASP Global Industry committee. He is available to talk on a variety of web application and information security and risk management topics. He gives two different types of presentations - preferred in Asia or Europe: &amp;lt;br&amp;gt;- CISO level: information security, risk management from Secure SDLCs, maturity models, standards and security strategy, to change management and managing application security in large organisations and the OWASP CISO Guide. &amp;lt;br&amp;gt;- Deep technical talks: new security standards and research, involving his work in web security research and as the chair of the web security working group at the IETF. Tobias has spoken at multiple OWASP AppSec and other security conferences, given university guest lectures and full training days on topics like CISO training, browser security, web security, new technologies for channel protection with SSL/TLS, electronic signatures, ...&lt;br /&gt;
| Asia and Europe  &amp;lt;br&amp;gt;(dual based in both regions)&lt;br /&gt;
| [http://uk.linkedin.com/in/gondrom BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:dan.cornell@owasp.org Dan Cornell] &lt;br /&gt;
| Dan Cornell has over twelve years of experience architecting, developing and securing web-based software systems. He speaks on a variety of software development and software security topics such as Vulnerability Management, Software Security Remediation, and Code Review/Static Analysis. Dan is based in San Antonio, TX and available to fly/drive as needed to the site. &lt;br /&gt;
| USA/San Antonio &lt;br /&gt;
| [http://www.denimgroup.com/about_team_dan.html BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:John.Steven@owasp.org John Steven] &lt;br /&gt;
| John speaks on a variety of topics including &amp;quot;How to build your own application security group&amp;quot;, &amp;quot;Threat Modeling&amp;quot;, &amp;quot;Code Review and Static analysis&amp;quot;, as well as other topics. John has spoken at and given tutorials for multiple OWASP conferences. John frequents New York, Boston, Washington DC, and Charlotte, but is available for travel elsewhere. &lt;br /&gt;
| Washington, DC/USA &lt;br /&gt;
| [http://www.cigital.com/about/team/management.php#jsteven BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:blake@owasp.org Blake Cornell] &lt;br /&gt;
| Blake is available to speak regarding topics including Security v. HIPPA, Penetration Testing Methodologies, Fuzzing and Blended Threats such as attacking VoIP with the OWASP Top 10. Blake lives in the NY Metro area and is available for speaking at regional, national and world wide events. &lt;br /&gt;
| New York, NY/USA &lt;br /&gt;
| [http://www.linkedin.com/in/blakecornell BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:Nick.Coblentz@gmail.com Nick Coblentz] &lt;br /&gt;
| Nick regularly performs research related to secure software development. He is available to present on topics such as the [http://www.owasp.org/index.php/Category:Software_Assurance_Maturity_Model Software Assurance Maturity Model (SAMM)], the [http://nickcoblentz.blogspot.com/2009/06/samm-inteview-template-version-10.html SAMM Interview Template], [http://nickcoblentz.blogspot.com/2009/05/issa-journal-web-application-security.html Building Web Application Security Portfolios], and [http://nickcoblentz.blogspot.com/2009/11/owasp-presentation-on-dec-10-microsoft.html The Microsoft SDL for Agile Development]. Please email Nick if you see articles on his [http://nickcoblentz.blogspot.com/ blog] that you would like him to present. &lt;br /&gt;
| USA/Kansas, Oklahoma, Missouri &lt;br /&gt;
| [http://www.linkedin.com/in/ncoblentz BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:johnccr@yahoo.com Juan Carlos Calderon] &lt;br /&gt;
| Juan has being part of the Appliction Security industry for 9 years, currently performs research on application and information security arena. He is available to present &amp;quot;Preparing an strategy for application vulnerability detection&amp;quot;, &amp;quot;Owasp Spanish and Internationalization&amp;quot; and &amp;quot;Análisis y efectos del cibercrimen en Mexico&amp;quot;(Analysis and effects of cibercrime in México). He is also open to talk about other topics related to OWASP materials and tools, send him a note to verify the coverage. &lt;br /&gt;
| Aguascalientes/México &lt;br /&gt;
| [http://www.linkedin.com/in/juancarloscalderon BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:edward@owasp.org Edward Bonver] &lt;br /&gt;
| Edward has over a decade of experience in the software security field. He currently works for Symantec's Product Security Team, where he brings all aspects of secure software development to product teams across the company. He is a frequent speaker at various industry conferences and OWASP events; topics of interest include Threat Modeling and Security Testing.&lt;br /&gt;
| Global(USA/Los Angeles-based)&lt;br /&gt;
| [http://www.linkedin.com/in/bonver BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:ludovic.petit@owasp.org Ludovic Petit] &lt;br /&gt;
| Chapter Leader OWASP France and OWASP Global Connections Committee Member,  [https://www.owasp.org/index.php/User:Ludovic_Petit '''Ludovic'''] is living in Paris and is willing to talk about Web Application Security topics with a Corporate dimension, including about Legal and Law Enforcement, the OWASP Foundation approach, and explain why WebApp Security is also linked to Legal and Regulatory aspects, so Corporate responsibility, to protect your business.&lt;br /&gt;
| France, Europe and elsewhere, according to my availabilities and if you pay yourself the travel and accommodation expenses.&lt;br /&gt;
| [http://www.linkedin.com/in/lpetit BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:magno.logan@owasp.org Magno Logan] &lt;br /&gt;
| OWASP Paraiba Chapter Leader and OWASP Portuguese Language Project Member. Magno (Logan) Rodrigues has an MBA in Information Security and studied Computer Forensics for one year in New York. He has done many talks about OWASP and it's main projects at national and international events such as [http://www.ensol.org.br/ ENSOL], [http://gts.nic.br/ GTS] and [https://www.owasp.org/index.php/AppSecLatam2011 App Sec Latam 2011]. Topics of interest include: OWASP Top 10, WebGoat, Java Security, E-commerce Security and Computer Forensics.&lt;br /&gt;
&lt;br /&gt;
| Latin America&lt;br /&gt;
| [https://www.owasp.org/index.php/User:Magno_Logan BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:wagner.elias@owasp.org Wagner Elias] &lt;br /&gt;
| Wagner founded the Brazil chapter is currently Curitiba-Brazil Chapter Leader and available to talk on a variety of web application security topics. Talks are interactive and include live demos and code examples. Wagner has spoken at various conferences in Brazil.&lt;br /&gt;
&lt;br /&gt;
Topics of interest: Mobile Security; SDL Process and Implementation; Code Review and Application Test&lt;br /&gt;
&lt;br /&gt;
| Brazil&lt;br /&gt;
| [https://www.owasp.org/index.php/User:wagner.elias BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:ramiro.pulgar@owasp.org Ramiro Pulgar] &lt;br /&gt;
| Chapter Leader OWASP Ecuador. [https://www.owasp.org/index.php/User:Ramiro_Pulgar '''milovisho'''] OWASP Ecuador Chapter Leader  &lt;br /&gt;
| Ecuador, Latin America, Global&lt;br /&gt;
| [http://ec.linkedin.com/in/ramiropulgar BIO]&lt;br /&gt;
|-&lt;br /&gt;
| [mailto:john.vargas@owasp.org John Vargas] &lt;br /&gt;
| Chapter Leader OWASP Perú. [https://www.owasp.org/index.php/User:Jvargas '''John Vargas'''] OWASP Perú Chapter Leader  &lt;br /&gt;
| Perú, Latin America, Global&lt;br /&gt;
| [http://pe.linkedin.com/in/jvargasp BIO]&lt;br /&gt;
|-&lt;br /&gt;
|[mailto:Ahmed.neil@owasp.org Ahmed M Neil] &lt;br /&gt;
|Neil is available to speak regarding topics including Digital forensics,Wep Application  threats and security, Medical Information System Security, Wep application Penetration Testing,Always like to discuss OWASP Top 10. I am in Mansoura, Egypt now and available for speaking at regional,and world wide events. &lt;br /&gt;
[https://www.owasp.org/index.php/User:Ahmed_M_Neil '''Ahmed Neil'''] OWASP Mansoura Chapter Leader  &lt;br /&gt;
| Africa,Global&lt;br /&gt;
| [http://www.linkedin.com/pub/ahmed-m-neil/38/590/73 BIO]&lt;br /&gt;
|-&lt;br /&gt;
|[mailto:pawel.krawczyk@owasp.org Pawel Krawczyk] &lt;br /&gt;
|Former chapter leader of OWASP Poland, speaking on hundreds of conferences and OWASP meetings. Topics: application security management, large scale vulnerability assessment, developing secure coding standards in agile environments,&lt;br /&gt;
|Europe, Global&lt;br /&gt;
|[https://uk.linkedin.com/in/pawelkrawczyk/ BIO]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Road Map and Getting Involved =&lt;br /&gt;
If you want to (re)do an OWASP related presentation, propose them here with your availability boundaries (timing/geographical) &lt;br /&gt;
&lt;br /&gt;
*Add your name, contact and bio information to become available as OWASP Speaker!&lt;br /&gt;
&lt;br /&gt;
=Project About=&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &amp;lt;headertabs /&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Project]]  [[Category:OWASP_Builders]] [[Category:OWASP_Defenders]]  [[Category:OWASP_Document]]&lt;/div&gt;</summary>
		<author><name>Pawel Krawczyk</name></author>	</entry>

	</feed>