<?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=Nawwar</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=Nawwar"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Nawwar"/>
		<updated>2026-05-05T11:04:50Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Jacksonville&amp;diff=254135</id>
		<title>Jacksonville</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Jacksonville&amp;diff=254135"/>
				<updated>2019-08-25T19:10:48Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: /*  Sponsorship/Membership   */ Name spelling correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Chapter Template|chaptername=Jacksonville|extra=The chapter leaders are [mailto:kevin.johnson@owasp.org Kevin Johnson] and [mailto:larry.franklin@owasp.org Larry Franklin].&lt;br /&gt;
|mailinglistsite=http://lists.owasp.org/mailman/listinfo/owasp-Jacksonville|emailarchives=http://lists.owasp.org/pipermail/owasp-Jacksonville}}&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;u&amp;gt;Upcoming Meetings&amp;lt;/u&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Monthly OWASP Jax meetings will be held on the second Monday of the month, unless otherwise stated.  The meeting location will be held in the Secure Ideas Headquarters training room at 3412 Kori Rd, Jacksonville, Fl 32257. The start time is 6:30 with a short introduction and presentations beginning at 7:00 until NLT 8:30pm. All are welcome to attend by registering at the following link; https://www.meetup.com/OWASP-Jacksonville-Chapter/. Please register by the Friday prior to the meeting.&lt;br /&gt;
&lt;br /&gt;
June 11, 2018 - Guest speaker will be Oleg Laskin. Oleg, will be presenting on the tools used during the testing of web applications, with an intro to applications like ZAP and Burp Suite. &lt;br /&gt;
&lt;br /&gt;
July 9, 2018 - **Cancelled**&lt;br /&gt;
&lt;br /&gt;
August 06, 2018 - Keith Perry.&lt;br /&gt;
&lt;br /&gt;
September 10, 2018 - Guest speakers Nathan Sweeney and Mic Whitehorn-Gillam, topic will be a discussion about testing an Application vs API  &lt;br /&gt;
Video link: https://www.youtube.com/watch?v=pyQDO6S9vQ4&lt;br /&gt;
&lt;br /&gt;
October 8, 2018 - Brandi Kiehl&lt;br /&gt;
Topic: WordClouds&lt;br /&gt;
&lt;br /&gt;
November 12, 2018 - Dr Johannes Ullrich &lt;br /&gt;
Topic:  Nation State Level Honeypotting: Emulating Vulnerable Web Applications at Scale Video link: https://youtu.be/2anqrtfJ1nA&lt;br /&gt;
&lt;br /&gt;
December 10 - OWASP Jax social ** Cancelled **&lt;br /&gt;
&lt;br /&gt;
January 14, 2019 - Guest Speaker Oleg Laskin , Password Cracking https://www.youtube.com/watch?v=Sz2IayEfuBg&amp;amp;t=741s&lt;br /&gt;
&lt;br /&gt;
February 11, 2019 - Guest Speaker Michael Marbut, Everything you want to know about passwords but we're too afraid to ask: a beginners guide to password hashing Video link : https://youtu.be/prhE150EiI4&lt;br /&gt;
&lt;br /&gt;
March 11, 2019 - Guest Speaker David Fekke,  this presentation will cover the BlackBerry Dynamics framework, what it can provide for mobile and enterprise security.  This presentation will include a demo of a iOS application built with BlackBerry Dynamics.  https://www.eventbrite.com/e/owaspjax-monthly-meeting-tickets-55975263520&lt;br /&gt;
&lt;br /&gt;
April 8, 2019 - Nawwar Kabbani - Modern authentication and authorization with OAUTH 2.0 and OpenID Connect&lt;br /&gt;
&lt;br /&gt;
May 13, 2019 - Guest Speaker Lev Shaket - GatsbyJs and AWS Lambda // Statically generate passphrases with dreidelware.org&lt;br /&gt;
&lt;br /&gt;
June 10, 2019 - Guest speaker Travis Phillips - Pwntools&lt;br /&gt;
&lt;br /&gt;
Be sure to sign up at our Meetup page https://www.meetup.com/OWASP-Jacksonville-Chapter/&lt;br /&gt;
&lt;br /&gt;
July 8, 2019 - Kevin Johnson CEO and owner of Secure Ideas LLC, - OWASP WishBook, an incite into OWASP projects and how you can contribute. &lt;br /&gt;
&lt;br /&gt;
August 12, 2019 - Martin Knobloch Chairman of the Board OWASP Foundation - Security in a DevOps world with OWASP tools &amp;amp; guides &lt;br /&gt;
&lt;br /&gt;
September 9, 2019 - Michael Marbut - Interactive presentation on OWASP's Juice Shop.&lt;br /&gt;
&lt;br /&gt;
October 14,2019 - Michael Dimmett -  &amp;quot;How the web works&amp;quot; and using chrome development tools to reverse engineer undocumented parts the youtube embed api. &lt;br /&gt;
&lt;br /&gt;
November 11, 2019 - Larry Franklin OWASP JAX Chapter Leader - Open discussion on Security risk associated with Web application development and how to manage them effectively.&lt;br /&gt;
&lt;br /&gt;
''Please join our Google groups at https://groups.google.com/a/owasp.org/forum/#!forum/jacksonville-chapter for topic discussions after the meetings, and for any future happenings in our OWASP group.''&lt;br /&gt;
&lt;br /&gt;
'''Our Sponsors:'''&lt;br /&gt;
&lt;br /&gt;
Secure Ideas&lt;br /&gt;
&lt;br /&gt;
Robert Half Technology Jacksonville&lt;br /&gt;
[[Category:OWASP Chapter]]&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SecureFlag&amp;diff=250846</id>
		<title>SecureFlag</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SecureFlag&amp;diff=250846"/>
				<updated>2019-04-30T18:33:14Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: /* ASP.NET */ Update ASP.NET section with more details and an alternative example.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{taggedDocument&lt;br /&gt;
| type=old&lt;br /&gt;
| lastRevision=2015-12-14&lt;br /&gt;
| comment=References out-of-date platforms and environments.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
The secure flag is an option that can be set by the application server when sending a new cookie to the user within an HTTP&amp;amp;nbsp;Response. The purpose of the secure flag is to prevent cookies from being observed by unauthorized parties due to the transmission of a the cookie in clear text.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To accomplish this goal, browsers which support the secure flag will only send cookies with the secure flag when the request is going to a HTTPS page. Said in another way, the browser will not send a cookie with the secure flag set over an unencrypted HTTP request.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By setting the secure flag, the browser will prevent the transmission of a cookie over an unencrypted channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Setting the Secure Flag =&lt;br /&gt;
&lt;br /&gt;
Following sections describes setting the Secure Flag in respective technologies.&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
&lt;br /&gt;
=== Servlet 3.0 (Java EE 6) ===&lt;br /&gt;
Sun Java EE supports secure flag in Cookie interface since version 6 (Servlet class version 3)[http://java.sun.com/javaee/6/docs/api/javax/servlet/http/Cookie.html#setSecure%28boolean%29], also for session cookies (JSESSIONID)[http://java.sun.com/javaee/6/docs/api/javax/servlet/SessionCookieConfig.html#setSecure%28boolean%29]. Methods ''setSecure'' and ''isSecure'' can be used to set and check for secure value in cookies.&lt;br /&gt;
&lt;br /&gt;
==== web.xml ====&lt;br /&gt;
Servlet 3.0 (Java EE 6) introduced a standard way to configure secure attribute for the session cookie, this can be done by applying the following configuration in web.xml&lt;br /&gt;
 &amp;amp;lt;session-config&amp;amp;gt;&lt;br /&gt;
  &amp;amp;lt;cookie-config&amp;amp;gt;&lt;br /&gt;
   &amp;amp;lt;secure&amp;amp;gt;true&amp;amp;lt;/secure&amp;amp;gt;&lt;br /&gt;
  &amp;amp;lt;/cookie-config&amp;gt;&lt;br /&gt;
 &amp;amp;lt;/session-config&amp;amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tomcat ===&lt;br /&gt;
In '''Tomcat 6''' if the first request for session is using ''https'' then it automatically sets secure attribute on session cookie.&lt;br /&gt;
&lt;br /&gt;
=== Setting it as a custom header ===&lt;br /&gt;
For '''older versions''' the workaround is to rewrite JSESSIONID value using and setting it as a custom header. The drawback is that servers can be configured to use a different session identifier than JSESSIONID.&lt;br /&gt;
&lt;br /&gt;
 String sessionid = request.getSession().getId();&lt;br /&gt;
 response.setHeader(&amp;quot;SET-COOKIE&amp;quot;, &amp;quot;JSESSIONID=&amp;quot; + sessionid + &amp;quot;; secure&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== Environment consideration ===&lt;br /&gt;
&lt;br /&gt;
With this flag always set, sessions won't work in environments(development/test/etc.) that may use http. SessionCookieConfig [http://java.sun.com/javaee/6/docs/api/javax/servlet/SessionCookieConfig.html#setSecure%28boolean%29] interface or setting custom header[https://www.owasp.org/index.php/SecureFlag#Setting_it_as_a_custom_header] trick can be leveraged to configure setting of this flag differently for each environment and can be driven by application configuration. &lt;br /&gt;
&lt;br /&gt;
== ASP.NET ==&lt;br /&gt;
&lt;br /&gt;
Set the following in Web.config:&lt;br /&gt;
&amp;lt;httpCookies requireSSL=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For some objects that have a requireSSL property, like the forms Authentication Cookie, set the requireSSL=&amp;quot;true&amp;quot; flag in the ''web.config'' for that specific element. For example: &lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;authentication mode=&amp;quot;Forms&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&amp;lt;forms loginUrl=&amp;quot;member_login.aspx&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
          &amp;lt;code&amp;gt;cookieless=&amp;quot;UseCookies&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
          &amp;lt;code&amp;gt;'''requireSSL=&amp;quot;true&amp;quot;'''&amp;lt;/code&amp;gt;&lt;br /&gt;
          &amp;lt;code&amp;gt;path=&amp;quot;/MyApplication&amp;quot; /&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;/authentication&amp;gt;&amp;lt;/code&amp;gt;  &lt;br /&gt;
Which will enable the secure flag on the Forms Authentication cookie, as well as checking that the http request is coming to the server over SSL/TLS connection. Note that in case TLS is offloaded to a load balancer, the requireSSL solution wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the cookies can be set to secure programmatically using the following code by adding a EndRequest event handler to the Global.asax.cs file:&lt;br /&gt;
 protected void Application_EndRequest(Object sender, EventArgs e) {&lt;br /&gt;
    // Iterate through any cookies found in the Response object.&lt;br /&gt;
    foreach (string cookieName in Response.Cookies.AllKeys) {&lt;br /&gt;
        Response.Cookies[cookieName]?.Secure = true;&lt;br /&gt;
    }&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
For session cookies managed by PHP, the flag is set either permanently in php.ini [http://php.net/manual/en/session.configuration.php#ini.session.cookie-secure PHP manual on ''SecureFlag''] through the parameter:&lt;br /&gt;
 session.cookie_secure = True&lt;br /&gt;
or in and during a script via the function [http://pl.php.net/manual/en/function.session-set-cookie-params.php]:&lt;br /&gt;
 void session_set_cookie_params  ( int $lifetime  [, string $path  [, string $domain  &lt;br /&gt;
                                   [, bool $secure= false  [, bool $httponly= false  ]]]] )&lt;br /&gt;
For application cookies a parameter in setcookie() sets Secure flag [http://pl.php.net/setcookie]:&lt;br /&gt;
 bool setcookie  ( string $name  [, string $value  [, int $expire= 0  [, string $path  &lt;br /&gt;
                  [, string $domain  [, bool $secure= false  [, bool $httponly= false  ]]]]]] )&lt;br /&gt;
&lt;br /&gt;
= Testing for the Secure Flag =&lt;br /&gt;
&lt;br /&gt;
Verifying that a web site sets this flag on any particular cookie is easy. Using an intercepting proxy, like [[ZAP]], you can capture each response from the server and examine any Set-Cookie headers it includes to see if the secure flag is set on the cookie.&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
* [[Testing for cookies attributes (OTG-SESS-002)|Testing for Cookie Attributes]]&lt;br /&gt;
* http://www.troyhunt.com/2011/11/owasp-top-10-for-net-developers-part-9.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Control]]&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=229631</id>
		<title>How to write insecure code</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=229631"/>
				<updated>2017-05-15T17:14:30Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: &amp;quot;Testing is overrated&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
&lt;br /&gt;
=HOW TO WRITE INSECURE CODE=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
In the interest of ensuring that there will be a future for hackers, criminals, and others who want to destroy the digital future, this paper captures tips from the masters on how to create insecure code. With a little creative use of these tips, you can also ensure your own financial future. Be careful, you don't want to make your code look hopelessly insecure, or your insecurity may be uncovered and fixed.&lt;br /&gt;
&lt;br /&gt;
The idea for this article comes from Roedy Green's [http://mindprod.com/jgloss/unmain.html How to write unmaintainable code]. You may find the [http://thc.org/root/phun/unmaintain.html one page version more readable]. Actually, making your code unmaintainable is a great first step towards making it insecure and there are some great ideas in this article, particularly the section on camouflage. Also many thanks to Steven Christey from MITRE who contributed a bunch of particularly insecure items.&lt;br /&gt;
&lt;br /&gt;
''Special note for the slow to pick up on irony set. This essay is a '''joke'''! Developers and architects are often bored with lectures about how to write '''secure''' code. Perhaps this is another way to get the point across.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Use this format for adding items to the list&lt;br /&gt;
; '''Title'''&lt;br /&gt;
: Details&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==General Principles==&lt;br /&gt;
&lt;br /&gt;
; '''Avoid the tools'''&lt;br /&gt;
: To ensure an application is forever insecure, you have to think about how security vulnerabilities are identified and remediated. Many software teams believe that automated tools can solve their security problems. So if you want to ensure vulnerabilities, simply make them difficult for automated tools to find. This is a lot easier than it sounds. All you have to do is make sure your vulnerabilities don't match anything in the tool's database of signatures. Your code can be as complex as you want, so it's pretty easy to avoid getting found. In fact, most inadvertent vulnerabilities can't be found by tools anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Always use default deny'''&lt;br /&gt;
: Apply the principle of &amp;quot;Default Deny&amp;quot; when building your application. Deny that your code can ever be broken, deny vulnerabilities until there's a proven exploit, deny to your customers that there was ever anything wrong, and above all - deny responsibility for flaws. Blame the dirty cache buffers.&lt;br /&gt;
&lt;br /&gt;
; '''Be a shark'''&lt;br /&gt;
: Always be on the move.  Leave security problems to operations staff.&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
&lt;br /&gt;
; '''Distribute security mechanisms'''&lt;br /&gt;
: Security checks should be designed so that they are as distributed as possible throughout the codebase. Try not to follow a consistent pattern and don't make it easy to find all the places where the mechanism is used. This will virtually ensure that security is implemented inconsistently.&lt;br /&gt;
&lt;br /&gt;
; '''Spread the wealth'''&lt;br /&gt;
: Another great way to avoid being found is to make sure your security holes aren't located in one place in your code. It's very difficult for analysts to keep all of your code in their head, so by spreading out the holes you prevent anyone from finding or understanding them.&lt;br /&gt;
&lt;br /&gt;
; '''Use dynamic code'''&lt;br /&gt;
: The single best way to make it difficult for a security analyst (or security tool for that matter) to follow through an application and uncover a flaw is to use dynamic code. It can be almost impossible to trace the flow through code that is loaded at runtime. Features like reflection and classloading are beautiful features for hiding vulnerabilities. Enable as many &amp;quot;plugin&amp;quot; points as possible.&lt;br /&gt;
&lt;br /&gt;
==Secure Languages==&lt;br /&gt;
&lt;br /&gt;
; '''Type safety'''&lt;br /&gt;
: Means anything you enter at the keyboard is secure.&lt;br /&gt;
&lt;br /&gt;
; '''Secure languages'''&lt;br /&gt;
: Pick only programming languages that are completely safe and don't require any security knowledge or special programming to secure.&lt;br /&gt;
&lt;br /&gt;
; '''Mix languages'''&lt;br /&gt;
: Different languages have different security rules, so the more languages you include the more difficult it will be to learn them all. It's hard enough for development teams to even understand the security ramifications of one language, much less three or four. You can use the transitions between languages to hide vulnerabilities too.&lt;br /&gt;
&lt;br /&gt;
==Trust Relationships==&lt;br /&gt;
&lt;br /&gt;
; '''Rely on security checks done elsewhere'''&lt;br /&gt;
: It's redundant to do security checks twice, so if someone else says that they've done a check, there's no point in doing it again. When possible, it's probably best to just assume that others are doing security right, and not waste time doing it yourself. Web services and other service interfaces are generally pretty secure, so don't bother checking what you send or what they return.&lt;br /&gt;
&lt;br /&gt;
; '''Trust insiders'''&lt;br /&gt;
: Malicious input only comes from the Internet, and you can trust that all the data in your databases is perfectly validated, encoded, and sanitized for your purposes.&lt;br /&gt;
&lt;br /&gt;
; '''Code wants to be free!'''&lt;br /&gt;
: Drop your source code into repositories that are accessible by all within the company.  This also prevents having to email those hard-coded shared secrets around.&lt;br /&gt;
&lt;br /&gt;
==Logging==&lt;br /&gt;
&lt;br /&gt;
; '''Use your logs for debugging'''&lt;br /&gt;
: Nobody will be able to trace attacks on your code if you fill up the logs with debugging nonsense. Extra points for making your log messages undecipherable by anyone except you. Even more points if the log messages look as though they might be security relevant.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use a logging framework'''&lt;br /&gt;
: The best approach to logging is just to write to stdout, or maybe to a file. Logging frameworks make the logs too easy to search and manage to be sure that nobody will ever review them.&lt;br /&gt;
&lt;br /&gt;
==Encryption==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own encryption scheme'''&lt;br /&gt;
: The standard encryption mechanisms are way too complicated to use. It's much easier to make up an encryption algorithm that scrambles up secret stuff. You don't need to bother with a key or anything, just mix it all up and nobody will figure it out.&lt;br /&gt;
&lt;br /&gt;
; '''Hard-code your keys'''&lt;br /&gt;
: Hard-coding is the best way to retain control. This way those pesky operations folks won't be able to monkey with (they say &amp;quot;rotate&amp;quot;) the keys, and they'll be locked into the source code where only smart people can understand them.  This will also make it easier to move from environment to environment as the hard-coded key will be the same everywhere.  This in turn means your code is secure everywhere.&lt;br /&gt;
&lt;br /&gt;
; '''Smart coders don't read manuals'''&lt;br /&gt;
: Just keep adding bytes until the algorithm stops throwing exceptions.  Or just save yourself time and cut-and-paste from a popular coding site.  This looks like a good start: byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };&lt;br /&gt;
&lt;br /&gt;
; '''Pack up your sensitive payload'''&lt;br /&gt;
: If you need to pass things that are sensitive, like passwords or PII, just pack it up in an encrypted blob.  Then just email the key to the developer who is coding the other side of the transaction, and punch out early.  This will also get you past Data Loss Prevention (DLP) tools which is a huge bonus.&lt;br /&gt;
&lt;br /&gt;
; '''Encryption is hard'''&lt;br /&gt;
: A great way to improve the security posture of your site is to use client-side JavaScript to encrypt passwords and other sensitive data that are submitted.  This can be used with or without HTTPS (TLS/SSL).  If you use it without HTTPS, you can save some money by skipping the annual purchase of a signed third party certificate.&lt;br /&gt;
&lt;br /&gt;
; '''HTTPS makes your application bullet proof'''&lt;br /&gt;
: If you use HTTPS encryption between your web application endpoint and the client, there is absolutely no way for anyone to steal any of the data that is transmitted.&lt;br /&gt;
&lt;br /&gt;
==Authentication==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own authentication scheme'''&lt;br /&gt;
: Authentication is simple, so just use your common sense and implement. Don't worry about esoteric stuff you hear about like session prediction, hashing credentials, brute force attacks, and so on. Only NSA eggheads could possibly ever figure that stuff out. And if users want to choose weak passwords, that's their own fault.&lt;br /&gt;
'''Just use a hash'''&lt;br /&gt;
&lt;br /&gt;
Salt is for pigs.  Its way too much work to salt and hash passwords.  Besides, only the application can get to the database and hashes are one way trap doors, so why would you need it?&lt;br /&gt;
; '''Sessions are inherently secure'''&lt;br /&gt;
: Sessions timeout after 20 minutes, so don't worry about them. You can put the SESSIONID in the URL, log files, or wherever else you feel like. What could an attacker do with a SESSIONID anyway? It's just a bunch of random letters and numbers.&lt;br /&gt;
&lt;br /&gt;
; '''Single Sign-On is easy'''&lt;br /&gt;
: If you need to submit a username and password (or other secret knocks) from one site to another, pack it up in an encrypted blob as above.  This way if anyone finds the blob, they'll have a heck of a time decrypting it, which is what they'll need to do to be able to encrypt it again and create the blob themselves.&lt;br /&gt;
: A one-way hash cannot be decrypted.  Therefore, this is a way to take the latter approach and make it unbreakable.&lt;br /&gt;
&lt;br /&gt;
==Authorization==&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think there's a difference between authentication and authorization.&lt;br /&gt;
&lt;br /&gt;
; '''Just let your authorization scheme evolve'''&lt;br /&gt;
: It's really hard to figure out all the access control rules for your application, so use a '''just in time''' development methodology. This way you can just code up new rules when you figure them out. If you end up with hundreds or thousands of lines of authorization code scattered throughout your application, you're on the right track.&lt;br /&gt;
&lt;br /&gt;
; '''Privilege makes code just work'''&lt;br /&gt;
: Using the highest privilege levels makes your product easier to install and run.&lt;br /&gt;
&lt;br /&gt;
; '''Optimize the developer... always'''&lt;br /&gt;
: Each developer, independent of one another, must decide where authorization decision and enforcement is made.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: RIA clients and fat clients that use remote services can make decisions about what the end-user can or can't see.&lt;br /&gt;
&lt;br /&gt;
; '''Volunteer to authorize access to other systems'''&lt;br /&gt;
: When a service you are calling, for example, has inappropriate access controls just be nice and live with it.  After all it will be your fault when a direct object reference permits any user of your system to see any data on their service.  Should that happen, it will be a chance for you to show your dedication when you're up at 3 AM on a Saturday morning sorting out a breach.&lt;br /&gt;
&lt;br /&gt;
==Policy==&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: Policy can't be known until the user requests arrive.  Put authorization logic where you see fit.  Sometimes you need to roll it into the UI.  Sometimes it's in the data layer.  Sometimes it's both.    &lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think that security requirements can be known at design time and expressed in a runtime-readable/declarative format.&lt;br /&gt;
&lt;br /&gt;
; '''The tool knows how to do it'''&lt;br /&gt;
: Let your automated tools dictate your security requirements. Tailoring is for suckers.&lt;br /&gt;
&lt;br /&gt;
==Input Validation==&lt;br /&gt;
&lt;br /&gt;
; '''Validation is for suckers'''&lt;br /&gt;
: Your application is already protected by a firewall, so you don't have to worry about attacks in user input. The security ''experts'' who keep nagging you are just looking to keep themselves in a job and know nothing about programming.&lt;br /&gt;
&lt;br /&gt;
; '''Let developers validate their way'''&lt;br /&gt;
: Don't bother with a standard way of doing validation, you're just cramping developer style. To create truly insecure code, you should try to validate as many different ways as possible, and in as many different places as possible.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: If the client doesn't, by design, produce wacky encoding, for example, then wacky encoding isn't a threat.&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
&lt;br /&gt;
; '''If you can build it and it appears to work then why describe it?'''&lt;br /&gt;
: The most successful applications do not waste time with requirements, security or otherwise.  Optimize the development by keeping the developers from having to read.&lt;br /&gt;
&lt;br /&gt;
; '''Security is just another option'''&lt;br /&gt;
: Assume that your sysadmins will RTFM and change the default settings you specified in a footnote on page 124.&lt;br /&gt;
&lt;br /&gt;
; '''Don't document how security works'''&lt;br /&gt;
: There is no point in writing down all the details of a security design. If someone wants to figure out if it works, they should check the code. After all, the code may change and then the documentation would be useless.&lt;br /&gt;
&lt;br /&gt;
; '''Freedom to innovate'''&lt;br /&gt;
: Standards are really just guidelines for you to add your own custom extensions.&lt;br /&gt;
&lt;br /&gt;
; '''Print is dead'''&lt;br /&gt;
: You already know everything about security, what else is there to learn? Books are for lamers, mailing lists and blogs are for media whores and FUD-tossing blowhards.&lt;br /&gt;
&lt;br /&gt;
==Coding==&lt;br /&gt;
&lt;br /&gt;
; '''Most APIs are safe'''&lt;br /&gt;
: Don't waste time poring through documentation for API functions. It's generally pretty safe to assume that APIs do proper validation, exception handling, logging, and thread safety.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use security patterns'''&lt;br /&gt;
: Make sure there's no standard way of implementing validation, logging, error handling, etc... on your project. It's best when developers are left free to express themselves and channel their inner muse in their code. Avoid establishing any security coding guidelines, that'll just inhibit creativity.&lt;br /&gt;
&lt;br /&gt;
; '''Make sure the build process has lots of steps'''&lt;br /&gt;
: You want to maximize the number of steps in the build process that have to occur in the right order to make a successful build. It's best if only one person knows how to actually set up all the config files and build the distribution. If you do have steps written down, you should have lots of notes distributed across a bunch of files and howto's in lots of locations.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
; '''Testing is overrated'''&lt;br /&gt;
: Testing is expensive and time-consuming. Just code and ship immediately. The market wants your newest release yesterday. If anything is broken, your loyal users will let you know. &lt;br /&gt;
; '''Test with a browser'''&lt;br /&gt;
: All you need to test a web application is a browser. That way, you ensure that your code will work perfectly for all of your legitimate users.  And what do you care if it doesn't work for hackers, attackers, and criminals? Using a fancy security testing tool like [[WebScarab]] is a waste of your valuable time.&lt;br /&gt;
'''Test with only one browser'''&lt;br /&gt;
&lt;br /&gt;
After all, they all work the same way and follow standards and never differ in terms of security.&lt;br /&gt;
; '''Build test code into every module'''&lt;br /&gt;
: You should build test code throughout the application. That way you'll have it there in production in case anything goes wrong and you need to run it.&lt;br /&gt;
&lt;br /&gt;
; '''Security warnings are all false alarms'''&lt;br /&gt;
: Everyone knows that security warnings are all false alarms, so you can safely just ignore them. Why should you waste your valuable time chasing down possible problems when it's not your money on the line. If a tool doesn't produce perfect results, then just forget it.&lt;br /&gt;
&lt;br /&gt;
==Libraries==&lt;br /&gt;
&lt;br /&gt;
; '''Use lots of precompiled libraries'''&lt;br /&gt;
: Libraries are great because you don't have to worry about whether the code has any security issues. You can trust your business to just about any old library that you download off the Internet and include in your application. Don't worry about checking the source code, it's probably not available and it's too much trouble to recompile. And it would take way too long to check all that source code anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Don't worry about using the latest version of components'''&lt;br /&gt;
: Just because a library has known vulnerabilities doesn't mean it's not safe to use. If there's no proof that *my* application is vulnerable then you're just wasting my time.&lt;br /&gt;
&lt;br /&gt;
==Culture==&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;I got a security approval&amp;quot;&lt;br /&gt;
: So what if it was several years ago, it's basically the same code anyway.&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Security has to *prove* it before I do anything&amp;quot;&lt;br /&gt;
: So what if you exploited my application, you cheated by using hacking&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Hello, this is an internal application, so security doesn't matter&amp;quot;&lt;br /&gt;
: We have firewalls and stuff       [[Category:How To]]&lt;br /&gt;
&lt;br /&gt;
== DevOps ==&lt;br /&gt;
'''Automation is enough security'''&lt;br /&gt;
&lt;br /&gt;
Forget about integrity, if we have a problem with a node, all we need to do is kill it and stand another up&lt;br /&gt;
&lt;br /&gt;
'''Automated Scanning'''&lt;br /&gt;
&lt;br /&gt;
It just creates more garbage nobody is going to read anyways&lt;br /&gt;
&lt;br /&gt;
'''Access Control on DevOps systems'''&lt;br /&gt;
&lt;br /&gt;
IAM roles and how keys are managed don't matter much, we can just check them right into GitHub and it'll be lost in a world of anonymity.  Hell, we can even put all our code there so we can just pull it from anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Static Analysis'''&lt;br /&gt;
&lt;br /&gt;
See automated scanning&lt;br /&gt;
&lt;br /&gt;
'''Dynamic Analysis'''&lt;br /&gt;
&lt;br /&gt;
See automated scanning&lt;br /&gt;
&lt;br /&gt;
'''Dependency checking'''&lt;br /&gt;
&lt;br /&gt;
No one would ever think to put a payload in a library, and hey, the signature on libraries are probably always there.&lt;br /&gt;
&lt;br /&gt;
'''Auditing is a waste of money'''&lt;br /&gt;
&lt;br /&gt;
There is no reason to check actual configurations written when we are using playbooks and configuration automation the tell us a node started out with a good configuration.  Why would it ever change?  Also see Automation is enough security&lt;br /&gt;
&lt;br /&gt;
'''We'll never lose control of our nodes'''&lt;br /&gt;
&lt;br /&gt;
Let's just write that root key down on paper and share it with the team.  Nobody would ever leak it and create a botnet on our dollar.&lt;br /&gt;
&lt;br /&gt;
'''CORS'''&lt;br /&gt;
&lt;br /&gt;
The cloud is all about sharing! Let's CORS * everything!&lt;br /&gt;
&lt;br /&gt;
'''Logging Services'''&lt;br /&gt;
&lt;br /&gt;
We're using other peoples infrastructure anyways, why bother with logs or alerts?  It's just a waste of time&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_logout_functionality_(OTG-SESS-006)&amp;diff=201894</id>
		<title>Testing for logout functionality (OTG-SESS-006)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_logout_functionality_(OTG-SESS-006)&amp;diff=201894"/>
				<updated>2015-10-08T20:22:29Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: /* References */ fixing a link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
Session termination is an important part of the session lifecycle. Reducing to a minimum the lifetime of the session tokens decreases the likelihood of a successful session hijacking attack. This can be seen as a control against preventing other attacks like Cross Site Scripting and Cross Site Request Forgery. Such attacks have been known to rely on a user having an authenticated session present. Not having a secure session termination only increases the attack surface for any of these attacks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A secure session termination requires at least the following components:&lt;br /&gt;
&lt;br /&gt;
* Availability of user interface controls that allow the user to manually log out.&lt;br /&gt;
* Session termination after a given amount of time without activity (session timeout).&lt;br /&gt;
* Proper invalidation of server-side session state.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are multiple issues which can prevent the effective termination of a session. For the ideal secure web application, a user should be able to terminate at any time through the user interface. Every page should contain a log out button on a place where it is directly visible. Unclear or ambiguous log out functions could cause the user not trusting such functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another common mistake in session termination is that the client-side session token is set to a new value while the server-side state remains active and can be reused by setting the session cookie back to the previous value. Sometimes only a confirmation message is shown to the user without performing any further action. This should be avoided. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some web application frameworks rely solely on the session cookie to identify the logged-on user. The user's ID is embedded in the (encrypted) cookie value. The application server does not do any tracking on the server-side of the session. When logging out, the session cookie is removed from the browser. However, since the application does not do any tracking, it does not know whether a session is logged out or not. So by reusing a session cookie it is possible to gain access to the authenticated session. A well-known example of this is the Forms Authentication functionality in ASP.NET.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Users of web browsers often don't mind that an application is still open and just close the browser or a tab. A web application should be aware of this behavior and terminate the session automatically on the server-side after a defined amount of time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The usage of a single sign-on (SSO) system instead of an application-specific authentication scheme often causes the coexistence of multiple sessions which have to be terminated separately. For instance, the termination of the application-specific session does not terminate the session in the SSO system. Navigating back to the SSO portal offers the user the possibility to log back in to the application where the log out was performed just before. On the other side a log out function in a SSO system does not necessarily cause session termination in connected applications.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
'''Testing for log out user interface:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Verify the appearance and visibility of the log out functionality in the user interface. For this purpose, view each page from the perspective of a user who has the intention to log out from the web application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
There are some properties which indicate a good log out user interface:&lt;br /&gt;
* A log out button is present on all pages of the web application.&lt;br /&gt;
* The log out button should be identified quickly by a user who wants to log out from the web application.&lt;br /&gt;
* After loading a page the log out button should be visible without scrolling.&lt;br /&gt;
* Ideally the log out button is placed in an area of the page that is fixed in the view port of the browser and not affected by scrolling of the content.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Testing for server-side session termination:'''&amp;lt;br&amp;gt;&lt;br /&gt;
First, store the values of cookies that are used to identify a session. Invoke the log out function and observe the behavior of the application, especially regarding session cookies. Try to navigate to a page that is only visible in an authenticated session, e.g. by usage of the back button of the browser. If a cached version of the page is displayed, use the reload button to refresh the page from the server. If the log out function causes session cookies to be set to a new value, restore the old value of the session cookies and reload a page from the authenticated area of the application. If these test don't show any vulnerabilities on a particular page, try at least some further pages of the application that are considered as security-critical, to ensure that session termination is recognized properly by these areas of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
No data that should be visible only by authenticated users should be visible on the examined pages while performing the tests. Ideally the application redirects to a public area or a log in form while accessing authenticated areas after termination of the session. It should be not necessary for the security of the application, but setting session cookies to new values after log out is generally considered as good practice.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Testing for session timeout:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Try to determine a session timeout by performing requests to a page in the authenticated area of the web application with increasing delays. If the log out behavior appears, the used delay matches approximately the session timeout value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
The same results as for server-side session termination testing described before are excepted by a log out caused by an inactivity timeout.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The proper value for the session timeout depends on the purpose of the application and should be a balance of security and usability. In a banking applications it makes no sense to keep an inactive session more than 15 minutes. On the other side a short timeout in a wiki or forum could annoy users which are typing lengthy articles with unnecessary log in requests. There timeouts of an hour and more can be acceptable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Testing for session termination in single sign-on environments (single sign-off):'''&amp;lt;br&amp;gt;&lt;br /&gt;
Perform a log out in the tested application. Verify if there is a central portal or application directory which allows the user to log back in to the application without authentication. Test if the application requests the user to authenticate, if the URL of an entry point to the application is requested. While logged in in the tested application, perform a log out in the SSO system. Then try to access an authenticated area of the tested application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
It is expected that the invocation of a log out function in a web application connected to a SSO system or in the SSO system itself causes global termination of all sessions. An authentication of the user should be required to gain access to the application after log out in the SSO system and connected application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
* &amp;quot;Burp Suite - Repeater&amp;quot; - http://portswigger.net/burp/repeater.html&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&lt;br /&gt;
* &amp;quot;The FormsAuthentication.SignOut method does not prevent cookie reply attacks in ASP.NET applications&amp;quot; - https://support.microsoft.com/en-us/kb/900111&lt;br /&gt;
* &amp;quot;Cookie replay attacks in ASP.NET when using forms authentication&amp;quot; - https://www.vanstechelman.eu/content/cookie-replay-attacks-in-aspnet-when-using-forms-authentication&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Session_puzzling_(OTG-SESS-008)&amp;diff=199137</id>
		<title>Testing for Session puzzling (OTG-SESS-008)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Session_puzzling_(OTG-SESS-008)&amp;diff=199137"/>
				<updated>2015-08-17T18:50:59Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: /* Summary */ typo: by -&amp;gt; but&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Session Variable Overloading (also known as Session Puzzling) is an application level vulnerability which can enable an attacker to perform a variety of malicious actions, including but not limited to:&lt;br /&gt;
* Bypass efficient authentication enforcement mechanisms, and impersonate legitimate users.&lt;br /&gt;
* Elevate the privileges of a malicious user account, in an environment that would otherwise be considered foolproof.&lt;br /&gt;
* Skip over qualifying phases in multi-phase processes, even if the process includes all the commonly recommended code level restrictions.&lt;br /&gt;
* Manipulate server-side values in indirect methods that cannot be predicted or detected.&lt;br /&gt;
* Execute traditional attacks in locations that were previously unreachable, or even considered secure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This vulnerability occurs when an application uses the same session variable for more than one purpose. An attacker can potentially access pages in an order unanticipated by the developers so that the session variable is set in one context and then used in another.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, an attacker could use session variable overloading to bypass authentication enforcement mechanisms of applications that enforce authentication by validating the existence of session variables that contain identity–related values, which are usually stored in the session after a successful authentication process. This means an attacker first accesses a location in the application that sets session context and then accesses privileged locations that examine this context. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example - an authentication bypass attack vector could be executed by accessing a publicly accessible entry point (e.g. a password recovery page) that populates the session with an identical session variable, based on fixed values or on user originating input.&lt;br /&gt;
&lt;br /&gt;
==How to Test==&lt;br /&gt;
=== Black Box Testing ===&lt;br /&gt;
&lt;br /&gt;
This vulnerability can be detected and exploited by enumerating all of the session variables used by the application and in which context they are valid. In particular this is possible by accessing a sequence of entry points and then examining exit points. In case of black box testing this procedure is difficult and requires some luck since every different sequence could lead to a different result. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
A very simple example could be the password reset functionality that, in the entry point, could request the user to provide  some identifying information such as the username or the e-mail address. This page might then populate the session with these identifying values, which are received directly from the client side, or obtained from queries or calculations based on the received input. At this point there may be some pages in the application that show private data based on this session object. In this manner the attacker could bypass the authentication process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Gray Box testing ===&lt;br /&gt;
&lt;br /&gt;
The most effective way to detect these vulnerabilities is via a source code review.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Session Puzzles: http://puzzlemall.googlecode.com/files/Session%20Puzzles%20-%20Indirect%20Application%20Attack%20Vectors%20-%20May%202011%20-%20Whitepaper.pdf&lt;br /&gt;
* Session Puzzling and Session Race Conditions: http://sectooladdict.blogspot.com/2011/09/session-puzzling-and-session-race.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Remediation==&lt;br /&gt;
&lt;br /&gt;
Session variables should only be used for a single consistent purpose.&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Hibernate&amp;diff=191207</id>
		<title>Hibernate</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Hibernate&amp;diff=191207"/>
				<updated>2015-03-11T17:07:54Z</updated>
		
		<summary type="html">&lt;p&gt;Nawwar: /* Persisting tainted data */ correcting inconsistent variable name&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Status ==&lt;br /&gt;
'''In progress'''&lt;br /&gt;
&lt;br /&gt;
== Before you begin ==&lt;br /&gt;
Since ORM architecture isn't obvious, this document will explain some important things you need to know in order to analyze a Hibernate application in a security context.  This document assumes some SQL and database knowledge.&lt;br /&gt;
&lt;br /&gt;
=== A note about SQL injection ===&lt;br /&gt;
Since it is the hot topic, I will address it now but discuss in detail later.&lt;br /&gt;
* Hibernate does not grant immunity to SQL Injection, one can misuse the api as they please.&lt;br /&gt;
* There is nothing special about HQL (Hibernates subset of SQL) that makes it any more or less susceptible.&lt;br /&gt;
* Functions such as createQuery(String query) and createSQLQuery(String query) create a Query object that will be executed when the call to commit() is made.  If the query string is tainted you have sql injection.  The details of these functions are covered later.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
=== The problem Hibernate addresses ===&lt;br /&gt;
In object oriented systems, we represent entities as objects, and use a database to persist those objects. Generally these objects are considered non-scalar values (non-primitive types).&lt;br /&gt;
But many databases can only store and manipulate scalar values organized in tables.&lt;br /&gt;
The crux of the problem is translating those objects to forms which can be stored in the database, and which can later be retrieved easily, while preserving the properties of the objects and their relationships; these objects are then said to be persistent.&lt;br /&gt;
Hibernate attempts to address this problem with Object/Relational Mapping (O/R M) by mapping attributes of objects we wish to persist to columns of a database. &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-relational_mapping See original article. ]&lt;br /&gt;
&lt;br /&gt;
=== How it works ===&lt;br /&gt;
* Usually Hibernate applications use [http://en.wikipedia.org/wiki/JavaBean JavaBeans] style [http://en.wikipedia.org/wiki/Plain_Old_Java_Object POJOs] to represent objects we want to persist in a database.&lt;br /&gt;
* These objects should have an identifier property (i.e private class variable) used to represent it's primary key value in the database.&lt;br /&gt;
* This identifier will be mapped in a hibernate mapping file, usually with the default extension .hbm.xml, you will see this mapping in the &amp;lt;id&amp;gt; element. This file will also map all other object properties we wish to preserve to columns in a database table, along with their data types and other stuff.&lt;br /&gt;
* Once objects are mapped, Hibernate provides the mechanism for you to store and access them via org.hibernate.Session and org.hibernate.Transaction objects.&lt;br /&gt;
* The Session object has methods to save() objects to a session, load() objects from a database and createQuery()s to be executed against the database.&lt;br /&gt;
* The Transaction object often wraps a database transaction, allowing one to begin() transactions, commit() changes, and rollback() to a previous state.&lt;br /&gt;
* Other classes worth mentioning: SessionFactory, TransactionFactory, and Query.&lt;br /&gt;
* Hibernate's main configuration file, extension .cfg.xml, provides basic setup for things like datasource, dialect, mapping files, etc. &lt;br /&gt;
[http://www.owasp.org/index.php/Hibernate/config-example See this configuration example]&lt;br /&gt;
&lt;br /&gt;
=== Jargon ===&lt;br /&gt;
*'''Transient''' - The instance is not associated with a Session, has no persistent representation in the database and no identifier assigned. An object that has just been instantiated with the new operator is said to be transient. &lt;br /&gt;
*'''Persistent''' - Is associated with a Session, has a representation in the database and has been assigned an identifier. Hibernate synchronizes changes on a persistent object with its representation in the database when it completes a unit of work. &lt;br /&gt;
*'''Detatched''' - was once in a persistent state, but its session has been closed. The reference is still valid and the object may be modified and even reattached to a new session later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hitting the database ===&lt;br /&gt;
The Session object represents the main interface or ''conversation'' between Java and Hibernate. A Session is used for a single request, or unit of work. To make an object persistent, it must first be associated with a Session. But where does the session come from?  Hibernate's Configuration object instantiates a SessionFactory (Configuration.buildSessionFactory()) which is an expensive, immutable, thread safe object intended to be shared by all application threads. Threads that service client requests must obtain a Session from the factory by calling SessionFactory.getCurrentSession() or SessionFactory.openSession(). &lt;br /&gt;
&lt;br /&gt;
Anyways, a Session is NOT thread safe and there are associated concurrency issues discussed in [https://www.owasp.org/index.php/Hibernate-Guidelines#Session_and_Concurrency_issues this section] of the Hibernate Guidelines page. Once an object is associated with a Session we can begin a transaction. All database communication must occur within the scope of a transaction. A transaction starts with a call to Transaction.begin() or Session.beginTransaction() and ends with a call to Transaction.commit().  &lt;br /&gt;
&lt;br /&gt;
To actually build queries, store and retrieve data we mostly use methods in the Session class. For example, load() will instantiate a class object, and load the state from the database into the instance.  Session.createQuery() will return a Query object which has many methods with which to operate on this query string. Query.setParameter(), setFloat(), and others act similar to prepared statements.  You can also simply call Query.executeUpdate() to execute the query.&lt;br /&gt;
&lt;br /&gt;
''Ok, why don't we just see what it looks like.''&lt;br /&gt;
Example1&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         Session sess = factory.openSession();&lt;br /&gt;
         Transaction tx;&lt;br /&gt;
         try {&lt;br /&gt;
              tx = sess.beginTransaction();&lt;br /&gt;
              Query q = sess.createQuery(&amp;quot;from DomesticCat cat where cat.name = ?&amp;quot;);&lt;br /&gt;
              q.setString(0, &amp;quot;Izi&amp;quot;);&lt;br /&gt;
              tx.commit();&lt;br /&gt;
         }&lt;br /&gt;
         catch (Exception e) {&lt;br /&gt;
             if (tx!=null) tx.rollback();&lt;br /&gt;
             throw e;&lt;br /&gt;
         }&lt;br /&gt;
         finally {&lt;br /&gt;
             sess.close();&lt;br /&gt;
         }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Another simple example using HQL and named parameters...this time we have a helper class to obtain a Session''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction(); //All database communication occurs within the scope of a transaction&lt;br /&gt;
&lt;br /&gt;
        Person aPerson = (Person) session&lt;br /&gt;
                .createQuery(&amp;quot;select p from Person p left join fetch p.events where p.id = :pid&amp;quot;)&lt;br /&gt;
                .setParameter(&amp;quot;pid&amp;quot;, personId); &lt;br /&gt;
&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Security Implications ==&lt;br /&gt;
These issues are discussed in context on this page and are also listed in [https://www.owasp.org/index.php/Hibernate-Guidelines#Important this section] of Hibernate Guidelines.&lt;br /&gt;
&lt;br /&gt;
* No communication with the database should occur outside of a database transaction. Doing so will probably result in synchronization issues. Transactions should also not encompass user think time.  Details are of how it's done is discussed in the [http://www.owasp.org/index.php/Hibernate#Defining_Transaction_Bounds Defining Transaction Bounds section] of this page.  &lt;br /&gt;
&lt;br /&gt;
* createQuery() can easily be passed a tainted SQL or HQL string, dialect is irrelevant. The proper way to construct a sql string hibernate style is to use Query and SQLQuery's setParameter(), setString(), setXXX() methods for named parameter and placeholder binding. Just like prepared statements.  Details are discussed in the [http://www.owasp.org/index.php/Hibernate#Creating_Queries Creating Queries section] of this page.&lt;br /&gt;
&lt;br /&gt;
* Persisting tainted objects is stored xss. Since stored XSS is generally hard to find with static tools, it is best to sanitize all data going in rather than waiting for it to show up on a jsp somewhere. Details of these functions are discussed in the [http://www.owasp.org/index.php/Hibernate#Persisting_Tainted_Data Persisting Tainted Data section] of this page.&lt;br /&gt;
&lt;br /&gt;
* An application should rollback and discard Session instance on error. So if the Session throws an exception, the catch block should have rollback() and finally should call Session.close(). This applies to any SQLException. Pretty cut and dry, see Example1 above. &lt;br /&gt;
&lt;br /&gt;
* You may not mix and match JDBC-style parameters (&amp;quot;?&amp;quot;) and named parameters (:namedparam) in the same query. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Person aPerson = (Person) session&lt;br /&gt;
                .createQuery(&amp;quot;select :somenamedparameter from ? where x = :someothernamedparameter&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Transaction.setTimeout(int) should be called to ensure that misbehaving transactions do not tie up resources in definitely. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Session sess = factory.openSession();&lt;br /&gt;
     try {&lt;br /&gt;
          //set transaction timeout to 3 seconds&lt;br /&gt;
          sess.getTransaction().setTimeout(3);&lt;br /&gt;
          sess.getTransaction().begin();&lt;br /&gt;
          // do some work&lt;br /&gt;
         ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Defining Transaction Bounds ==&lt;br /&gt;
Usually, ending a Session involves four distinct phases:&lt;br /&gt;
&lt;br /&gt;
* flush the session&lt;br /&gt;
* commit the transaction&lt;br /&gt;
* close the session&lt;br /&gt;
* handle exceptions &lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
* If commit() is present, no need to call flush() as it does this already.&lt;br /&gt;
* Most database communication methods only propagate exceptions if they're outside the scope of the session. (this is an assumption based on the many functions whose source I've examined, I won't be perusing the entire api source to back this assumption) &lt;br /&gt;
&lt;br /&gt;
Consider this example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       // Non-managed environment idiom&lt;br /&gt;
       Session sess = factory.openSession();&lt;br /&gt;
       Transaction tx = null;&lt;br /&gt;
       try {&lt;br /&gt;
              tx = sess.beginTransaction();&lt;br /&gt;
              // do some work&lt;br /&gt;
              ...&lt;br /&gt;
              tx.commit();&lt;br /&gt;
       }&lt;br /&gt;
       catch (RuntimeException e) {&lt;br /&gt;
              if (tx != null) tx.rollback();&lt;br /&gt;
              throw e; // or display error message&lt;br /&gt;
       }&lt;br /&gt;
       finally {&lt;br /&gt;
              sess.close();&lt;br /&gt;
       }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most Common Functions:&lt;br /&gt;
&lt;br /&gt;
* Session.beginTransaction() - begin transaction (doh)&lt;br /&gt;
* Session.getTransaction() - begin transaction&lt;br /&gt;
* Session.flush() - end transaction&lt;br /&gt;
* Session.close() - end session&lt;br /&gt;
* Transaction.begin() - begin transaction&lt;br /&gt;
* Transaction.commit() - end transaction&lt;br /&gt;
* Transaction.rollback() -&lt;br /&gt;
&lt;br /&gt;
== Creating, manipulating and executing queries ==&lt;br /&gt;
* The Session interface defines methods that create Query and SQLQuery objects - these are the methods we care about because they allow the developer to construct query strings (as opposed to letting Hibernate perform the sql operations).&lt;br /&gt;
* The Query/SQLQuery objects are mutable and executable, but are not actually SUNK until Transaction.commit(), or Query.executeUpdate() is called. However, I think it is best that we flag functions that create and construct Query objects as they would be in direct contact with tainted data. &lt;br /&gt;
* Once a Query or SQLQuery object is obtained from the Session, the parameters of its sql string should be set using the setter functions like setParameter(), the setters are listed here. These setters check for type mismatch, or guess the type, then check for positional mismatch and named parameter mismatch so they're pretty safe me thinks. Concatenating tainted parameters using the '+' operator, on the other hand, would be equivalent to mis-using a prepared-statement. &lt;br /&gt;
&lt;br /&gt;
Consider this example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     String table = (String) req.getParameter(&amp;quot;table&amp;quot;);//obviously retarded&lt;br /&gt;
     String parameter1 = request.getParameter(&amp;quot;param1&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
     Session session = sessionFactory.getCurrentSession();&lt;br /&gt;
     try{&lt;br /&gt;
          session.beginTransaction();&lt;br /&gt;
                SQLQuery query = session.createSQLQuery(&amp;quot;SELECT * FROM &amp;quot; + table + &amp;quot;WHERE stuff= ?&amp;quot;); /*B00*/&lt;br /&gt;
                query.setParameter(0, parameter1); /*YAY*/&lt;br /&gt;
          session.getTransaction().commit();&lt;br /&gt;
     } catch (Exception e) {} &lt;br /&gt;
     session.close();//omfg no rollback?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most Common Functions:&lt;br /&gt;
&lt;br /&gt;
* Session.createSQLQuery(String queryString) - creates a Query with given SQL string - technically executed on commit() or flush() but this function is more directly related to the taint source.&lt;br /&gt;
* Session.createQuery(String queryString) - creates Query with given HQL string.&lt;br /&gt;
* Session.createFilter(Object collection, String queryString) - creates a Query with filter string.&lt;br /&gt;
* Query.setParameter() - variations on this binds parameters to &amp;quot;?&amp;quot; and &amp;quot;:namedparams&amp;quot;&lt;br /&gt;
* Query.executeUpdate() -&lt;br /&gt;
* Query.getQueryString() -&lt;br /&gt;
&lt;br /&gt;
==== More Examples ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using queries from other Queries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     String sql;&lt;br /&gt;
&lt;br /&gt;
     session.beginTransaction();&lt;br /&gt;
          Query q1 = session.createQuery(taintSQL); //pretend taintSQL came from unchecked input&lt;br /&gt;
          sql = q1.getQueryString(); //get taintSQL&lt;br /&gt;
     session.getTransaction.commit();&lt;br /&gt;
     &lt;br /&gt;
     session.beginTransaction();&lt;br /&gt;
          Query q2 = new QueryImpl(sql, session, parameterMetadata); //reuse taintSQL w/o validation&lt;br /&gt;
          session.getTransaction.commit(); //evil prevails&lt;br /&gt;
     session.close();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using executeUpdate()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     public void executeUpdateHQL(Session session, String evil)//a few calls deep from where evil became tainted&lt;br /&gt;
        {&lt;br /&gt;
          Query query = session.createQuery(evil);  /*B00*/&lt;br /&gt;
          query.setString(&amp;quot;name&amp;quot;,&amp;quot;Evil&amp;quot;);&lt;br /&gt;
          query.setString(&amp;quot;newName&amp;quot;,&amp;quot;EEvil&amp;quot;); //these don't matter if the sql is already evil&lt;br /&gt;
          int rowCount = query.executeUpdate();  /*B00*/&lt;br /&gt;
          System.out.println(&amp;quot;Rows affected: &amp;quot; + rowCount);&lt;br /&gt;
&lt;br /&gt;
          //See the results of the update and some other random stuff&lt;br /&gt;
          query = session.createQuery(&amp;quot;from Supplier&amp;quot;);&lt;br /&gt;
          List results = query.list();            &lt;br /&gt;
&lt;br /&gt;
          displaySupplierList(results);            &lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
named parameter (preferred)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Query q = sess.createQuery(&amp;quot;from DomesticCat cat where cat.name = :name&amp;quot;);&lt;br /&gt;
q.setString(&amp;quot;name&amp;quot;, &amp;quot;Fritz&amp;quot;);&lt;br /&gt;
Iterator cats = q.iterate();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
positional parameter&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Query q = sess.createQuery(&amp;quot;from DomesticCat cat where cat.name = ?&amp;quot;);&lt;br /&gt;
q.setString(0, &amp;quot;Izi&amp;quot;);&lt;br /&gt;
Iterator cats = q.iterate();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
named parameter list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
List names = new ArrayList();&lt;br /&gt;
names.add(&amp;quot;Izi&amp;quot;);&lt;br /&gt;
names.add(&amp;quot;Fritz&amp;quot;);&lt;br /&gt;
Query q = sess.createQuery(&amp;quot;from DomesticCat cat where cat.name in (:namesList)&amp;quot;);&lt;br /&gt;
q.setParameterList(&amp;quot;namesList&amp;quot;, names);&lt;br /&gt;
List cats = q.list();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Executing a bunch of actions (relevant fns listed in the excel sheet)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	private List executions;&lt;br /&gt;
		....&lt;br /&gt;
	executions = new LinkedList();&lt;br /&gt;
		....&lt;br /&gt;
	private void executeActions(List list) throws HibernateException {&lt;br /&gt;
		for ( Iterator execItr = list.iterator(); execItr.hasNext(); ) {&lt;br /&gt;
			execute( (Executable) execItr.next() );&lt;br /&gt;
		}&lt;br /&gt;
		list.clear();&lt;br /&gt;
		session.getBatcher().executeBatch();&lt;br /&gt;
	}&lt;br /&gt;
	public void execute(Executable executable) {&lt;br /&gt;
		final boolean lockQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();&lt;br /&gt;
		if ( executable.hasAfterTransactionCompletion() || lockQueryCache ) {&lt;br /&gt;
			executions.add( executable );&lt;br /&gt;
		}&lt;br /&gt;
		if (lockQueryCache) {&lt;br /&gt;
			session.getFactory()&lt;br /&gt;
				.getUpdateTimestampsCache()&lt;br /&gt;
				.preinvalidate( executable.getPropertySpaces() );&lt;br /&gt;
		}&lt;br /&gt;
		executable.execute();&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persisting tainted data ==&lt;br /&gt;
&lt;br /&gt;
* Assume persistent objects have JavaBeans style setter methods as this is most common practice. When these setters are called with tainted parameters consider this object to be tainted.&lt;br /&gt;
* We should flag all functions where tainted objects are made persistent. Although most documents will define Session.save() or Session.persist() as making an object persistent, it is actually PENDING until a call to Transaction.commit() is made. Whether or not we want to flag the saves, or the commits is up to scan dev - keep in mind that if we're flagging commit() we must first decide that the code between Transaction.begin() or Session.beginTransaction() and Transaction.commit() contains eevil.&lt;br /&gt;
* The only associated cwe I can think of right now is stored xss. &lt;br /&gt;
&lt;br /&gt;
Consider this example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Session session  = sessionFactory.getCurrentSession();&lt;br /&gt;
     String firstname = request.getParameter(&amp;quot;firstname&amp;quot;);&lt;br /&gt;
     String lastname  = request.getParameter(&amp;quot;lastname&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
     try{&lt;br /&gt;
          Transaction tx = session.beginTransaction();&lt;br /&gt;
&lt;br /&gt;
          Person thePerson = session.load(Person.class, new Long(69));//loading an already persistent object&lt;br /&gt;
          thePerson.setFirstname(firstname);// then adding tainted data to it&lt;br /&gt;
          thePerson.setLastname(lastname);&lt;br /&gt;
          session.save(thePerson);  //persisting our changes&lt;br /&gt;
&lt;br /&gt;
          session.getTransaction().commit();&lt;br /&gt;
     } catch (Exception e) {&lt;br /&gt;
          if (tx!=null) tx.rollback();&lt;br /&gt;
          throw e;&lt;br /&gt;
     } &lt;br /&gt;
     session.close();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most Common Functions:&lt;br /&gt;
&lt;br /&gt;
* Session.save(Object object) - save object to the session, object should not contain tainted data.&lt;br /&gt;
* Session.persist(Object object) -&lt;br /&gt;
* Session.void replicate(Object object, ReplicationMode?? replicationMode) -&lt;br /&gt;
* Session.void saveOrUpdate(Object object) -&lt;br /&gt;
* Session.update(Object object)() -&lt;br /&gt;
* Session.evict(Object object)() - remove instance from session cache&lt;br /&gt;
* Session.clear() - evict all loaded instances&lt;br /&gt;
* Session.load(Class theClass, Serializable id) - gets an object from the db for you to manipulate. &lt;br /&gt;
&lt;br /&gt;
[[Category:Hibernate]]&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category:Java]]&lt;/div&gt;</summary>
		<author><name>Nawwar</name></author>	</entry>

	</feed>