<?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=Joern.zaefferer</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=Joern.zaefferer"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Joern.zaefferer"/>
		<updated>2026-06-01T02:20:39Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=35878</id>
		<title>SSL Best Practices</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SSL_Best_Practices&amp;diff=35878"/>
				<updated>2008-08-12T16:21:08Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Status ==&lt;br /&gt;
Draft&lt;br /&gt;
&lt;br /&gt;
==What is SSL==&lt;br /&gt;
&lt;br /&gt;
SSL is the abbreviation of Secured Socket Layer. It is a protocol enabling to settle a secured communication between two hosts. The origin host is viewed as an SSL client and the destination host as an SSL server.&lt;br /&gt;
&lt;br /&gt;
SSL has also been normalised as the TLS (Transport Layer Security) protocol. &lt;br /&gt;
&lt;br /&gt;
'''SSL is used on top of a transport level protocol''' like HTTP or FTP in order to secure it. &lt;br /&gt;
&lt;br /&gt;
SSL enables : &lt;br /&gt;
* authentication of the destination host for the origin host or mutual authentication of both the origin and the destination hosts&lt;br /&gt;
* data confidentiality through encryption&lt;br /&gt;
* data integrity checking through hashing.&lt;br /&gt;
&lt;br /&gt;
SSL relies on two types of encryption :&lt;br /&gt;
* public key encryption in the initiation phase, where authentication takes place&lt;br /&gt;
* secret key encryption when a session has been established and data is sent between two peers which trust each other.&lt;br /&gt;
&lt;br /&gt;
'''SSL only secures the communication between two endpoints''' : in the origin and destination points, data is in clear text, unless it is encrypted by another means, at the application level.&lt;br /&gt;
&lt;br /&gt;
==How SSL is implemented in J2EE==&lt;br /&gt;
==HTTPS best practices in general==&lt;br /&gt;
==HTTPS best practices in J2EE==&lt;br /&gt;
==Examples with Tomcat==&lt;br /&gt;
==Examples with JBoss==&lt;br /&gt;
&lt;br /&gt;
==Examples with Jetty==&lt;br /&gt;
&lt;br /&gt;
See [http://docs.codehaus.org/display/JETTY/How+to+configure+SSL How to configure SSL] for Jetty&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Preventing_SQL_Injection_in_Java&amp;diff=35877</id>
		<title>Preventing SQL Injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Preventing_SQL_Injection_in_Java&amp;diff=35877"/>
				<updated>2008-08-12T16:08:10Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: /* Parameterizied Queries */ spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Released 14/1/2008&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
As the name implies, SQL injection vulnerabilities allow an attacker to inject (or execute) SQL commands within an application.  It is one of the most wide spread and dangerous application vulnerability.  The CLASP project provides a good overview of [[SQL injection]].&lt;br /&gt;
&lt;br /&gt;
==Example of SQL injection==&lt;br /&gt;
The following Java servlet code, used to perform a login function, illustrates the vulnerability by accepting user input without performing adequate input validation or escaping meta-characters:&lt;br /&gt;
 conn = pool.getConnection( );&lt;br /&gt;
 String sql = &amp;quot;select * from user where username='&amp;quot; + username +&amp;quot;' and password='&amp;quot; + password + &amp;quot;'&amp;quot;;&lt;br /&gt;
 stmt = conn.createStatement();&lt;br /&gt;
 rs = stmt.executeQuery(sql);&lt;br /&gt;
 if (rs.next()) {&lt;br /&gt;
 loggedIn = true;&lt;br /&gt;
 	out.println(&amp;quot;Successfully logged in&amp;quot;);&lt;br /&gt;
 } else {&lt;br /&gt;
 	out.println(&amp;quot;Username and/or password not recognized&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
It is possible for attackers to provide a username containing SQL meta-characters that subvert the intended function of the SQL statement.  For example, by providing a username of:&lt;br /&gt;
 admin' OR '1'='1&lt;br /&gt;
and a blank password, the generated SQL statement becomes:&lt;br /&gt;
 select * from user where username='admin' OR '1'='1' and password=' '&lt;br /&gt;
This allows an attacker to log in to the site without supplying a password, since the ‘OR’ expression is always true.  Using the same technique attackers can inject other SQL commands which could extract, modify or delete data within the database.&lt;br /&gt;
&lt;br /&gt;
==Attack techniques==&lt;br /&gt;
For more information on SQL injection attacks see:&lt;br /&gt;
* http://www.spidynamics.com/papers/SQLInjectionWhitePaper.pdf&lt;br /&gt;
* http://www.nextgenss.com/papers/advanced_sql_injection.pdf&lt;br /&gt;
* http://www.appsecinc.com/presentations/Manipulating_SQL_Server_Using_SQL_Injection.pdf &lt;br /&gt;
&lt;br /&gt;
==Defence Strategy==&lt;br /&gt;
To prevent SQL injection:&lt;br /&gt;
* All queries should be parametrized.&lt;br /&gt;
* All dynamic data should be explicitly bound to parametrized queries.&lt;br /&gt;
* String concatenation should never be used to create dynamic SQL.&lt;br /&gt;
&lt;br /&gt;
==Parameterized Queries==&lt;br /&gt;
All data access techniques provide some means for escaping SQL meta-characters automatically. The following sections detail how to perform input validation and meta-character escaping using popular data access technologies.&lt;br /&gt;
&lt;br /&gt;
===Prepared Statements===&lt;br /&gt;
Variables passed as arguments to prepared statements will automatically be escaped by the JDBC driver.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example: &amp;lt;/b&amp;gt;ps.1&amp;lt;br&amp;gt;&lt;br /&gt;
 String selectStatement = &amp;quot;SELECT * FROM User WHERE userId = ? &amp;quot;;&lt;br /&gt;
 PreparedStatement prepStmt = con.prepareStatement(selectStatement);&lt;br /&gt;
 prepStmt.setString(1, userId);&lt;br /&gt;
 ResultSet rs = prepStmt.executeQuery();&lt;br /&gt;
&lt;br /&gt;
Although Prepared Statements helps in defending against SQL Injection, there are possibilities of SQL Injection attacks through inappropriate usage of Prepared Statements. The example below explains such a scenario where the input variables are passed directly into the Prepared Statement and thereby paving way for SQL Injection attacks. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example: &amp;lt;/b&amp;gt;ps.2&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String strUserName = request.getParameter(&amp;quot;Txt_UserName&amp;quot;); &lt;br /&gt;
PreparedStatement prepStmt = con.prepareStatement(&amp;quot;SELECT * FROM user WHERE userId = '+strUserName+'&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stored Procedures===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
===Hibernate===&lt;br /&gt;
According to [http://forum.hibernate.org/viewtopic.php?t=960817&amp;amp;start=0&amp;amp;postdays=0&amp;amp;postorder=asc this forum thread] hibernate uses prepared statements, so it is protected from direct sql injection, but it could still be vulnerable to [http://www.owasp.org/index.php/Interpreter_Injection#ORM_Injection injecting HQL statements].&lt;br /&gt;
&lt;br /&gt;
==Variable Binding==&lt;br /&gt;
&lt;br /&gt;
It is critical to use Bind Variables as mentioned in the example ps.1 above. Usage of PreparedStatement with Bind variables defends SQL Injection attacks and improves the performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Dynamic Queries via String Concatenation==&lt;br /&gt;
&lt;br /&gt;
The important thing to remember is to &amp;lt;b&amp;gt;never construct SQL statements using string concatenation of unchecked input values.&amp;lt;/b&amp;gt;  Creating of dynamic queries via the java.sql.Statement class leads to SQL Injection.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[1] [http://research.corsaire.com/whitepapers/060116-a-modular-approach-to-data-validation.pdf A Modular Approach to Data Validation]&lt;br /&gt;
*[2] [http://forum.hibernate.org/viewtopic.php?t=960817&amp;amp;start=0&amp;amp;postdays=0&amp;amp;postorder=asc&amp;amp;highlight= Topic: does Hibernate guard against SQL injection?]&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=35876</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=35876"/>
				<updated>2008-08-12T16:02:50Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: /* Noteworthy Frameworks */  added Wicket&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level, for example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===[[Java Security Basics]]===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* Command injection - Runtime.getRuntime().exec() (0%, TD)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Using JCaptcha]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[J2EE Security For Deployers]] ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Security Analysts and Testers]]==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Maintenance&amp;diff=35875</id>
		<title>Talk:Maintenance</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Maintenance&amp;diff=35875"/>
				<updated>2008-08-12T15:49:28Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: New page: About Update Notifications: Isn't this about web application security? Since when do web apps need the user to manually update?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;About Update Notifications: Isn't this about web application security? Since when do web apps need the user to manually update?&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Guide_to_Cryptography&amp;diff=35873</id>
		<title>Guide to Cryptography</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Guide_to_Cryptography&amp;diff=35873"/>
				<updated>2008-08-12T14:52:37Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: /* Asymmetric Cryptography (also called Public/Private Key Cryptography) */ grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
To ensure that cryptography is safely used to protect the confidentiality and integrity of sensitive user data&lt;br /&gt;
&lt;br /&gt;
==Platforms Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS5.18 – Cryptographic key management&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Initially confined to the realms of academia and the military, cryptography has become ubiquitous thanks to the Internet. Common every day uses of cryptography include mobile phones, passwords, SSL, smart cards, and DVDs. Cryptography has permeated everyday life, and is heavily used by many web applications.&lt;br /&gt;
&lt;br /&gt;
Cryptography (or crypto) is one of the more advanced topics of information security, and one whose understanding requires the most schooling and experience. It is difficult to get right because there are many approaches to encryption, each with advantages and disadvantages that need to be thoroughly understood by web solution architects and developers.  In addition, serious cryptography research is typically based in advanced mathematics and number theory, providing a serious barrier to entry. &lt;br /&gt;
&lt;br /&gt;
The proper and accurate implementation of cryptography is extremely critical to its efficacy. A small mistake in configuration or coding will result in removing a large degree of the protection it affords and rending the crypto implementation useless against serious attacks.&lt;br /&gt;
&lt;br /&gt;
A good understanding of crypto is required to be able to discern between solid products and snake oil. The inherent complexity of crypto makes it easy to fall for fantastic claims from vendors about their product. Typically, these are “a breakthrough in cryptography” or “unbreakable” or provide &amp;quot;military grade&amp;quot; security. If a vendor says &amp;quot;trust us, we have had experts look at this,” chances are they weren't experts!&lt;br /&gt;
&lt;br /&gt;
==Cryptographic Functions ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic systems can provide one or more of the following four services. It is important to distinguish between these, as some algorithms are more suited to particular tasks, but not to others.&lt;br /&gt;
&lt;br /&gt;
When analyzing your requirements and risks, you need to decide which of these four functions should be used to protect your data.&lt;br /&gt;
&lt;br /&gt;
===Authentication ===&lt;br /&gt;
&lt;br /&gt;
Using a cryptographic system, we can establish the identity of a remote user (or system). A typical example is the SSL certificate of a web server providing proof to the user that he or she is connected to the correct server.&lt;br /&gt;
&lt;br /&gt;
The identity is not of the user, but of the cryptographic key of the user. Having a less secure key lowers the trust we can place on the identity.&lt;br /&gt;
&lt;br /&gt;
===Non-Repudiation ===&lt;br /&gt;
&lt;br /&gt;
The concept of non-repudiation is particularly important for financial or e-commerce applications. Often, cryptographic tools are required to prove that a unique user has made a transaction request. It must not be possible for the user to refute his or her actions.&lt;br /&gt;
&lt;br /&gt;
For example, a customer may request a transfer of money from her account to be paid to another account. Later, she claims never to have made the request and demands the money be refunded to the account. If we have non-repudiation through cryptography, we can prove – usually through digitally signing the transaction request, that the user authorized the transaction.&lt;br /&gt;
&lt;br /&gt;
===Confidentiality ===&lt;br /&gt;
&lt;br /&gt;
More commonly, the biggest concern will be to keep information private. Cryptographic systems were originally developed to function in this capacity. Whether it be passwords sent during a log on process, or storing confidential medical records in a database, encryption can assure that only users who have access to the appropriate key will get access to the data.&lt;br /&gt;
&lt;br /&gt;
===Integrity ===&lt;br /&gt;
&lt;br /&gt;
We can use cryptography to provide a means to ensure data is not viewed or altered during storage or transmission. Cryptographic hashes for example, can safeguard data by providing a secure checksum.&lt;br /&gt;
&lt;br /&gt;
==Cryptographic Algorithms ==&lt;br /&gt;
&lt;br /&gt;
Various types of cryptographic systems exist that have different strengths and weaknesses. Typically, they are divided into two classes; those that are strong, but slow to run and those that are quick, but less secure. Most often a combination of the two approaches is used (e.g.: SSL), whereby we establish the connection with a secure algorithm, and then if successful, encrypt the actual transmission with the weaker, but much faster algorithm.&lt;br /&gt;
&lt;br /&gt;
===Symmetric Cryptography ===&lt;br /&gt;
&lt;br /&gt;
Symmetric Cryptography is the most traditional form of cryptography.  In a symmetric cryptosystem, the involved parties share a common secret (password, pass phrase, or key). Data is encrypted and decrypted using the same key. These algorithms tend to be comparatively fast, but they cannot be used unless the involved parties have already exchanged keys.  Any party possessing a specific key can create encrypted messages using that key as well as decrypt any messages encrypted with the key.  In systems involving a number of users who each need to set up independent, secure communication channels symmetric cryptosystems can have practical limitations due to the requirement to securely distribute and manage large numbers of keys.&lt;br /&gt;
&lt;br /&gt;
Common examples of symmetric algorithms are DES, 3DES and AES. The 56-bit keys used in DES are short enough to be easily brute-forced by modern hardware and DES should no longer be used.  Triple DES (or 3DES) uses the same  algorithm, applied three times with different keys giving it an effective key length of 128 bits.  Due to the problems using the DES alrgorithm, the United States National Institute of Standards and Technology (NIST) hosted a selection process for a new algorithm.  The winning algorithm was Rijndael and the associated cryptosystem is now known as the Advanced Encryption Standard or AES.  For most applications 3DES is acceptably secure at the current time, but for most new applications it is advisable to use AES.&lt;br /&gt;
&lt;br /&gt;
===Asymmetric Cryptography (also called Public/Private Key Cryptography) ===&lt;br /&gt;
&lt;br /&gt;
Asymmetric algorithms use two keys, one to encrypt the data, and either key to decrypt. These inter-dependent keys are generated together. One is labeled the Public key and is distributed freely. The other is labeled the Private Key and must be kept hidden.&lt;br /&gt;
&lt;br /&gt;
Often referred to as Public/Private Key Cryptography, these cryptosystems can provide a number of different functions depending on how they are used. &lt;br /&gt;
&lt;br /&gt;
The most common usage of asymmetric cryptography is to send messages with a guarantee of confidentiality.  If User A wanted to send a message to User B, User A would get access to User B’s publicly-available Public Key.  The message is then encrypted with this key and sent to User B.  Because of the cryptosystem’s property that messages encoded with the Public Key of User B can only be decrypted with User B’s Private Key, only User B can read the message.&lt;br /&gt;
&lt;br /&gt;
Another usage scenario is one where User A wants to send User B a message and wants User B to have a guarantee that the message was sent by User A.  In order to accomplish this, User A would encrypt the message with their Private Key.  The message can then only be decrypted using User A’s Public Key.  This guarantees that User A created the message Because they are then only entity who had access to the Private Key required to create a message that can be decrcrypted by User A’s Public Key.  This is essentially a digital signature guaranteeing that the message was created by User A.&lt;br /&gt;
&lt;br /&gt;
A Certificate Authority (CA), whose public certificates are installed with browsers or otherwise commonly available, may also digitally sign public keys or certificates. We can authenticate remote systems or users via a mutual trust of an issuing CA. We trust their ‘root’ certificates, which in turn authenticate the public certificate presented by the server.&lt;br /&gt;
&lt;br /&gt;
PGP and SSL are prime examples of a systems implementing asymmetric cryptography, using RSA or other algorithms.&lt;br /&gt;
&lt;br /&gt;
===Hashes ===&lt;br /&gt;
&lt;br /&gt;
Hash functions take some data of an arbitrary length (and possibly a key or password) and generate a fixed-length hash based on this input. Hash functions used in cryptography have the property that it is easy to calculate the hash, but difficult or impossible to re-generate the original input if only the hash value is known.  In addition, hash functions useful for cryptography  have the property that it is difficult to craft an initial input such that the hash will match a specific desired value.&lt;br /&gt;
&lt;br /&gt;
MD5 and SHA-1 are common hashing algorithms used today. These algorithms are considered weak (see below) and are likely to be replaced after a process similar to the AES selection. New applications should consider using SHA-256 instead of these weaker algorithms.&lt;br /&gt;
&lt;br /&gt;
===Key Exchange Algorithms ===&lt;br /&gt;
&lt;br /&gt;
Lastly, we have key exchange algorithms (such as Diffie-Hellman for SSL). These allow use to safely exchange encryption keys with an unknown party. &lt;br /&gt;
&lt;br /&gt;
==Algorithm Selection ==&lt;br /&gt;
&lt;br /&gt;
As modern cryptography relies on being computationally expensive to break, specific standards can be set for key sizes that will provide assurance that with today’s technology and understanding, it will take too long to decrypt a message by attempting all possible keys.&lt;br /&gt;
&lt;br /&gt;
Therefore, we need to ensure that both the algorithm and the key size are taken into account when selecting an algorithm.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Proprietary encryption algorithms are not to be trusted as they typically rely on ‘security through obscurity’ and not sound mathematics. These algorithms should be avoided if possible.&lt;br /&gt;
&lt;br /&gt;
Specific algorithms to avoid:&lt;br /&gt;
&lt;br /&gt;
* MD5 has recently been found less secure than previously thought. While still safe for most applications such as hashes for binaries made available publicly, secure applications should now be migrating away from this algorithm.&lt;br /&gt;
&lt;br /&gt;
* SHA-0 has been conclusively broken. It should no longer be used for any sensitive applications.&lt;br /&gt;
&lt;br /&gt;
* SHA-1 has been reduced in strength and we encourage a migration to SHA-256, which implements a larger key size.&lt;br /&gt;
&lt;br /&gt;
* DES was once the standard crypto algorithm for encryption; a normal desktop machine can now break it. AES is the current preferred symmetric algorithm.&lt;br /&gt;
&lt;br /&gt;
Cryptography is a constantly changing field. As new discoveries in cryptanalysis are made, older algorithms will be found unsafe. In addition, as computing power increases the feasibility of brute force attacks will render other cryptosystems or the use of certain key lengths unsafe. Standard bodies such as NIST should be monitored for future recommendations. &lt;br /&gt;
&lt;br /&gt;
Specific applications, such as banking transaction systems may have specific requirements for algorithms and key sizes.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Assuming you have chosen an open, standard algorithm, the following recommendations should be considered when reviewing algorithms:&lt;br /&gt;
&lt;br /&gt;
'''Symmetric:'''&lt;br /&gt;
&lt;br /&gt;
* Key sizes of 128 bits (standard for SSL) are sufficient for most applications&lt;br /&gt;
&lt;br /&gt;
* Consider 168 or 256 bits for secure systems such as large financial transactions&lt;br /&gt;
&lt;br /&gt;
'''Asymmetric:'''&lt;br /&gt;
&lt;br /&gt;
The difficulty of cracking a 2048 bit key compared to a 1024 bit key is far, far, far, more than the twice you might expect. Don’t use excessive key sizes unless you know you need them. Bruce Schneier in 2002 (see the references section) recommended the following key lengths for circa 2005 threats:&lt;br /&gt;
&lt;br /&gt;
* Key sizes of 1280 bits are sufficient for most personal applications&lt;br /&gt;
&lt;br /&gt;
* 1536 bits should be acceptable today for most secure applications&lt;br /&gt;
&lt;br /&gt;
* 2048 bits should be considered for highly protected applications.&lt;br /&gt;
&lt;br /&gt;
'''Hashes:'''&lt;br /&gt;
&lt;br /&gt;
* Hash sizes of 128 bits (standard for SSL) are sufficient for most applications&lt;br /&gt;
&lt;br /&gt;
* Consider 168 or 256 bits for secure systems, as many hash functions are currently being revised (see above).&lt;br /&gt;
&lt;br /&gt;
NIST and other standards bodies will provide up to date guidance on suggested key sizes.&lt;br /&gt;
&lt;br /&gt;
'''Design your application to cope with new hashes and algorithms'''&lt;br /&gt;
&lt;br /&gt;
==Key Storage ==&lt;br /&gt;
&lt;br /&gt;
As highlighted above, crypto relies on keys to assure a user’s identity, provide confidentiality and integrity as well as non-repudiation. It is vital that the keys are adequately protected. Should a key be compromised, it can no longer be trusted.&lt;br /&gt;
&lt;br /&gt;
Any system that has been compromised in any way should have all its cryptographic keys replaced. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Unless you are using hardware cryptographic devices, your keys will most likely be stored as binary files on the system providing the encryption. &lt;br /&gt;
&lt;br /&gt;
Can you export the private key or certificate from the store? &lt;br /&gt;
&lt;br /&gt;
* Are any private keys or certificate import files (usually in PKCS#12 format) on the file system? Can they be imported without a password?&lt;br /&gt;
&lt;br /&gt;
* Keys are often stored in code. This is a bad idea, as it means you will not be able to easily replace keys should they become compromised.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Cryptographic keys should be protected as much as is possible with file system permissions. They should be read only and only the application or user directly accessing them should have these rights.&lt;br /&gt;
&lt;br /&gt;
* Private keys should be marked as not exportable when generating the certificate signing request. &lt;br /&gt;
&lt;br /&gt;
* Once imported into the key store (CryptoAPI, Certificates snap-in, Java Key Store, etc), the private certificate import file obtained from the certificate provider should be safely destroyed from front-end systems. This file should be safely stored in a safe until required (such as installing or replacing a new front end server)&lt;br /&gt;
&lt;br /&gt;
* Host based intrusion systems should be deployed to monitor access of keys. At the very least, changes in keys should be monitored.&lt;br /&gt;
&lt;br /&gt;
* Applications should log any changes to keys. &lt;br /&gt;
&lt;br /&gt;
* Pass phrases used to protect keys should be stored in physically secure places; in some environments, it may be necessary to split the pass phrase or password into two components such that two people will be required to authorize access to the key. These physical, manual processes should be tightly monitored and controlled.&lt;br /&gt;
&lt;br /&gt;
* Storage of keys within source code or binaries should be avoided. This not only has consequences if developers have access to source code, but key management will be almost impossible.&lt;br /&gt;
&lt;br /&gt;
* In a typical web environment, web servers themselves will need permission to access the key. This has obvious implications that other web processes or malicious code may also have access to the key. In these cases, it is vital to minimize the functionality of the system and application requiring access to the keys.&lt;br /&gt;
&lt;br /&gt;
* For interactive applications, a sufficient safeguard is to use a pass phrase or password to encrypt the key when stored on disk. This requires the user to supply a password on startup, but means the key can safely be stored in cases where other users may have greater file system privileges.&lt;br /&gt;
&lt;br /&gt;
Storage of keys in hardware crypto devices is beyond the scope of this document. If you require this level of security, you should really be consulting with crypto specialists.&lt;br /&gt;
&lt;br /&gt;
==Insecure transmission of secrets ==&lt;br /&gt;
&lt;br /&gt;
In security, we assess the level of trust we have in information. When applied to transmission of sensitive data, we need to ensure that encryption occurs before we transmit the data onto any untrusted network. &lt;br /&gt;
&lt;br /&gt;
In practical terms, this means we should aim to encrypt as close to the source of the data as possible.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
This can be extremely difficult without expert help. We can try to at least eliminate the most common problems:&lt;br /&gt;
&lt;br /&gt;
* The encryption algorithm or protocol needs to be adequate to the task. The above discuss on weak algorithms and weak keys should be a good starting point&lt;br /&gt;
&lt;br /&gt;
* We must ensure that through all paths of the transmission we apply this level of encryption&lt;br /&gt;
&lt;br /&gt;
* Extreme care needs to be taken at the point of encryption and decryption. If your encryption library needs to use temporary files, are these adequately protected? &lt;br /&gt;
&lt;br /&gt;
* Are keys stored securely? Is an unsecured file left behind after it has been encrypted?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
We have the possibility to encrypt or otherwise protect data at different levels. Choosing the right place for this to occur can involve looking at both security as well as resource requirements. &lt;br /&gt;
&lt;br /&gt;
'''Application''': at this level, the actual application performs the encryption or other crypto function. This is the most desirable, but can place additional strain on resources and create unmanageable complexity. Encryption would be performed typically through an API such as the OpenSSL toolkit (www.openssl.com) or operating system provided crypto functions.&lt;br /&gt;
&lt;br /&gt;
An example would be an S/MIME encrypted email, which is transmitted as encoded text within a standard email. No changes to intermediate email hosts are necessary to transmit the message because we do not require a change to the protocol itself.&lt;br /&gt;
&lt;br /&gt;
'''Protocol''': at this layer, the protocol provides the encryption service. Most commonly, this is seen in HTTPS, using SSL encryption to protect sensitive web traffic. The application no longer needs to implementing secure connectivity. However, this does not mean the application has a free ride. SSL requires careful attention when used for mutual (client-side) authentication, as there are two different session keys, one for each direction. Each should be verified before transmitting sensitive data.&lt;br /&gt;
&lt;br /&gt;
Attackers and penetration testers love SSL to hide malicious requests (such as injection attacks for example). Content scanners are most likely unable to decode the SSL connection, letting it pass to the vulnerable web server.&lt;br /&gt;
&lt;br /&gt;
'''Network''': below the protocol layer, we can use technologies such as Virtual Private Networks (VPN) to protect data. This has many incarnations, the most popular being IPsec (Internet Protocol v6 Security), typically implemented as a protected ‘tunnel’ between two gateway routers. Neither the application nor the protocol needs to be crypto aware – all traffic is encrypted regardless.&lt;br /&gt;
&lt;br /&gt;
Possible issues at this level are computational and bandwidth overheads on network devices.&lt;br /&gt;
&lt;br /&gt;
==Reversible Authentication Tokens ==&lt;br /&gt;
&lt;br /&gt;
Today’s web servers typically deal with large numbers of users. Differentiating between them is often done through cookies or other session identifiers. If these session identifiers use a predictable sequence, an attacker need only generate a value in the sequence in order to present a seemingly valid session token.&lt;br /&gt;
&lt;br /&gt;
This can occur at a number of places; the network level for TCP sequence numbers, or right through to the application layer with cookies used as authenticating tokens.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Any deterministic sequence generator is likely to be vulnerable.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
The only way to generate secure authentication tokens is to ensure there is no way to predict their sequence. In other words: true random numbers.&lt;br /&gt;
&lt;br /&gt;
It could be argued that computers can not generate true random numbers, but using new techniques such as reading mouse movements and key strokes to improve entropy has significantly increased the randomness of random number generators. It is critical that you do not try to implement this on your own; use of existing, proven implementations is highly desirable.&lt;br /&gt;
&lt;br /&gt;
Most operating systems include functions to generate random numbers that can be called from almost any programming language.&lt;br /&gt;
&lt;br /&gt;
'''Windows &amp;amp; .NET:''' On Microsoft platforms including .NET, it is recommended to use the inbuilt CryptGenRandom function (&amp;lt;u&amp;gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/cryptgenrandom.asp&amp;lt;/u&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Unix:''' For all Unix based platforms, OpenSSL is an excellent option (&amp;lt;u&amp;gt;http://www.openssl.org/&amp;lt;/u&amp;gt;). It features tools and API functions to generate random numbers. On some platforms, /dev/urandom is a suitable source of pseudo-random entropy.&lt;br /&gt;
&lt;br /&gt;
'''PHP:'''  mt_rand() uses a Mersenne Twister, but is nowhere near as good as CryptoAPI’s secure random number generation options, OpenSSL, or /dev/urandom which is available on many Unix variants. mt_rand() has been noted to produce the same number on some platforms – test prior to deployment. '''Do not use rand() as it is very weak.'''&lt;br /&gt;
&lt;br /&gt;
'''Java:''' java.security.SecureRandom within the Java Cryptography Extension (JCE) provides secure random numbers. This should be used in preference to other random number generators.&lt;br /&gt;
&lt;br /&gt;
'''ColdFusion: '''ColdFusion MX 7 leverages the JCE java.security.SecureRandom class of the underlying JVM as its pseudo random number generator (PRNG)'''''.'' '''&lt;br /&gt;
&lt;br /&gt;
==Safe UUID generation ==&lt;br /&gt;
&lt;br /&gt;
UUIDs (such as GUIDs and so on) are only unique if you generate them. This seems relatively straightforward. However, there are many code snippets available that contain existing UUIDS. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
# Determine the source of your existing UUIDS &lt;br /&gt;
## Did they come from MSDN?&lt;br /&gt;
## Or from a example found on the Internet? &lt;br /&gt;
# Use your favorite search engine to find out&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Do not cut and paste UUIDs and GUIDs from anything other than the UUIDGEN program or from the UuidCreate() API&lt;br /&gt;
&lt;br /&gt;
* Generate fresh UUIDs or GUIDs for each new program &lt;br /&gt;
&lt;br /&gt;
==Summary ==&lt;br /&gt;
&lt;br /&gt;
Cryptography is one of pillars of information security. Its usage and propagation has exploded due to the Internet and it is now included in most areas computing. Crypto can be used for:&lt;br /&gt;
&lt;br /&gt;
* Remote access such as IPsec VPN&lt;br /&gt;
&lt;br /&gt;
* Certificate based authentication&lt;br /&gt;
&lt;br /&gt;
* Securing confidential or sensitive information&lt;br /&gt;
&lt;br /&gt;
* Obtaining non-repudiation using digital certificates&lt;br /&gt;
&lt;br /&gt;
* ?Online orders and payments&lt;br /&gt;
&lt;br /&gt;
* Email and messaging security such as S/MIME&lt;br /&gt;
&lt;br /&gt;
A web application can implement cryptography at multiple layers: application, application server or runtime (such as .NET), operating system and hardware. Selecting an optimal approach requires a good understanding of application requirements, the areas of risk, and the level of security strength it might require, flexibility, cost, etc.&lt;br /&gt;
&lt;br /&gt;
Although cryptography is not a panacea, the majority of security breaches do not come from brute force computation but from exploiting mistakes in implementation. The strength of a cryptographic system is measured in key length. Using a large key length and then storing the unprotected keys on the same server, eliminates most of the protection benefit gained. Besides the secure storage of keys, another classic mistake is engineering custom cryptographic algorithms (to generate random session ids for example). Many web applications were successfully attacked because the developers thought they could create their crypto functions. &lt;br /&gt;
&lt;br /&gt;
Our recommendation is to use proven products, tools, or packages rather than rolling your own.&lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* Wu, H., ''Misuse of stream ciphers in Word and Excel''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://eprint.iacr.org/2005/007.pdf&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Bindview, ''Vulnerability in Windows NT's SYSKEY encryption'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.bindview.com/Services/razor/Advisories/1999/adv_WinNT_syskey.cfm&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Schneier, B. ''Is 1024 bits enough?, ''April 2002 Cryptogram''&lt;br /&gt;
&lt;br /&gt;
''&amp;lt;u&amp;gt;http://www.schneier.com/crypto-gram-0204.html#3&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Schneier, B., Cryptogram, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.counterpane.com/cryptogram.html&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* NIST, Replacing SHA-1 with stronger variants: SHA-256 ? 512&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://csrc.nist.gov/CryptoToolkit/tkhash.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://csrc.nist.gov/CryptoToolkit/tkencryption.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* UUIDs are only unique if you generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://blogs.msdn.com/larryosterman/archive/2005/07/21/441417.aspx&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Cryptographically Secure Random Numbers on Win32:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx&amp;lt;/u&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
==Cryptography ==&lt;br /&gt;
&lt;br /&gt;
The following section describes the ColdFusion’s cryptography features. ColdFusion MX leverages the Java Cryptography Extension (JCE) of the underlying J2EE platform for cryptography and random number generation. It provides functions for symmetric (or private-key) encryption. While it does not provide native functionality for public-key (asymmetric) encryption, it does use the Java Secure Socket Extension (JSSE) for SSL communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pseudo-Random Number Generation'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides three functions for random number generation: rand(), randomize(), and randRange(). Function descriptions and syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Rand''' – Use to generate a pseudo-random number&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	rand([algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Randomize''' – Use to seed the pseudo-random number generator (PRNG) with an integer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	randomize(number [, algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''RandRange''' – Use to generate a pseudo-random integer within the range of the specified numbers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	randrange(number1, number2 [, algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following values are the allowed algorithm parameters''' ''':&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: (default) – Invokes java.util.rand&lt;br /&gt;
&lt;br /&gt;
SHA1PRNG: (recommended) – Invokes java.security.SecureRandom using the Sun Java SHA-1 PRNG algorithm.&lt;br /&gt;
&lt;br /&gt;
IBMSecureRandom: IBM WebSphere’s JVM does not support the SHA1PRNG algorithm. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Symmetric Encryption'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion MX 7 provides six encryption functions: decrypt(), decryptBinary(), encrypt(), encryptBinary(), generateSecretKey(), and hash(). Function descriptions and syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Decrypt''' – Use to decrypt encrypted strings with specified key, algorithm, encoding, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	decrypt(encrypted_string, key[, algorithm[, encoding[, IVorSalt[, iterations]]]]))'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''DecryptBinary''' – Use to decrypt encrypted binary data with specified key, algorithm, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	decryptBinary(bytes, key[, algorithm[, IVorSalt[, iterations]]])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Encrypt''' – Use to encrypt string using specific algorithm, encoding, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	encrypt(string, key[, algorithm[, encoding[, IVorSalt[, iterations]]]]))'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''EncryptBinary''' – Use to encrypt binary data with specified key, algorithm, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	encryptBinary(bytes, key[, algorithm[, IVorSalt[, iterations]]])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GenerateSecretKey''' – Use to generate a secure key using the specified algorithm for the encrypt and encryptBinary functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	generateSecretKey(algorithm)'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Hash '''– Use for one-way conversion of a variable-length string to fixed-length string using the specified algorithm and encoding&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	hash(string[, algorithm[, encoding]] )'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion offers the following default algorithms for these functions''' ''':&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: the algorithm used in ColdFusion MX and prior releases. This algorithm is the least secure option (default). &lt;br /&gt;
&lt;br /&gt;
AES: the Advanced Encryption Standard specified by the National Institute of Standards and Technology (NIST) FIPS-197. (recommended)&lt;br /&gt;
&lt;br /&gt;
BLOWFISH: the Blowfish algorithm defined by Bruce Schneier. &lt;br /&gt;
&lt;br /&gt;
DES: the Data Encryption Standard algorithm defined by NIST FIPS-46-3. &lt;br /&gt;
&lt;br /&gt;
DESEDE: the &amp;quot;Triple DES&amp;quot; algorithm defined by NIST FIPS-46-3. &lt;br /&gt;
&lt;br /&gt;
PBEWithMD5AndDES: A password-based version of the DES algorithm which uses a MD5 hash of the specified password as the encryption key &lt;br /&gt;
&lt;br /&gt;
PBEWithMD5AndTripleDES: A password-based version of the DESEDE algorithm which uses a MD5 hash of the specified password as the encryption key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following algorithms are provided by default for the hash() function. Note, SHA algorithms used in ColdFusion are NIST FIPS-180-2 compliant''' ''':&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: Generates a MD5 hash string identical to that generated by ColdFusion MX and ColdFusion MX 6.1 (default). &lt;br /&gt;
&lt;br /&gt;
MD5: Generates a 128-bit digest.&lt;br /&gt;
&lt;br /&gt;
SHA: Generates a 160-bit digest. (SHA-1)&lt;br /&gt;
&lt;br /&gt;
SHA-256: Generates a 256-bit digest&lt;br /&gt;
&lt;br /&gt;
SHA-384: Generates a 384-bit digest&lt;br /&gt;
&lt;br /&gt;
SHA-512: Generates a 512-bit digest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pluggable Encryption'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion MX 7 introduced pluggable encryption for CFML. The JCE allows developers to specify multiple cryptographic service providers. ColdFusion can leverage the algorithms, feedback modes, and padding methods of third-party Java security providers to strengthen its cryptography functions. For example, ColdFusion can leverage the Bouncy Castle ('''&amp;lt;u&amp;gt;http://www.bouncycastle.org/'''&amp;lt;/u&amp;gt;) crypto package and use the SHA-224 algorithm for the hash() function or the Serpent block encryption for the encrypt() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See Macromedia’s Strong Encryption in ColdFusion MX 7 technote for information on installing additional security providers for ColdFusion at http://www.macromedia.com/go/e546373d. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SSL'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion does not provide tags and functions for public-key encryption, but it can communicate over SSL. ColdFusion leverages the Sun JSSE to communicate over SSL with web and LDAP (lightweight directory access protocol) servers. ColdFusion uses the Java certificate database (e.g. jre_root/lib/security/cacerts) to store server certificates. It compares presented certificate of remote systems to those stored in the database. It also grabs the host system’s certificate from this database and uses it to present to remote systems to initiate the SSL handshake. Certificate information is then exposed as CGI variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Best Practices'''''&lt;br /&gt;
&lt;br /&gt;
Enable /dev/urandom for higher entropy for random number generation&lt;br /&gt;
&lt;br /&gt;
Call the randomize function before calling rand() or randRange() to seed the random number generator&lt;br /&gt;
&lt;br /&gt;
DO NOT use the CFMX_COMPAT algorithms. Upgrade your application to use stronger cryptographic ciphers.&lt;br /&gt;
&lt;br /&gt;
Use AES or higher for symmetric encryption &lt;br /&gt;
&lt;br /&gt;
Use SHA-256 or higher for the hash function&lt;br /&gt;
&lt;br /&gt;
Use a salt (or random string) for password generation with the hash function&lt;br /&gt;
&lt;br /&gt;
Always use generateSecretKey() to generate keys of the appropriate length for Block Encryption algorithms unless a customized key is required&lt;br /&gt;
&lt;br /&gt;
Use separate key databases to store remote server certificates separately from the ColdFusion server’s certificate&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Encryption]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Error_Handling,_Auditing_and_Logging&amp;diff=35868</id>
		<title>Error Handling, Auditing and Logging</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Error_Handling,_Auditing_and_Logging&amp;diff=35868"/>
				<updated>2008-08-12T12:44:52Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: /* Error Handling */ spelling/grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
Many industries are required by legal and regulatory requirements to be:&lt;br /&gt;
&lt;br /&gt;
* Auditable – all activities that affect user state or balances are formally tracked&lt;br /&gt;
&lt;br /&gt;
* Traceable – it’s possible to determine where an activity occurs in all tiers of the application&lt;br /&gt;
&lt;br /&gt;
* High integrity – logs cannot be overwritten or tampered by local or remote users&lt;br /&gt;
&lt;br /&gt;
Well-written applications will dual-purpose logs and activity traces for audit and monitoring, and make it easy to track a transaction without excessive effort or access to the system. They should possess the ability to easily track or identify potential fraud or anomalies end-to-end. &lt;br /&gt;
&lt;br /&gt;
==Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS11 – Manage Data – All sections should be reviewed, but in particular:&lt;br /&gt;
&lt;br /&gt;
DS11.4 Source data error handling&lt;br /&gt;
&lt;br /&gt;
DS11.8 Data input error handling&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Error handling, debug messages, auditing and logging are different aspects of the same topic: how to track events within an application:&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Best practices ==&lt;br /&gt;
&lt;br /&gt;
* Fail safe – do not fail open&lt;br /&gt;
&lt;br /&gt;
* Dual purpose logs&lt;br /&gt;
&lt;br /&gt;
* Audit logs are legally protected – protect them&lt;br /&gt;
&lt;br /&gt;
* Reports and search logs using a read-only copy or complete replica &lt;br /&gt;
&lt;br /&gt;
==Error Handling ==&lt;br /&gt;
&lt;br /&gt;
Error handling takes two forms: structured exception handling and functional error checking. Structured exception handling is always preferred as it is easier to cover 100% of code. Functional languages, such as PHP 4, that do not have exceptions are very hard to cover 100% of all errors. Code that covers 100% of errors is extraordinarily verbose and difficult to read, and can contain subtle bugs and errors in the error handling code itself.&lt;br /&gt;
&lt;br /&gt;
Motivated attackers like to see error messages as they might leak information that leads to further attacks, or may leak privacy related information. Web application error handling is rarely robust enough to survive a penetration test. &lt;br /&gt;
&lt;br /&gt;
Applications should always fail safe. If an application fails to an unknown state, it is likely that an attacker may be able to exploit this indeterminate state to access unauthorized functionality, or worse create, modify or destroy data.&lt;br /&gt;
&lt;br /&gt;
===Fail safe ===&lt;br /&gt;
&lt;br /&gt;
* Inspect the application’s fatal error handler.&lt;br /&gt;
&lt;br /&gt;
* Does it fail safe? If so, how?&lt;br /&gt;
&lt;br /&gt;
* Is the fatal error handler called frequently enough?&lt;br /&gt;
&lt;br /&gt;
* What happens to in-flight transactions and ephemeral data?&lt;br /&gt;
&lt;br /&gt;
===Debug errors ===&lt;br /&gt;
&lt;br /&gt;
* Does production code contain debug error handlers or messages?  &lt;br /&gt;
&lt;br /&gt;
* If the language is a scripting language without effective pre-processing or compilation, can the debug flag be turned on in the browser?&lt;br /&gt;
&lt;br /&gt;
* Do the debug messages leak privacy related information, or information that may lead to further successful attack?&lt;br /&gt;
&lt;br /&gt;
===Exception handling ===&lt;br /&gt;
&lt;br /&gt;
* Does the code use structured exception handlers (try {} catch {} etc) or function-based error handling? &lt;br /&gt;
&lt;br /&gt;
* If the code uses function-based error handling, does it check every return value and handle the error appropriately?&lt;br /&gt;
&lt;br /&gt;
* Would fuzz injection against the average interface fail? &lt;br /&gt;
&lt;br /&gt;
===Functional return values ===&lt;br /&gt;
&lt;br /&gt;
Many languages indicate an error condition by return value. E.g.:&lt;br /&gt;
&lt;br /&gt;
''$query = mysql_query(“SELECT * FROM table WHERE id=4”, $conn);''&lt;br /&gt;
&lt;br /&gt;
''if ( $query === false ) {''&lt;br /&gt;
&lt;br /&gt;
''		// error''&lt;br /&gt;
&lt;br /&gt;
''} ''&lt;br /&gt;
&lt;br /&gt;
* Are all functional errors checked? If not, what can go wrong?&lt;br /&gt;
&lt;br /&gt;
==Detailed error messages ==&lt;br /&gt;
&lt;br /&gt;
Detailed error messages provide attackers with a mountain of useful information.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable  ===&lt;br /&gt;
&lt;br /&gt;
* Are detailed error messages turned on? &lt;br /&gt;
&lt;br /&gt;
* Do the detailed error messages leak information that may be used to stage a further attack, or leak privacy related information? &lt;br /&gt;
&lt;br /&gt;
* Does the browser cache the error message?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Ensure that your application has a “safe mode” which it can return if something truly unexpected occurs. If all else fails, log the user out and close the browser window&lt;br /&gt;
&lt;br /&gt;
Production code should not be capable of producing debug messages. If it does, debug mode should be triggered by editing a file or configuration option on the server. In particular, debug should not enabled by an option in the application itself&lt;br /&gt;
&lt;br /&gt;
If the framework or language has a structured exception handler (ie try {} catch {}), it should be used in preference to functional error handling&lt;br /&gt;
&lt;br /&gt;
If the application uses functional error handling, its use must be comprehensive and thorough&lt;br /&gt;
&lt;br /&gt;
Detailed error messages, such as stack traces or leaking privacy related information, should never be presented to the user. Instead a generic error message should be used. This includes HTTP status response codes (ie 404 or 500 Internal Server error). &lt;br /&gt;
&lt;br /&gt;
==Logging ==&lt;br /&gt;
&lt;br /&gt;
===Where to log to? ===&lt;br /&gt;
&lt;br /&gt;
Logs should be written so that the log file attributes are such that only new information can be written (older records cannot be rewritten or deleted). For added security, logs should also be written to a write once / read many device such as a CD-R.&lt;br /&gt;
&lt;br /&gt;
Copies of log files should be made at regular intervals depending on volume and size (daily, weekly, monthly, etc.). .). A common naming convention should be adopted with regards to logs, making them easier to index. Verification that logging is still actively working is overlooked surprisingly often, and can be accomplished via a simple cron job!&lt;br /&gt;
&lt;br /&gt;
Make sure data is not overwritten.&lt;br /&gt;
&lt;br /&gt;
Log files should be copied and moved to permanent storage and incorporated into the organization's overall backup strategy.&lt;br /&gt;
&lt;br /&gt;
Log files and media should be deleted and disposed of properly and incorporated into an organization's shredding or secure media disposal plan. Reports should be generated on a regular basis, including error reporting and anomaly detection trending.&lt;br /&gt;
&lt;br /&gt;
Be sure to keep logs safe and confidential even when backed up.&lt;br /&gt;
&lt;br /&gt;
===Handling ===&lt;br /&gt;
&lt;br /&gt;
Logs can be fed into real time intrusion detection and performance and system monitoring tools. All logging components should be synced with a timeserver so that all logging can be consolidated effectively without latency errors. This time server should be hardened and should not provide any other services to the network.&lt;br /&gt;
&lt;br /&gt;
No manipulation, no deletion while analyzing.&lt;br /&gt;
&lt;br /&gt;
===General Debugging ===&lt;br /&gt;
&lt;br /&gt;
Logs are useful in reconstructing events after a problem has occurred, security related or not. Event reconstruction can allow a security administrator to determine the full extent of an intruder's activities and expedite the recovery process.&lt;br /&gt;
&lt;br /&gt;
===Forensics evidence ===&lt;br /&gt;
&lt;br /&gt;
Logs may in some cases be needed in legal proceedings to prove wrongdoing. In this case, the actual handling of the log data is crucial.&lt;br /&gt;
&lt;br /&gt;
===Attack detection ===&lt;br /&gt;
&lt;br /&gt;
Logs are often the only record that suspicious behavior is taking place: Therefore logs can sometimes be fed real-time directly into intrusion detection systems.&lt;br /&gt;
&lt;br /&gt;
===Quality of service ===&lt;br /&gt;
&lt;br /&gt;
Repetitive polls can be protocol led so that network outages or server shutdowns get protocolled and the behavior can either be analyzed later on or a responsible person can take immediate actions.&lt;br /&gt;
&lt;br /&gt;
===Proof of validity ===&lt;br /&gt;
&lt;br /&gt;
Application developers sometimes write logs to prove to customers that their applications are behaving as expected.&lt;br /&gt;
&lt;br /&gt;
* Required by law or corporate policies&lt;br /&gt;
&lt;br /&gt;
* Logs can provide individual accountability in the web application system universe by tracking a user's actions.&lt;br /&gt;
&lt;br /&gt;
It can be corporate policy or local law to be required to (as example) save header information of all application transactions. These logs must then be kept safe and confidential for six months before they can be deleted.&lt;br /&gt;
&lt;br /&gt;
The points from above show all different motivations and result in different requirements and strategies. This means, that before we can implement a logging mechanism into an application or system, we have to know the requirements and their later usage. If we fail in doing so this can lead to unintentional results.&lt;br /&gt;
&lt;br /&gt;
Failure to enable or design the proper event logging mechanisms in the web application may undermine an organization's ability to detect unauthorized access attempts, and the extent to which these attempts may or may not have succeeded. We will look into the most common attack methods, design and implementation errors as well as the mitigation strategies later on in this chapter.&lt;br /&gt;
&lt;br /&gt;
There is another reason why the logging mechanism must be planned before implementation. In some countries, laws define what kind of personal information is allowed to be not only logged but also analyzed. For example, in Switzerland, companies are not allowed to log personal information of their employees (like what they do on the internet or what they write in their emails). So if a company wants to log a workers surfing habits, the corporation needs to inform her of their plans in advance.&lt;br /&gt;
&lt;br /&gt;
This leads to the requirement of having anonymized logs or de-personalized logs with the ability to re-personalized them later on if need be. If an unauthorized person has access to (legally) personalized logs, the corporation is acting unlawful again. So there can be a few (not only) legal traps that must be kept in mind.&lt;br /&gt;
&lt;br /&gt;
===Logging types ===&lt;br /&gt;
&lt;br /&gt;
Logs can contain different kinds of data. The selection of the data used is normally affected by the motivation leading to the logging. This section contains information about the different types of logging information and the reasons why we could want to log them.&lt;br /&gt;
&lt;br /&gt;
In general, the logging features include appropriate debugging information’s such as time of event, initiating process or owner of process, and a detailed description of the event. The following are types of system events that can be logged in an application. It depends on the particular application or system and the needs to decide which of these will be used in the logs:&lt;br /&gt;
&lt;br /&gt;
* Reading of data file access and what kind of data is read. This not only allows to see if data was read but also by whom and when.&lt;br /&gt;
&lt;br /&gt;
* Writing of data logs also where and with what mode (append, replace) data was written. This can be used to see if data was overwritten or if a program is writing at all.&lt;br /&gt;
&lt;br /&gt;
* Modification of any data characteristics, including access control permissions or labels, location in database or file system, or data ownership. Administrators can detect if their configurations were changed.&lt;br /&gt;
&lt;br /&gt;
* Administrative functions and changes in configuration regardless of overlap (account management actions, viewing any user's data, enabling or disabling logging, etc.)&lt;br /&gt;
&lt;br /&gt;
* Miscellaneous debugging information that can be enabled or disabled on the fly.&lt;br /&gt;
&lt;br /&gt;
* All authorization attempts (include time) like success/failure, resource or function being authorized, and the user requesting authorization. We can detect password guessing with these logs. These kinds of logs can be fed into an Intrusion Detection system that will detect anomalies.&lt;br /&gt;
&lt;br /&gt;
* Deletion of any data (object). Sometimes applications are required to have some sort of versioning in which the deletion process can be cancelled.&lt;br /&gt;
&lt;br /&gt;
* Network communications (bind, connect, accept, etc.). With this information an Intrusion Detection system can detect port scanning and brute force attacks.&lt;br /&gt;
&lt;br /&gt;
* All authentication events (logging in, logging out, failed logins, etc.) that allow to detect brute force and guessing attacks too.&lt;br /&gt;
&lt;br /&gt;
==Noise ==&lt;br /&gt;
&lt;br /&gt;
Intentionally invoking security errors to fill an error log with entries (noise) that hide the incriminating evidence of a successful intrusion. When the administrator or log parser application reviews the logs, there is every chance that they will summarize the volume of log entries as a denial of service attempt rather than identifying the 'needle in the haystack'.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
This is difficult since applications usually offer an unimpeded route to functions capable of generating log events. If you can deploy an intelligent device or application component that can shun an attacker after repeated attempts, then that would be beneficial. Failing that, an error log audit tool that can reduce the bulk of the noise, based on repetition of events or originating from the same source for example. It is also useful if the log viewer can display the events in order of severity level, rather than just time based.&lt;br /&gt;
&lt;br /&gt;
==Cover Tracks ==&lt;br /&gt;
&lt;br /&gt;
The top prize in logging mechanism attacks goes to the contender who can delete or manipulate log entries at a granular level, &amp;quot;as though the event never even happened!&amp;quot;. Intrusion and deployment of rootkits allows an attacker to utilize specialized tools that may assist or automate the manipulation of known log files. In most cases, log files may only be manipulated by users with root / administrator privileges, or via approved log manipulation applications. As a general rule, logging mechanisms should aim to prevent manipulation at a granular level since an attacker can hide their tracks for a considerable length of time without being detected. Simple question; if you were being compromised by an attacker, would the intrusion be more obvious if your log file was abnormally large or small, or if it appeared like every other day's log?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Assign log files the highest security protection, providing reassurance that you always have an effective 'black box' recorder if things go wrong. This includes:&lt;br /&gt;
&lt;br /&gt;
Applications should not run with Administrator, or root-level privileges. This is the main cause of log file manipulation success since super users typically have full file system access. Assume the worst case scenario and suppose your application is exploited. Would there be any other security layers in place to prevent the application's user privileges from manipulating the log file to cover tracks?&lt;br /&gt;
&lt;br /&gt;
Ensuring that access privileges protecting the log files are restrictive, reducing the majority of operations against the log file to alter and read.&lt;br /&gt;
&lt;br /&gt;
Ensuring that log files are assigned object names that are not obvious and stored in a safe location of the file system.&lt;br /&gt;
&lt;br /&gt;
Writing log files using publicly or formally scrutinized techniques in an attempt to reduce the risk associated with reverse engineering or log file manipulation.&lt;br /&gt;
&lt;br /&gt;
Writing log files to read-only media (where event log integrity is of critical importance).&lt;br /&gt;
&lt;br /&gt;
Use of hashing technology to create digital fingerprints. The idea being that if an attacker does manipulate the log file, then the digital fingerprint will not match and an alert generated.&lt;br /&gt;
&lt;br /&gt;
Use of host-based IDS technology where normal behavioral patterns can be 'set in stone'. Attempts by attackers to update the log file through anything but the normal approved flow would generate an exception and the intrusion can be detected and blocked. This is one security control that can safeguard against simplistic administrator attempts at modifications.&lt;br /&gt;
&lt;br /&gt;
==False Alarms ==&lt;br /&gt;
&lt;br /&gt;
Taking cue from the classic 1966 film &amp;quot;How to Steal a Million&amp;quot;, or similarly the fable of Aesop; &amp;quot;The Boy Who Cried Wolf&amp;quot;, be wary of repeated false alarms, since this may represent an attacker's actions in trying to fool the security administrator into thinking that the technology is faulty and not to be trusted until it can be fixed.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Simply be aware of this type of attack, take every security violation seriously, always get to the bottom of the cause event log errors rather, and don't just dismiss errors unless you can be completely sure that you know it to be a technical problem.&lt;br /&gt;
&lt;br /&gt;
===Denial of Service ===&lt;br /&gt;
&lt;br /&gt;
By repeatedly hitting an application with requests that cause log entries, multiply this by ten thousand, and the result is that you have a large log file and a possible headache for the security administrator. Where log files are configured with a fixed allocation size, then once full, all logging will stop and an attacker has effectively denied service to your logging mechanism. Worse still, if there is no maximum log file size, then an attacker has the ability to completely fill the hard drive partition and potentially deny service to the entire system. This is becoming more of a rarity though with the increasing size of today's hard disks.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
The main defense against this type of attack are to increase the maximum log file size to a value that is unlikely to be reached, place the log file on a separate partition to that of the operating system or other critical applications and best of all, try to deploy some kind of system monitoring application that can set a threshold against your log file size and/or activity and issue an alert if an attack of this nature is underway.&lt;br /&gt;
&lt;br /&gt;
==Destruction ==&lt;br /&gt;
&lt;br /&gt;
Following the same scenario as the Denial of Service above, if a log file is configured to cycle round overwriting old entries when full, then an attacker has the potential to do the evil deed and then set a log generation script into action in an attempt to eventually overwrite the incriminating log entries, thus destroying them.&lt;br /&gt;
&lt;br /&gt;
If all else fails, then an attacker may simply choose to cover their tracks by purging all log file entries, assuming they have the privileges to perform such actions. This attack would most likely involve calling the log file management program and issuing the command to clear the log, or it may be easier to simply delete the object which is receiving log event updates (in most cases, this object will be locked by the application). This type of attack does make an intrusion obvious assuming that log files are being regularly monitored, and does have a tendency to cause panic as system administrators and managers realize they have nothing upon which to base an investigation on.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Following most of the techniques suggested above will provide good protection against this attack. Keep in mind two things:&lt;br /&gt;
&lt;br /&gt;
Administrative users of the system should be well trained in log file management and review. 'Ad-hoc' clearing of log files is never advised and an archive should always be taken. Too many times a log file is cleared, perhaps to assist in a technical problem, erasing the history of events for possible future investigative purposes.&lt;br /&gt;
&lt;br /&gt;
An empty security log does not necessarily mean that you should pick up the phone and fly the forensics team in. In some cases, security logging is not turned on by default and it is up to you to make sure that it is. Also, make sure it is logging at the right level of detail and benchmark the errors against an established baseline in order measure what is considered 'normal' activity.&lt;br /&gt;
&lt;br /&gt;
==Audit Trails ==&lt;br /&gt;
&lt;br /&gt;
Audit trails are legally protected in many countries, and should be logged into high integrity destinations to prevent casual and motivated tampering and destruction. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Do the logs transit in the clear between the logging host and the destination?&lt;br /&gt;
&lt;br /&gt;
* Do the logs have a HMAC or similar tamper proofing mechanism to prevent change from the time of the logging activity to when it is reviewed?&lt;br /&gt;
&lt;br /&gt;
* Can relevant logs be easily extracted in a legally sound fashion to assist with prosecutions?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Only audit truly important events – you have to keep audit trails for a long time, and debug or informational messages are wasteful&lt;br /&gt;
&lt;br /&gt;
* Log centrally as appropriate and ensure primary audit trails are not kept on vulnerable systems, particularly front end web servers&lt;br /&gt;
&lt;br /&gt;
* Only review copies of the logs, not the actual logs themselves&lt;br /&gt;
&lt;br /&gt;
* Ensure that audit logs are sent to trusted systems&lt;br /&gt;
&lt;br /&gt;
* For highly protected systems, use write-once media or similar to provide trust worthy long term log repositories&lt;br /&gt;
&lt;br /&gt;
* For highly protected systems, ensure there is end-to-end trust in the logging mechanism. World writeable logs, logging agents without credentials (such as SNMP traps, syslog etc) are legally vulnerable to being excluded from prosecution &lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* Oracle Auditing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.sans.org/atwork/description.php?cid=738&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Sarbanes Oxley for IT security&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.securityfocus.com/columnists/322&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Java Logging Overview&lt;br /&gt;
&amp;lt;u&amp;gt;http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Error Handling and Logging ==&lt;br /&gt;
&lt;br /&gt;
All applications have failures – whether they occur during compilation or runtime. Most programming languages will throw runtime exceptions for illegally executing code (e.g. syntax errors) often in the form of cryptic system messages. These failures and resulting system messages can lead to several security risks if not handled properly including; enumeration, buffer attacks, sensitive information disclosure, etc.  If an attack occurs it is important that forensics personnel be able to trace the attacker’s tracks via adequate logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides structured exception handling and logging tools. These tools can help developers customize error handling to prevent unwanted disclosure, and provide customized logging for error tracking and audit trails. These tools should be combined with web server, J2EE application server, and operating system tools to create the full system/application security overview.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Error Handling'''&lt;br /&gt;
&lt;br /&gt;
Hackers can use the information exposed by error messages. Even missing templates errors (HTTP 404) can expose your server to attacks (e.g. buffer overflow, XSS, etc.). If you enable the Robust Exception Information debugging option, ColdFusion will display:&lt;br /&gt;
&lt;br /&gt;
Physical path of template &lt;br /&gt;
&lt;br /&gt;
URI of template &lt;br /&gt;
&lt;br /&gt;
Line number and line snippet &lt;br /&gt;
&lt;br /&gt;
SQL statement used (if any) &lt;br /&gt;
&lt;br /&gt;
Data source name (if any) &lt;br /&gt;
&lt;br /&gt;
Java stack trace&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides tags and functions for developers to use to customize error handling. Administrators can specify default templates in the ColdFusion Administrator (CFAM) to handle unknown or unhandled exceptions. ColdFusion’s structure exception handling works in the following order:&lt;br /&gt;
&lt;br /&gt;
Template level (ColdFusion templates and components)&lt;br /&gt;
&lt;br /&gt;
ColdFusion exception handling tags: cftry, cfcatch, cfthrow, and cfrethrow&lt;br /&gt;
&lt;br /&gt;
try and catch statements in CFScript&lt;br /&gt;
&lt;br /&gt;
Application level (Application.cfc/cfm)&lt;br /&gt;
&lt;br /&gt;
Specify custom templates for individual exceptions types with the cferror tag&lt;br /&gt;
&lt;br /&gt;
Application.cfc onError method to handle uncaught application exceptions&lt;br /&gt;
&lt;br /&gt;
System level (ColdFusion Administrator settings)&lt;br /&gt;
&lt;br /&gt;
Missing Template Handler execute when a requested ColdFusion template is not found&lt;br /&gt;
&lt;br /&gt;
Site-wide Error Handler executes globally for all unhandled exceptions on the server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Best Practices '''&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to go unhandled&lt;br /&gt;
&lt;br /&gt;
Do not allow any exceptions to reach the browser&lt;br /&gt;
&lt;br /&gt;
Display custom error pages to users with an email link for feedback&lt;br /&gt;
&lt;br /&gt;
Do not enable “Robust Exception Information” in production.&lt;br /&gt;
&lt;br /&gt;
Specify custom pages for ColdFusion to display in each of the following cases: &lt;br /&gt;
&lt;br /&gt;
When a ColdFusion page is missing (the Missing Template Handler page) &lt;br /&gt;
&lt;br /&gt;
When an otherwise-unhandled exception error occurs during the processing of a page (the Site-wide Error Handler page) &lt;br /&gt;
&lt;br /&gt;
You specify these pages on the Settings page in the Server Settings are in the ColdFusion MX Administrator; for more information, see the ColdFusion MX Administrator Help.&lt;br /&gt;
&lt;br /&gt;
Use the cferror tag to specify ColdFusion pages to handle specific types of errors. &lt;br /&gt;
&lt;br /&gt;
Use the cftry, cfcatch, cfthrow, and cfrethrow tags to catch and handle exception errors directly on the page where they occur. &lt;br /&gt;
&lt;br /&gt;
In CFScript, use the try and catch statements to handle exceptions. &lt;br /&gt;
&lt;br /&gt;
Use the onError event in Application.cfc to handle exception errors that are not handled by try/catch code on the application pages. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Logging'''&lt;br /&gt;
&lt;br /&gt;
Log files can help with application debugging and provide audit trails for attack detection. ColdFusion provides several logs for different server functions. It leverages the Apache Log4j libraries for customized logging. It also provides logging tags to assist in application debugging. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a partial list of ColdFusion log files and their descriptions''' '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
&lt;br /&gt;
 || Log file  || Description &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || application.log || Records every ColdFusion MX error reported to a user. Application page errors, including ColdFusion MX syntax, ODBC, and SQL errors, are written to this log file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || exception.log  || Records stack traces for exceptions that occur in ColdFusion.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || scheduler.log || Records scheduled events that have been submitted for execution. Indicates whether task submission was initiated and whether it succeeded. Provides the scheduled page URL, the date and time executed, and a task ID.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || server.log || Records start up messages and errors for ColdFusion MX.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || customtag.log || Records errors generated in custom tag processing.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || mail.log || Records errors generated by an SMTP mail server.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || mailsent.log || Records messages sent by ColdFusion MX.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || flash.log || Records entries for Macromedia Flash Remoting.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CFAM contains the Logging Settings and log viewer screens. Administrators can configure the log directory, maximum log file size, and maximum number of archives. It also allows administrators to log slow running pages, CORBA calls, and scheduled task execution. The log viewer allows viewing, filtering, and searching of any log files in the log directory (default is cf_root/logs). Administrators can archive, save, and delete log files as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The cflog and cftrace tags allow developer to create customized logging. &amp;lt;cflog&amp;gt; can write custom messages to the Application.log, Scheduler.log, or a custom log file. The custom log file must be in the default log directory – if it does not exist ColdFusion will create it. &amp;lt;cftrace&amp;gt; tracks execution times, logic flow, and variable at the time the tag executes. It records the data in the cftrace.log (in the default logs directory) and can display this info either inline or in the debugging output of the current page request. Use &amp;lt;cflog&amp;gt; to write custom error messages, track user logins, and record user activity to a custom log file.  Use &amp;lt;cftrace&amp;gt; to track variables and application state within running requests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Best Practices'''&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;cflog&amp;gt; for customized logging&lt;br /&gt;
&lt;br /&gt;
Incorporate into custom error handling&lt;br /&gt;
&lt;br /&gt;
Record application specific messages&lt;br /&gt;
&lt;br /&gt;
Actively monitor and fix errors in ColdFusion’s logs&lt;br /&gt;
&lt;br /&gt;
Optimize logging settings &lt;br /&gt;
&lt;br /&gt;
Rotate log files to keep them current &lt;br /&gt;
&lt;br /&gt;
Keep files size manageable&lt;br /&gt;
&lt;br /&gt;
Enable logging of slow running pages&lt;br /&gt;
&lt;br /&gt;
Set the time interval lower than the configured Timeout Request value in the CFAM Settings screen&lt;br /&gt;
&lt;br /&gt;
Long running page timings are recorded in the server.log&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;cftrace&amp;gt; sparingly for audit trails&lt;br /&gt;
&lt;br /&gt;
Use with inline=“false”&lt;br /&gt;
&lt;br /&gt;
Use it to track user input – Form and/or URL variables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Best Practices in Action'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following code adds error handling and logging to the dbLogin and logout methods in the code from Authentication section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
&lt;br /&gt;
 ||&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;dblogin&amp;quot; access=&amp;quot;private&amp;quot; output=&amp;quot;false&amp;quot; returntype=&amp;quot;struct&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strUserName&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strPassword&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset var retargs = StructNew()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif IsValid(&amp;quot;regex&amp;quot;, uUserName, &amp;quot;[A-Za-z0-9%]*&amp;quot;) AND IsValid(&amp;quot;regex&amp;quot;, uPassword, &amp;quot;[A-Za-z0-9%]*&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfquery name=&amp;quot;loginQuery&amp;quot; dataSource=&amp;quot;#Application.DB#&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
		SELECT hashed_password, salt&lt;br /&gt;
&lt;br /&gt;
		FROM UserTable&lt;br /&gt;
&lt;br /&gt;
		WHERE UserName =&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfqueryparam value=&amp;quot;#strUserName#&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; maxlength=&amp;quot;25&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfquery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfif loginQuery.hashed_password EQ Hash(strPassword &amp;amp; loginQuery.salt, &amp;quot;SHA-256&amp;quot; )&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;YES&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset Session.UserName = strUserName&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cflog text=&amp;quot;#getAuthUser()# has logged in!&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		  	type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;!-- Add code to get roles from database --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfcatch type=&amp;quot;database&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  	&amp;lt;cflog text=&amp;quot;Error in dbLogin(). #cfcatch.details#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	  		type=&amp;quot;Error&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			log=&amp;quot;Application&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfcatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;logout&amp;quot; access=&amp;quot;remote&amp;quot; output=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;logintype&amp;quot; type=&amp;quot;string&amp;quot; required=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif isDefined(&amp;quot;form.logout&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflogout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset StructClear(Session)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;cflog text=&amp;quot;#getAuthUser()# has been logged out.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		application=&amp;quot;yes&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif arguments.logintype eq &amp;quot;challenge&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset foo = closeBrowser()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--- replace this URL to a page logged out users should see ---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflocation url=&amp;quot;login.cfm&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;dblogin&amp;quot; access=&amp;quot;private&amp;quot; output=&amp;quot;false&amp;quot; returntype=&amp;quot;struct&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strUserName&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strPassword&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset var retargs = StructNew()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif IsValid(&amp;quot;regex&amp;quot;, uUserName, &amp;quot;[A-Za-z0-9%]*&amp;quot;) AND IsValid(&amp;quot;regex&amp;quot;, uPassword, &amp;quot;[A-Za-z0-9%]*&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfquery name=&amp;quot;loginQuery&amp;quot; dataSource=&amp;quot;#Application.DB#&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
		SELECT hashed_password, salt&lt;br /&gt;
&lt;br /&gt;
		FROM UserTable&lt;br /&gt;
&lt;br /&gt;
		WHERE UserName =&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfqueryparam value=&amp;quot;#strUserName#&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; maxlength=&amp;quot;25&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfquery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfif loginQuery.hashed_password EQ Hash(strPassword &amp;amp; loginQuery.salt, &amp;quot;SHA-256&amp;quot; )&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;YES&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset Session.UserName = strUserName&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cflog text=&amp;quot;#getAuthUser()# has logged in!&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		  	type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;!-- Add code to get roles from database --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfcatch type=&amp;quot;database&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  	&amp;lt;cflog text=&amp;quot;Error in dbLogin(). #cfcatch.details#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	  		type=&amp;quot;Error&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			log=&amp;quot;Application&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfcatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;logout&amp;quot; access=&amp;quot;remote&amp;quot; output=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;logintype&amp;quot; type=&amp;quot;string&amp;quot; required=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif isDefined(&amp;quot;form.logout&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflogout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset StructClear(Session)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflog text=&amp;quot;#getAuthUser()# has been logged out.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		application=&amp;quot;yes&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif arguments.logintype eq &amp;quot;challenge&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset foo = closeBrowser()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--- replace this URL to a page logged out users should see ---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflocation url=&amp;quot;login.cfm&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Error Handling]]&lt;br /&gt;
[[Category:Logging]]&lt;br /&gt;
[[Category:OWASP Logging Project]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Canonicalization,_locale_and_Unicode&amp;diff=35860</id>
		<title>Canonicalization, locale and Unicode</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Canonicalization,_locale_and_Unicode&amp;diff=35860"/>
				<updated>2008-08-12T12:18:58Z</updated>
		
		<summary type="html">&lt;p&gt;Joern.zaefferer: /* Description */ grammar mistake&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
To ensure the application is robust when subjected to encoded, internationalized and Unicode input. &lt;br /&gt;
&lt;br /&gt;
==Platforms Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS11.9 – Data processing integrity&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Applications are rarely tested for Unicode exploits, and yet many are vulnerable due to the same sort of issues which allows HTTP Request Smuggling to work – every browser, web server, web application firewall or HTTP inspection agent, and other device treats user locale handling in different (and usually confusing) manner. &lt;br /&gt;
&lt;br /&gt;
Canonicalization deals with the way in which systems convert data from one form to another. Canonical means the simplest or most standard form of something. Canonicalization is the process of converting something from one representation to the simplest form. &lt;br /&gt;
&lt;br /&gt;
Web applications have to deal with lots of canonicalization issues from URL encoding to IP address translation. When security decisions are made based on less than perfectly canonicalized data, the application itself must be able to deal with unexpected input safely. &lt;br /&gt;
&lt;br /&gt;
'''NB: To be secure against canonicalization attacks does not mean that every application has to be internationalized, but all applications should be safe when Unicode and malformed representations are entered. '''&lt;br /&gt;
&lt;br /&gt;
==Unicode ==&lt;br /&gt;
&lt;br /&gt;
Unicode Encoding is a method for storing characters with multiple bytes. Wherever input data is allowed, data can be entered using Unicode to disguise malicious code and permit a variety of attacks. RFC 2279 references many ways that text can be encoded.&lt;br /&gt;
&lt;br /&gt;
Unicode was developed to allow a Universal Character Set (UCS) that encompasses most of the world's writing systems. Multi-octet characters, however, are not compatible with many current applications and protocols, and this has led to the development of a few UCS transformation formats (UTF) with varying characteristics. UTF-8 has the characteristic of preserving the full US-ASCII range. It is compatible with file systems, parsers and other software relying on US-ASCII values, but it is transparent to other values.&lt;br /&gt;
&lt;br /&gt;
The importance of UTF-8 representation stems from the fact that web-servers/applications perform several steps on their input of this format. The order of the steps is sometimes critical to the security of the application. Basically, the steps are &amp;quot;URL decoding&amp;quot; potentially followed by &amp;quot;UTF-8 decoding&amp;quot;, and intermingled with them are various security checks, which are also processing steps.&lt;br /&gt;
&lt;br /&gt;
If, for example, one of the security checks is searching for &amp;quot;..&amp;quot;, and it is carried out before UTF-8 decoding takes place, it is possible to inject &amp;quot;..&amp;quot; in their overlong UTF-8 format. Even if the security checks recognize some of the non-canonical format for dots, it may still be that not all formats are known to it. &lt;br /&gt;
&lt;br /&gt;
Consider the ASCII character &amp;quot;.&amp;quot; (dot). Its canonical representation is a dot (ASCII 2E). Yet if we think of it as a character in the second UTF-8 range (2 bytes), we get an overlong representation of it, as C0 AE. Likewise, there are more overlong representations: E0 80 AE, F0 80 80 AE, F8 80 80 80 AE and FC 80 80 80 80 AE.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
&lt;br /&gt;
 || UCS-4 Range || UTF-8 Encoding&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000000-0x0000007F'' || ''0xxxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000080 - 0x000007FF'' || ''110xxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000800-0x0000FFFF'' || ''1110xxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00010000-0x001FFFFF'' || ''11110xxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00200000-0x03FFFFFF'' || ''111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x04000000-0x7FFFFFFF'' || ''1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consider the representation C0 AE of a &amp;quot;.&amp;quot;. Like UTF-8 encoding requires, the second octet has &amp;quot;10&amp;quot; as its two most significant bits. Now, it is possible to define 3 variants for it, by enumerating the rest of the possible 2 bit combinations (&amp;quot;00&amp;quot;, &amp;quot;01&amp;quot; and &amp;quot;11&amp;quot;). Some UTF-8 decoders would treat these variants as identical to the original symbol (they simply use the least significant 6 bits, disregarding the most significant 2 bits). Thus, the 3 variants are C0 2E, C0 5E and C0 FE.&lt;br /&gt;
&lt;br /&gt;
It is thus possible to form illegal UTF-8 encodings, in two senses:&lt;br /&gt;
&lt;br /&gt;
* A UTF-8 sequence for a given symbol may be longer than necessary for representing the symbol. &lt;br /&gt;
&lt;br /&gt;
* A UTF-8 sequence may contain octets that are in incorrect format (i.e. do not comply with the above 6 formats).&lt;br /&gt;
&lt;br /&gt;
To further &amp;quot;complicate&amp;quot; things, each representation can be sent over HTTP in several ways:&lt;br /&gt;
&lt;br /&gt;
'''In the raw'''. That is, without URL encoding at all. This usually results in sending non-ASCII octets in the path, query or body, which violates the HTTP standards. Nevertheless, most HTTP servers do get along just fine with non-ASCII characters.&lt;br /&gt;
&lt;br /&gt;
'''Valid URL encoding'''. Each non-ASCII character (more precisely, all characters that require URL encoding - a superset of non ASCII characters) is URL-encoded. This results in sending, say, %C0%AE.&lt;br /&gt;
&lt;br /&gt;
'''Invalid URL encoding'''. This is a variant of valid URL encoding, wherein some hexadecimal digits are replaced with non-hexadecimal digits, yet the result is still interpreted as identical to the original, under some decoding algorithms. For example, %C0 is interpreted as character number ('C'-'A'+10)*16+('0'-'0') = 192. Applying the same algorithm to %M0 yields ('M'-'A'+10)*16+('0'-'0') = 448, which, when forced into a single byte, yields (8 least significant bits) 192, just like the original. So, if the algorithm is willing to accept non-hexadecimal digits (such as 'M'), then it is possible to have variants for %C0 such as %M0 and %BG.&lt;br /&gt;
&lt;br /&gt;
It should be kept in mind that these techniques are not directly related to Unicode, and they can be used in non-Unicode attacks as well. &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=../../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
URL Encoding of the example attack:&lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%2F../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
Unicode encoding of the example attack:&lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%9c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%pc../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%9v../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%qf../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%8s../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%1c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%9c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%e0%80%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%f0%80%80%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%f8%80%80%80%af../bin/ls%20-al&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
A suitable canonical form should be chosen and all user input canonicalized into that form before any authorization decisions are performed. Security checks should be carried out after UTF-8 decoding is completed. Moreover, it is recommended to check that the UTF-8 encoding is a valid canonical encoding for the symbol it represents.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.ietf.org/rfc/rfc2279.txt?number=2279  &amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Input Formats ==&lt;br /&gt;
&lt;br /&gt;
Web applications usually operate internally as one of ASCII, ISO 8859-1, or Unicode (Java programs are UTF-16 example). Your users may be using another locale, and attackers can choose their locale and character set with impunity. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Investigate the web application to determine if it asserts an internal code page, locale or culture.&lt;br /&gt;
&lt;br /&gt;
If the default character set, locale is not asserted it will be one of the following:&lt;br /&gt;
&lt;br /&gt;
* HTTP Posts. Interesting tidbit: All HTTP posts are required to be ISO 8859-1, which will lose data for most double byte character sets. You must test your application with your supported browsers to determine if they pass in fully encoded double byte characters safely&lt;br /&gt;
&lt;br /&gt;
* HTTP Gets. Depends on the previously rendered page and per-browser implementations, but URL encoding is not properly defined for double byte character sets. IE can be optionally forced to do all submits as UTF-8 which is then properly canonicalized on the server&lt;br /&gt;
&lt;br /&gt;
* .NET: Unicode (little endian)&lt;br /&gt;
&lt;br /&gt;
* JSP implementations, such as Tomcat: UTF8 - see “javaEncoding” in web.xml by many servlet containers&lt;br /&gt;
&lt;br /&gt;
* Java: Unicode (UTF-16, big endian, '''''or''''' depends on the OS during JVM startup)&lt;br /&gt;
&lt;br /&gt;
* PHP: Set in php.ini, ISO 8859-1. &lt;br /&gt;
&lt;br /&gt;
'''NB: Many PHP functions make (invalid) assumptions as to character set and may not work properly when changed to another character set. Test your application with the new character set thoroughly!'''&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Determine your application’s needs, and set both the asserted language locale and character set appropriately. &lt;br /&gt;
&lt;br /&gt;
==Locale assertion ==&lt;br /&gt;
&lt;br /&gt;
The web server should always assert a locale and preferably a country code, such as “en_US”, “fr_FR”, “zh_CN”&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Use a HTTP header sniffer or even just telnet against your web server:&lt;br /&gt;
&lt;br /&gt;
''HEAD / HTTP1.0''&lt;br /&gt;
&lt;br /&gt;
Should display something like this:&lt;br /&gt;
&lt;br /&gt;
''HTTP/1.1 200 OK''&lt;br /&gt;
&lt;br /&gt;
''Date: Sun, 24 Jul 2005 08:13:17 GMT''&lt;br /&gt;
&lt;br /&gt;
''Server: Apache/1.3.29''&lt;br /&gt;
&lt;br /&gt;
''Connection: close''&lt;br /&gt;
&lt;br /&gt;
''Content-Type: text/html;''''' charset=iso-8859-1'''&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Review and implement these guidelines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w3.org/International/technique-index&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a minimum, select the correct output locale and character set. &lt;br /&gt;
&lt;br /&gt;
==Double (or n-) encoding ==&lt;br /&gt;
&lt;br /&gt;
Most web applications only check once to determine if the input is has been de-encoded into the correct Unicode values. However, an attacker may have doubly encoded the attack string. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Use XSS Cheat Sheet double encoder utility to double encode a XSS string&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://ha.ckers.org/xss.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If the resultant injection is a successful XSS output, then your application is vulnerable&lt;br /&gt;
&lt;br /&gt;
* This attack may also work against:&lt;br /&gt;
&lt;br /&gt;
# Filenames&lt;br /&gt;
# Non-obvious items like report types, and language selectors&lt;br /&gt;
# Theme names&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Assert the correct locale and character set for your application&lt;br /&gt;
&lt;br /&gt;
* Use HTML entities, URL encoding and so on to prevent Unicode characters being treated improperly by the many divergent browser, server and application combinations&lt;br /&gt;
&lt;br /&gt;
* Test your code and overall solution extensively&lt;br /&gt;
&lt;br /&gt;
==HTTP Request Smuggling ==&lt;br /&gt;
&lt;br /&gt;
HTTP Request Smuggling (HRS) is an issue detailed in depth by Klein, Linhart, Heled, and Orrin in a whitepaper found in the references section. The basics of HTTP Request Smuggling is that many larger solutions use many components to provide a web application. The differences between the firewall, web application firewall, load balancers, SSL accelerators, reverse proxies, and web servers allow a specially crafted attack to bypass all the controls in the front-end systems and directly attack the web server. &lt;br /&gt;
&lt;br /&gt;
The types of attack they describe are:&lt;br /&gt;
&lt;br /&gt;
* Web cache poisoning&lt;br /&gt;
&lt;br /&gt;
* Firewall/IDS/IPS evasion&lt;br /&gt;
&lt;br /&gt;
* Forward and backward HRS techniques&lt;br /&gt;
&lt;br /&gt;
* Request hijacking&lt;br /&gt;
&lt;br /&gt;
* Request credential hijacking&lt;br /&gt;
&lt;br /&gt;
Since the whitepaper, several examples of real life HRS have been discovered. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Review the whitepaper&lt;br /&gt;
&lt;br /&gt;
* Review your infrastructure for vulnerable components&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Minimize the total number of components that may interpret the inbound HTTP request&lt;br /&gt;
&lt;br /&gt;
* Keep your infrastructure up to date with patches&lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* IDS Evasion using Unicode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://online.securityfocus.com/print/infocus/1232&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* W3C Internationalization Home Page&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w3.org/International/&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* HTTP Request Smuggling&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.watchfire.com/resources/HTTP-Request-Smuggling.pdf&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* XSS Cheat Sheet&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://ha.ckers.org/xss.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Canonicalization]]&lt;br /&gt;
[[Category:Encoding]]&lt;/div&gt;</summary>
		<author><name>Joern.zaefferer</name></author>	</entry>

	</feed>