<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-32502865</id><updated>2012-02-16T19:10:30.256+05:30</updated><category term='AppSecBestPractice'/><category term='AppSec Buzzwords'/><category term='CrytptographyBasics'/><title type='text'>Application Security by Richard Lewis</title><subtitle type='html'>Application security in-depth.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-32502865.post-7937662340329310998</id><published>2006-11-15T11:25:00.002+05:30</published><updated>2006-11-15T12:04:06.672+05:30</updated><title type='text'>Simple security design review steps</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Know the application&lt;/span&gt;&lt;br /&gt;Every computer application, no matter how complex, consists of components that lie in the following categories&lt;br /&gt;a) Processes&lt;br /&gt;b) Data channels&lt;br /&gt;c) Data stores&lt;br /&gt;d) Interactors&lt;br /&gt;[Readers familiar with DFDs or data flow diagrams will instantly recognise that these categories.] Start out by decomposing the system into smaller components and start creating DFDs of the same. Creating the DFDs will help the reviewer in the following way:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Will give you a deeper understanding of the system.&lt;/li&gt;&lt;li&gt;Will force application teams to think about their application and stimulate security discussions even before the security review begins!&lt;/li&gt;&lt;/ol&gt;Create the DFDs until you (the reviewer) have a fairly good understanding of the system. I would recommend that you draw these diagrams 'online' with the app teams. This allows the app team to correct your thinking as you move on. Dont strive for 100% familiarization with the application.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Identify Threats&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;Behavioural Tips&lt;/span&gt;&lt;br /&gt;Do not adopt an extremist stance when identifying threats. Do not give the app teams the impression that you are policing and judging their application. Remember, you goal is to &lt;span style="font-style: italic;"&gt;prise out&lt;/span&gt; as much as possible from the app team. They are your best source of threats! Dont start out with "Do you realize that your application can be attacked in this manner?". Instead say something like, "Lets try and find out how the application responds to this threat.".&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Technical Tips&lt;br /&gt;&lt;/span&gt;I have come to realize after no matter what your threat, they will always lie in one or more of the following categories:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Loss of confidentiality&lt;/span&gt; - Data ends up getting read by someone other than the intended user.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Loss of integrity&lt;/span&gt; - Data has been tampered with and the system (or user) can no longer trust the data.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Loss of availability&lt;/span&gt; - The application has &lt;span style="font-style: italic;"&gt;gone for a toss  &lt;/span&gt;and is no longer providing the expected quality of service (sluggish or totally down system)&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Damage of the contract between a user and his credentials&lt;/span&gt; - This manifests in the form of repudiating (user denying having carried out certain operations), impostor&lt;span style="font-style: italic;"&gt;ing &lt;/span&gt;(user forging as someone else or worse still, getting through without authenticating to the system)&lt;/li&gt;&lt;/ol&gt;Use these categories to identify threats in the system.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-7937662340329310998?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/7937662340329310998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=7937662340329310998' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7937662340329310998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7937662340329310998'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/11/simple-security-design-review-steps_8388.html' title='Simple security design review steps'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-7313418737592220431</id><published>2006-10-27T13:06:00.000+05:30</published><updated>2006-11-08T14:12:25.138+05:30</updated><title type='text'>Security considerations for user authorization in applications</title><content type='html'>&lt;ol&gt;&lt;li&gt;There exists a clearly defined matrix defines access permissions on resources by different user roles and processes.&lt;/li&gt;&lt;li&gt;Access to sensitive and system resources is restricted to selected roles only.&lt;/li&gt;&lt;li&gt;Authorization is based on Windows authentication&lt;/li&gt;&lt;li&gt;The system uses ACLs (in addition to other) techniques for authorization.&lt;/li&gt;&lt;li&gt;The system uses application-level, (in addition to other) techniques for authorization.&lt;/li&gt;&lt;li&gt;The system uses code access level (in addition to other) techniques for authorization. (e.g.. CAS in dot net)&lt;/li&gt;&lt;li&gt;The authorization mechanism of the application achieves from organizational changes and movements e.g.. Richard is in one role today, another tomorrow. In tomorrow's role he is less privileged than today's.&lt;/li&gt;&lt;li&gt;Identity information is passed without specific protection from one part of the application to the other, only if the sender and the receiver reside in trusted zones.&lt;/li&gt;&lt;li&gt;Identity information is passed by signing/encrypting from one part of the application to the other, if the sender and the receiver reside in non-trusted zones.&lt;/li&gt;&lt;li&gt;Authorization has been performed in the UI tier such that controls are hid/shown based on user authorization. If this is true check the following: the logic for the above is consolidated in a single section of the design documents. Where the behaviour of a control is consistent across pages, a repeater control is used.&lt;/li&gt;&lt;li&gt;The MVC pattern is used for the application.&lt;/li&gt;&lt;li&gt;If the number of roles is less and/or if the pages for each role differ to a large extent then separate UI should be created.&lt;/li&gt;&lt;li&gt;Authorization has been performed in the UI tier such that flow of UI is changed based on type of user&lt;/li&gt;&lt;li&gt;Authorization has been performed in the UI tier such that access to the entry page of the app is configured for authorized users only.&lt;/li&gt;&lt;li&gt;Authorization has been performed in the UI tier such that authorization check is carried out each time a new page is loaded.&lt;/li&gt;&lt;li&gt;Authorization has been performed at the business logic.&lt;/li&gt;&lt;li&gt;Authorization has been performed at the database level.&lt;/li&gt;&lt;li&gt;Access to database tables and other entities is being controlled using SQL Data Definition Language such as GRANT, DENY and REVOKE.&lt;/li&gt;&lt;li&gt;The database rules are being used to enforce security and authorization.&lt;/li&gt;&lt;li&gt;The architecture takes into consideration that no more data is read other than what is required to be displayed to the user. &lt;/li&gt;&lt;li&gt;All operations that perform a business process are authorized.&lt;/li&gt;&lt;li&gt;Authorization functionality is encapsulated as utility classes. (This will obviate the need for non-security minded programmers from having to learn too much about authorization)&lt;/li&gt;&lt;li&gt;Guards are present to ensure that sensitive data cannot propagate outside the data tier.&lt;/li&gt;&lt;li&gt;"If the authorization logic is simple, checks are being made in stored procedures.&lt;/li&gt;&lt;li&gt;If the authorization logic is complex, checks are being made in data access logic components and call SPs."&lt;/li&gt;&lt;li&gt;If an authorization cache is being used then it is protected by encryption (for confidentiality) and is signed (to prevent tampering)&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-7313418737592220431?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/7313418737592220431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=7313418737592220431' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7313418737592220431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7313418737592220431'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/security-considerations-for-user.html' title='Security considerations for user authorization in applications'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-7687713510152465398</id><published>2006-10-27T13:03:00.000+05:30</published><updated>2006-10-27T13:04:39.236+05:30</updated><title type='text'>Security considerations for session management in applications</title><content type='html'>&lt;ol&gt;&lt;li&gt;Authentication cookies are protected in transit by using SSL&lt;/li&gt;&lt;li&gt;The contents of authentication cookies are encrypted.&lt;/li&gt;&lt;li&gt;A session timeout has been factored in the design of the application&lt;/li&gt;&lt;li&gt;Session ids generated for tracking sessions should not be guessable numbers (e.g.. First user who visits the site gets session no. 1, the second user gets 2 and so on.)&lt;/li&gt;&lt;li&gt;Session ids are not reused for a long cycle.&lt;/li&gt;&lt;li&gt;Design supports an elaborate mitigation for session hijacking attacks.&lt;/li&gt;&lt;li&gt;Use one session token with two values during authentication. One value before authentication and one after.&lt;/li&gt;&lt;li&gt;The system does not rely too much on persistent cookies&lt;/li&gt;&lt;li&gt;Guards are present for confidentiality and integrity of cookies.&lt;/li&gt;&lt;li&gt;Are sensitive cookies marked as "secure"&lt;/li&gt;&lt;li&gt;Does the application rely on IP filtering for security?&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-7687713510152465398?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/7687713510152465398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=7687713510152465398' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7687713510152465398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/7687713510152465398'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/security-considerations-for-session.html' title='Security considerations for session management in applications'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-4225115730159186841</id><published>2006-10-27T13:02:00.000+05:30</published><updated>2006-10-27T13:03:15.369+05:30</updated><title type='text'>Security considerations when auditing and logging in applications</title><content type='html'>&lt;ol&gt;&lt;li&gt;The design has a standardized approach to exception handling across the application.&lt;/li&gt;&lt;li&gt;In the case of an exception minimum amount of information is returned to the user.&lt;/li&gt;&lt;li&gt;Lowest level exceptions are encapsulated into a relevant exception for the benefit of the above tiers of the application. (For e.g.. Instead of telling that a certain row/column of the database could not be accessed, it is better to inform a plain "access denied")&lt;/li&gt;&lt;li&gt;Where user actions are being logged, private data should not be written to the log. (e.g.. Changed passwords, critical settings etc.)&lt;/li&gt;&lt;li&gt;The key parameters to be logged and audited have been identified.&lt;/li&gt;&lt;li&gt;The application has levels of auditing and logging.&lt;/li&gt;&lt;li&gt;Application logs have been protected from tampering.&lt;/li&gt;&lt;li&gt;Application logs have been protected from unauthorized access.&lt;/li&gt;&lt;li&gt;Utilities have been factored in for interpretation of log files.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-4225115730159186841?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/4225115730159186841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=4225115730159186841' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4225115730159186841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4225115730159186841'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/security-considerations-when-auditing.html' title='Security considerations when auditing and logging in applications'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-3037830203709531553</id><published>2006-10-27T11:17:00.000+05:30</published><updated>2006-10-27T11:19:58.822+05:30</updated><title type='text'>Security considerations when handling sensitive data</title><content type='html'>&lt;ol&gt;&lt;li&gt;All data along with their criticality have been identified.&lt;/li&gt;&lt;li&gt;A matrix indicating the data and the means to secure it is available in the design document.&lt;/li&gt;&lt;li&gt;All data required to be kept confidential is encrypted.&lt;/li&gt;&lt;li&gt;All data that absolutely must not be tampered is digital signed using private key or using HMAC.&lt;/li&gt;&lt;li&gt;Private information (secrets) is not persisted to disk until necessary.&lt;/li&gt;&lt;li&gt;Private information (secrets) is kept in memory for only as longs as it is necessary.&lt;/li&gt;&lt;li&gt;Private information (secrets) are not stored as literal values in code (no hard-coded values)&lt;/li&gt;&lt;li&gt;Database connection information such as user name and password are not stored in plaintext on disk.&lt;/li&gt;&lt;li&gt;No sensitive data is stored in persisted cookies.&lt;/li&gt;&lt;li&gt;No custom-built algorithms are being used to encrypt data.&lt;/li&gt;&lt;li&gt;If standard algorithms are being used, then the library used to implement them are tested sufficiently. (Watch out for algos like AES, RSA etc. implemented by local app teams)&lt;/li&gt;&lt;li&gt;If standard algos are being used, there is a documented rationale for chosen key sizes.&lt;/li&gt;&lt;li&gt;The encryption key is stored in a secure manner.&lt;/li&gt;&lt;li&gt;There is a provision in the application for changing the keys used for encryption.&lt;/li&gt;&lt;li&gt;There is a provision in the application for rolling over data (i.e. data encrypted with "old" key to be re-encrypted using "new" key)&lt;/li&gt;&lt;li&gt;There is a provision in the application for handling scenarios like "lost key", "lost password to key" and "key compromise"&lt;/li&gt;&lt;li&gt;Sensitive data is not transmitted using GET, as it can be directly seen in the browser address bar.&lt;/li&gt;&lt;li&gt;Sensitive information is not being sent in the HTTP headers as these can be easily changed.&lt;/li&gt;&lt;li&gt;Audit logs are encrypted (if required) , but should be definitely be protected against tampering and loss of integrity.&lt;/li&gt;&lt;li&gt;Where possible, WS-Security or SSL/TLS is used to protect ephemeral data rather than implement crypto schemes out of primitives.&lt;/li&gt;&lt;li&gt;For .NET code, System.Security.Cryptography namespace will be used.&lt;/li&gt;&lt;li&gt;For Java code, JCE providers will be used (Bouncycastle or SunOne)&lt;/li&gt;&lt;li&gt;For C/C++ code CryptoAPI (CSP) will be used&lt;/li&gt;&lt;li&gt;For scripting, CAPICOM will be used&lt;/li&gt;&lt;li&gt;For Windows kernel mode, statically linked version of RSA32.LIB will be used."&lt;/li&gt;&lt;li&gt;The crypto algorithm being used will be easily replaceable. Hard coding is not being done. It is easy to upgrade the algorithms in the future.&lt;/li&gt;&lt;li&gt;If the user of the software does not specify it, strong algorithms are used by default. The software will not "automatically" fall back to a weak crypto.&lt;/li&gt;&lt;li&gt;If symmetric key-based cryptography will be used, then the CBC mode will be used.&lt;/li&gt;&lt;li&gt;If hash functions will be used, then the SHA-2 family of hash functions (SHA-256, SHA-384 or SHA-512) will be used.&lt;/li&gt;&lt;li&gt;The application will DP API (Data Protection API) to store secure data and passwords.&lt;/li&gt;&lt;li&gt;If the application requires random numbers, a strong quality random number generator will be used.&lt;/li&gt;&lt;li&gt;If a secret key is required to be generated from a user password, the user password should not be merely hashed. Instead a KDF (Key derivation function) should be used to derive a key from a password. (Eg. CryptDeriveKey on Windows)&lt;/li&gt;&lt;li&gt;Are cache-control : no-cache or cache-control : no-store used to prevent caching in browser?&lt;/li&gt;&lt;li&gt;Application caters if 128-bit SSL is not supported in the web browser.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-3037830203709531553?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/3037830203709531553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=3037830203709531553' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/3037830203709531553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/3037830203709531553'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/security-considerations-when-handling.html' title='Security considerations when handling sensitive data'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-4520405569745092281</id><published>2006-10-24T08:29:00.001+05:30</published><updated>2006-10-24T08:31:12.777+05:30</updated><title type='text'>Windows registry application security best practices</title><content type='html'>Use the following appsec best practices when dealing with the Windows registry.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use of registry reduces application portability. Therefore, use only if required.&lt;/li&gt;&lt;li&gt;Don’t use the registry as a configuration trash–bin.&lt;/li&gt;&lt;li&gt;Don’t store secrets in registry.&lt;/li&gt;&lt;li&gt;Encrypt application data stored in the registry.&lt;/li&gt;&lt;li&gt;Discourage users from directly editing the registry.&lt;/li&gt;&lt;li&gt;Perform input validation on data read and written to registry.&lt;/li&gt;&lt;li&gt;Don’t write data to HKLM. Reading back the data will require the user to be logged on as administrator as by default only Read-access is provided to HKLM all users.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Don't open registry keys for FULL_CONTROL or ALL_ACCESS.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-4520405569745092281?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/4520405569745092281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=4520405569745092281' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4520405569745092281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4520405569745092281'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/windows-registry-application-security.html' title='Windows registry application security best practices'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-5057420995097797832</id><published>2006-10-17T14:50:00.000+05:30</published><updated>2006-10-17T15:57:00.489+05:30</updated><title type='text'>List of security regulations to comply applications to</title><content type='html'>There are the following regulations that applications have often to comply to:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="tx"&gt;International Standard - ISO 17799&lt;/span&gt;&lt;/li&gt;&lt;li style="font-weight: bold;"&gt;&lt;span class="tx"&gt;California AB 1950 and SB 1386 - Personal Information  Privacy&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Children's Online Privacy Protection Act of 1998&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Director of Central Intelligence Directive series&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Regulation E - Electronic Fund Transfer&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;General - EU Directive Applicability&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Federal Information Security Management Act (FISMA)&lt;/span&gt;&lt;/li&gt;&lt;li style="font-weight: bold;"&gt;&lt;span class="tx"&gt;The Gramm-Leach-Bliley Act (GLBA) -  Act of 1999&lt;/span&gt;&lt;/li&gt;&lt;li style="font-weight: bold;"&gt;&lt;span class="tx"&gt;The Health Insurance Portability and Accountability Act (HIPAA)  of 1996&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;International Standard - ISO 27001&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Japan's Personal Information Protection Act&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;MasterCard Site Data Protection Program (SDP)&lt;/span&gt;&lt;span class="m"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;North American Electric Reliability Council (NERC) Critical  Infrastructure Protection Committee (CIPC) Security Guidelines for the  Electricity Sector&lt;/span&gt;&lt;/li&gt;&lt;li&gt;OWASP 10 Most Critical Web Application Security Vulnerabilities&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;" class="tx"&gt;Payment Card Industry Data Security Standard (PCI)&lt;/span&gt;&lt;span class="m"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Personal Information Protection and Electronic Documents Act  (PIPED Act)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;The Privacy Act of 1974&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Safe Harbor&lt;/span&gt;&lt;/li&gt;&lt;li&gt;SANS Top 20 Internet Security Vulnerabilities&lt;/li&gt;&lt;li&gt;Securities Exchange Act of 1934&lt;/li&gt;&lt;li style="font-weight: bold;"&gt;Sarbanes-Oxley Act of 2002&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;Title 21 Code of Federal Regulations (21 CFR Part 11) Electronic  Records&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;UK Data Protection Act 1998&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Visa Cardholder Information Security Program (CISP)&lt;/li&gt;&lt;li&gt;&lt;span class="tx"&gt;WASC Web Security Threat Classification&lt;/span&gt;&lt;/li&gt;&lt;li style="font-weight: bold;"&gt;BASEL II&lt;/li&gt;&lt;/ol&gt;&lt;span class="tx"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-5057420995097797832?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/5057420995097797832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=5057420995097797832' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/5057420995097797832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/5057420995097797832'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/list-of-security-regulations-to-comply.html' title='List of security regulations to comply applications to'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-9026819937797419116</id><published>2006-10-12T12:44:00.000+05:30</published><updated>2006-10-12T16:17:01.134+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='AppSecBestPractice'/><title type='text'>Temporary Files Security In-depth</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Many applications require to create and maintain temporary files. Often these temporary files are created without the enduser knowing about the same. Security attacks realized due to insecure temporary file management is a critical category of security attacks on software applications. Application developers are required to follow certain security best practices when creating temporary files. In this article I shall discuss these best practices.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;Vulnerabilities due to poor tmp file implementations&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;Attack#1 &lt;/span&gt;&lt;br /&gt;victim.c:&lt;br /&gt;    filename = mktemp(template);&lt;br /&gt;    fd = open(filename, …);&lt;br /&gt;&lt;br /&gt;But an adversary can create a file with the same name between the two statements.&lt;br /&gt;Then, victim.c will either end up opening the adversary’s file, or will fail to create the temporary file itself.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Attack#2 Symbolic Link Vulnerability&lt;/span&gt;&lt;br /&gt;If the attacker knows where the application creates its temporary files and can guess the name of the next temporary file, the following attack can be realized:&lt;br /&gt;- Attacker will put a symbolic link at the temporary file location.&lt;br /&gt;- The attacker will link the symbolic link to a privileged file.&lt;br /&gt;- Now, the application will unknowingly write to the privileged file instead of writing to the file in the temp directory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Security Considerations when designing Temporary File modules&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. Avoid temporary files altogether&lt;/span&gt;&lt;br /&gt;Temporary files often end up creating more problems than solving them. The effort (time/money) required to develop a temporary file management module often outweighs the features that get added to the application.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Reasearch the platform support for temporary files&lt;/span&gt;&lt;br /&gt;Before starting out to code the temporary file generation module, assess the existing support for file generation on the target platform. For example, Windows has the GetTempPath() API call that provides the default temporary directory path.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. Ensure file name uniqueness&lt;/span&gt;&lt;br /&gt;The filename of the temporary file must be unique. This ensures that the application does not end up clobbering any existing data on the disk. If a file having the same name already exists on the disk, the logic of file name generation should generate (see next point) a new  file name and use that instead.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4. Ensure file name randomness&lt;/span&gt;&lt;br /&gt;When generating the file name of the temporary file ensure that the name is not guessable. Typically, the default APIs that are supplied by the operating system for generating temporary files create filenames containing monotonically increasing integers. Therefore it becomes possible to predict the filename of the next temporary file that the application will generate. Use cryptography to generate unique file names. For eg. the CryptGenRandom() function may be used to achieve this.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5. Ensure proper permissions for the temporary file&lt;/span&gt;&lt;br /&gt;Ensure that the temporary file have the appropriate ACLs (access control lists) set on them. Avoid publically writable temporary directories if possible.  If using a publically writable directory, make a directory within the publically writable directory for temporary files, with read and write permissions for the application only. Temporary files are often used to hold intermittent state information about the operation in progress and may contain confidential information.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;6. Ensure secure cleanup of temporary files after usage&lt;/span&gt;&lt;br /&gt;One of the most common attacks on applications that use temporary files is the recovery of previously deleted temporary files from the disk. This is trivially possible with the help of software available on the Internet. In order to mitigate against this operation, shred temporary files. Depending on the sensitivity of the information contained in the temporary file, ensure that the cleanup is commensurate with the security levels desired.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;7. Prevent covert access&lt;/span&gt;&lt;br /&gt;Sometimes the application's temporary files containing sensitive information may be indexed by the underlying Operating System service that may be active on the user system. For example, the indexing service on Windows, when active, silently builds an index of all files on disk. It is possible that sensitive information will end up getting indexed so that a malicious user may use the Search Files/Folders feature to obtain application intelligence.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;8. Dont use dangerous functions for temporary file generation&lt;/span&gt;&lt;br /&gt;Dont use mktemp(), tmpnam(), tempname(), tmpfile() for generating temporary files. Also don’t reuse the parameter in mkstemp(f) in any other function call, such as stat(), chmod(), etc because the same name may refer to a different file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;9. Avoid storing very sensitive information in temporary files&lt;/span&gt;&lt;br /&gt;As a rule, avoid storing sensitive information in temporary files. This is a very common reason for most attacks on applications. An application may employ sophisticated security safeguards such as encryption for securing its data but between encryption may be unwittingly storing sensitive information to an unprotected temporary file. Avoid this at all costs.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;10. Rely on absolute file paths and file handles&lt;/span&gt;&lt;br /&gt;When building the file paths of the temporary file, use absolute paths. Do not use relative file paths. Also, if the directory path where the temporary files are being housed is being accepted from the user, ensure that it has been sanitised. To prevent time-of-check-to-time-of-use (TOCTOU) attacks, ensure that you use file handles (and not file paths) for future access to the temporary files. Many a vulnerability have been imputed to applications using relative file paths for temporary file access.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;11. Securely create temporary files&lt;/span&gt;&lt;br /&gt;If open() is being used to create a temporary file use the O_CREAT|O_EXCL flags. If the Windows CreateFile() is being used to create a temporary file use the CREATE_NEW attribute. Calling the APIs with these flags ensures that these APIs fail if a file is already present with the same name in the temporary directory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Conclusion&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;Temporary files are sometimes very useful for the application developer. However, improper implementation of temp file modules leads to the realization of several attacks on the application. The application developer must use the techniques contained in this article to mitigate against these security issues.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-9026819937797419116?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/9026819937797419116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=9026819937797419116' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/9026819937797419116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/9026819937797419116'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/temporary-files-security-in-depth.html' title='Temporary Files Security In-depth'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-4160473479770384966</id><published>2006-10-05T14:21:00.000+05:30</published><updated>2006-10-05T14:47:17.675+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CrytptographyBasics'/><title type='text'>When to consider cryptography in your application</title><content type='html'>Cryptography &lt;span style="font-weight: bold;"&gt;DOES&lt;/span&gt; provides the following services to applications:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;a) Confidentiality &lt;/span&gt;&lt;br /&gt;Prevents application from being read and disclosed to everyone except for the intended recipient. This is achieved using encryption.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;b) Authentication&lt;/span&gt;&lt;br /&gt;Provides techniques using which the sender of a message (or originator of the data) can be authenticate reliably. This is achieved using message digesting and encryption.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;b) Integrity&lt;/span&gt;&lt;br /&gt;Provides a tamper-detection and tamper-evident technique for detecting if the message has been tampered since it was first generated. This is achieved using HMACs and digital signatures.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;c) Non-repudiation&lt;/span&gt;&lt;br /&gt;Provides a means for preventing an entity from denying an operation was carried out by that entity by providing conclusive proof. This too is achieved using digital signatures.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;d) Replay protection&lt;/span&gt;&lt;br /&gt;Provides techniques that can be used to prevent a previous message from being replayed to recreate the desired operation. This is done with a combination of message digesting and timestamps.&lt;br /&gt;&lt;br /&gt;Cryptography &lt;span style="font-weight: bold;"&gt;DOES&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;NOT &lt;/span&gt;provides the following services to applications:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;a) Denial of service protection&lt;/span&gt;&lt;br /&gt; Cryptography represents an operation carried out on data. It does not (and cannot) prevent DoS attacks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;b) Preventing Eavesdropping&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;c) Providing access control&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-4160473479770384966?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/4160473479770384966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=4160473479770384966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4160473479770384966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/4160473479770384966'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/10/when-to-consider-cryptography-in-your.html' title='When to consider cryptography in your application'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-788067361396218552</id><published>2006-09-29T15:17:00.000+05:30</published><updated>2006-09-29T15:19:14.429+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='AppSecBestPractice'/><title type='text'>AppSec Best Practice#2 - User Authentication using Passwords</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger2/5201/3967/1600/SecureAuth.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger2/5201/3967/320/SecureAuth.jpg" alt="" border="0" /&gt;&lt;/a&gt;In this post, I have described the accepted secure manner in which web applications must authenticate their users.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-788067361396218552?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/788067361396218552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=788067361396218552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/788067361396218552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/788067361396218552'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/09/appsec-best-practice2-user.html' title='AppSec Best Practice#2 - User Authentication using Passwords'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115950550987857027</id><published>2006-09-29T10:04:00.002+05:30</published><updated>2006-09-29T12:50:56.026+05:30</updated><title type='text'>Using SSL in your applications - think again</title><content type='html'>We are used to the padded lock that appears at the bottom of the browser when visiting sites having the https:// prefix.  That's a visual cue to indicate that SSL is active for that web session.  SSL is used by web application architects as a security mechanism to protect data. However there are a few limitations to bear in mind when relying only on SSL for your application security needs.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;1. SSL operates at the transport level not at the application level&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;This simply means that do not use SSL to protect persistent data on your PC. SSL protects data on when it is on the wire between the client and the server. The data is decrypted after it has reached its destination. Consider this example - You enter in your credit card number on a web page. Assuming SSL is active, the credit card number is encrypted before leaving your PC. The encrypted credit card number travels protected over the wire right upto the web server, at which point it is decrypted by SSL. Thereafter the data is in clear. It is the responsibility of the web application to protect it after that point.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;2. SSL protects either all the data or none at all&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;As mentioned in the previous point, SSL operates at the transport level. This means that applications do not get to decide what they wish to encrypt and what they dont. This can have performance impacts in some cases as I have found that a site that uses SSL through out its pages turns out kind of slow. If SSL is active, all data is protected. Period.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;3. SSL does not provide non-repudiation services&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;Non-repudiation means the ability to provide irrefutable evidence that a certain operation had been carried out. SSL does not, and cannot, provide that service.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;4. SSL is not always effective for securing web services&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;Web services are not always front-ended by web servers. There often arises a scenario in which the application directly communicates with the web service (without intervention of the web server). In such cases, SSL does not help.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115950550987857027?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115950550987857027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115950550987857027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115950550987857027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115950550987857027'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/09/using-ssl-in-your-applicat_115950550987857027.html' title='Using SSL in your applications - think again'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115735221822232293</id><published>2006-09-04T12:10:00.000+05:30</published><updated>2006-09-04T12:15:28.600+05:30</updated><title type='text'>C/C++ CodeSec QuickTip#1 Memory Management</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;Applies to&lt;/span&gt;&lt;br /&gt;Whenever some memory is being allocated using new, for example.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;What to Check For&lt;/span&gt;&lt;br /&gt;Ensure that delete will be called properly. Ensure that all exceptions are being caught for code following the new. Consider the following code:&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102);font-family:courier new;" &gt;int * myint = new int;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102);font-family:courier new;" &gt;//some work - with no exception handling&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102);font-family:courier new;" &gt;delete myint;&lt;/span&gt;&lt;br /&gt;What will happen if an exception occurs in the second line of code? The delete will not be called and a memory leak will exist.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Why&lt;/span&gt;&lt;br /&gt;Although you may take great pains to match new and delete, the delete may end up not being called due to very different reasons.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;How to Check&lt;/span&gt;&lt;br /&gt;1.    Search for all locations in code where memory is being allocated.&lt;br /&gt;2.    Identify how the corresponding memory is being deallocated.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;How to Fix&lt;/span&gt;&lt;br /&gt;If ever you need to use new and delete, do ensure to new in the constructor and delete in the destructor. This is the only guarantee that the memory will be freed.&lt;br /&gt;If you cannot always do a new in the constructor, then ensure that there arent any alternate code paths. For example, change of logic in code that prevents the deallocation code from executing. Another example (as described above) is when an unhandled exception occurs and the deallocation code is altogether skipped.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Problem Example&lt;/span&gt;&lt;br /&gt;int * myint = new int;&lt;br /&gt;//some work - with no exception handling&lt;br /&gt;delete myint;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Solution Example&lt;/span&gt;&lt;br /&gt;int * myint = new int; //FIX: Move this code to the constructor&lt;br /&gt;//some work - with no exception handling&lt;br /&gt;delete myint; //FIX: Move this code to the constructor&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115735221822232293?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115735221822232293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115735221822232293' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115735221822232293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115735221822232293'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/09/cc-codesec-quicktip1-memory-management.html' title='C/C++ CodeSec QuickTip#1 Memory Management'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115700195368589571</id><published>2006-08-31T10:39:00.000+05:30</published><updated>2006-08-31T13:20:50.523+05:30</updated><title type='text'>Canonicalization Attacks</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;What are canonicalisation attacks?&lt;/span&gt;&lt;br /&gt;Unauthorised access of file and directories on the web server machine by tampering file/directory paths that a web site normally allows users to enter as part of its functionality. The attack is typically carried out by entering the path of the file in input field on a web page or by supplying it as part of the URL.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the consequences?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Loss of confidentiality, integrity and a denial of service results if files are deleted.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;What files can the attacker access?&lt;/span&gt;&lt;br /&gt;Any file or folder on the disk(s) of the web server m/c.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Defending applications against canonicalisation attacks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(102, 51, 255);"&gt;- Administrative Controls&lt;/span&gt;&lt;br /&gt;a) Ensure that the web server hosts on a secure file system like NTFS.&lt;br /&gt;&lt;br /&gt;b) Set ACL (access control lists) on files and folders. This can be done by setting appropriate permissions in the [Security] tab in the [Properties] tabpage of files and folders. Ensure that only administrators can access sensitive files and folders.&lt;br /&gt;&lt;br /&gt;c) Do not keep sensitive files, source code or any such material on the web server machine.&lt;br /&gt;&lt;br /&gt;d) Turn-off MS-DOS file name (8.3) convention on the machine by adding the following setting to the &lt;span style="font-family:courier new;"&gt;HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Control \FileSystem &lt;/span&gt;registry key: &lt;span style="font-family:courier new;"&gt;NtfsDisable8dot3NameCreation : REG_DWORD : 1.&lt;/span&gt;&lt;br /&gt;Note that this option does not remove previously generated 8.3 filenames.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(102, 51, 255);"&gt;- Programming Controls&lt;/span&gt;&lt;br /&gt;a) White-list directories that you would like to have your application access rather than black-list them.&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;    BAD WAY:&lt;/span&gt;&lt;br /&gt;    string InputFilePath = GetPathFromUser();&lt;br /&gt;     if ( InputFilePath = = "Secret Directory")&lt;br /&gt;         Output ("Access Denied")&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;    CORRECT WAY&lt;/span&gt;&lt;br /&gt;    string InputFilePath = GetPathFromUser();&lt;br /&gt;     if ( InputFilePath startsWith "Application-accessible Directory")&lt;br /&gt;         allow Further operations...&lt;br /&gt;    else&lt;br /&gt;        Output ("Access Denied")&lt;br /&gt;&lt;br /&gt;b) If ACLs have been set (Point b in Administrative Controls, above) then turn on Integrated Windows Authentication (in IIS) and impersonate using the WindowsIdentity class in your .NET code.&lt;br /&gt;&lt;br /&gt;c) Filter the user input path by subjecting it to &lt;span style="font-family:courier new;"&gt;MapPath &lt;/span&gt;in .NET. MapPath( ), according to MSDN, maps the virtual path in the requested URL to a physical path on the server . To prevent the path from mapping to a path in another application on the same server, set MapPath's third parameter to &lt;span style="font-family:courier new;"&gt;false&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;d) Use regular expressions to control the file\folders that can be accessed. This can be implemented in a) above.&lt;br /&gt;&lt;br /&gt;e) Reduce UTF-8 to its canonical form. UTF-8 text can be represented in multiple forms - guard against this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115700195368589571?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115700195368589571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115700195368589571' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115700195368589571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115700195368589571'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/canonicalization-attacks.html' title='Canonicalization Attacks'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115692685911767455</id><published>2006-08-30T11:09:00.000+05:30</published><updated>2006-08-30T14:04:19.223+05:30</updated><title type='text'>HTTP Fingerprinting</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;What is HTTP Fingerprinting?&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;HTTP Fingerprinting is a technique that helps determine the following:&lt;br /&gt;a) The web server software hosting the website&lt;br /&gt;b) Version and other deployment details of the webserver&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;How does HTTP Fingerprinting help?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;Depends on which side you are looking from. From a bonafide perspective, HTTP fingerprinting allows n/w administrators to profile the webservers in their environment and monitor patches. It also allows an pen-tester/security auditor to narrow down the list of attacks that the server must be subject to expose vulnerabilities.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;Why is HTTP Fingerprinting possible?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;Try this. Ask a programmer to implement a string comparison function. Provide the flowchart that details the logic. Now ask another programmer to do the same. Provide the same flowchart to this programmer too. You can be sure that the implementations, although accurate, would be dissimilar. The same goes for the way in which HTTP web servers are implemented. There are several vendors in the market today viz. Microsoft, Apache, Netscape and the list goes on. The web server implementations from each of these vendors have their own nuances and subtleties in which they implement the HTTP protocol. This, unfortunately, is the reason why HTTP Fingerprinting becomes possible!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;How does one go about HTTP fingerprinting?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;&lt;span style="font-style: italic;"&gt;- Use banner grabbing&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Try the following,&lt;br /&gt;    (i) run &lt;span style="font-family: courier new;"&gt;&lt;span style="font-weight: bold;"&gt;telnet IP_Address 80&lt;/span&gt; &lt;span style="font-family: arial;"&gt;at the command prompt. Substitute IP_Address with the IP address of the machine hosting the web server.&lt;br /&gt;    (ii) Type in the telnet window &lt;/span&gt;&lt;/span&gt;  &lt;span style="font-weight: bold; font-family: courier new;"&gt;HEAD / HTTP/1.0&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: arial;"&gt;    (iii) Press Enter.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: arial;"&gt;    (iv) Press Enter again.&lt;br /&gt;If all runs fine, what you should see is the web server banner! Feast on the information that you will see. You should be able to determine the following:&lt;br /&gt;- The default home page configured for the site&lt;br /&gt;- The last time the page was modified&lt;br /&gt;- The web server running along with its version&lt;br /&gt;- The time on the server&lt;br /&gt;...and lots more.&lt;br /&gt;Banner grabbing allows an attacker to get vital information about the web server software running on the box. It allows script kiddies (and determined hackers) to narrow down to the Achille's heel of the website. The other things you can do is best left to your imagination!&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;&lt;span style="font-style: italic;"&gt;- Difference in HTTP implementations&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;This involves subjecting the web server to different HTTP messages and observing the responses. These responses are then compared to expected responses from the corresponding web servers. Matches will indicate a correct recognition of the web server.&lt;br /&gt;Illustrating this point, Microsoft IIS 6.0 when subject to a &lt;span style="font-weight: bold; font-family: courier new;"&gt;HEAD / HTTP/1.0 &lt;/span&gt;emits out a response in which &lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;Server &lt;/span&gt;&lt;/span&gt;and &lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;Date &lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;are &lt;span style="font-weight: bold; font-family: courier new;"&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/span&gt;contiguous. The same is not seen for other web servers. More examples can be found at &lt;a href="http://net-square.com/httprint/httprint_paper.html"&gt;http://net-square.com/httprint/httprint_paper.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;How does one prevent HTTP fingerprinting?&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;- By changing the HTTP server banner string to something obscure or misleading&lt;br /&gt;&lt;br /&gt;- Transposing the HTTP headers so as to remove any points of distinction&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;- &lt;/span&gt;&lt;span style="font-style: italic;"&gt;Using custom HTTP error codes such as 404 or 500&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;- &lt;/span&gt;&lt;span style="font-style: italic;"&gt;Using HTTP server plug-ins available that allow you to do some of the above&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;HTTP Fingerprinting Bottomline&lt;br /&gt;&lt;/span&gt;&lt;/span&gt; HTTP fingerprinting remains the "entry-point" for a user (whatever his/her intentions) and offers him/her a clear line-of-sight perspective. HTTP fingerprinting also remains a necessary evil.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115692685911767455?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115692685911767455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115692685911767455' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115692685911767455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115692685911767455'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/http-fingerprinting.html' title='HTTP Fingerprinting'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115572936637255293</id><published>2006-08-16T17:02:00.000+05:30</published><updated>2006-08-23T09:46:19.520+05:30</updated><title type='text'>Encryption considerations in software applications</title><content type='html'>Encryption is the new buzzword that is often recommended as the panacea for most security ills. I do not disagree, however, there are a few caveats that you need to consider before using encryption:&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;1. How will the encryption keys be generated?&lt;br /&gt;&lt;/span&gt;A primary requirement when generating cryptographic keys is that they should be random or unpredictable. Unfortunately, the problem with generating random numbers is that you have to supply a sufficiently random number as seed in the first place - a classical chicken and the egg situation. Having said this, however several techniques (to be covered in a future post) exist to generate random numbers.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;2. What encryption technique will your application use?&lt;br /&gt;&lt;/span&gt;First things first. Hashing, message digesting and digital signatures DO NOT constitute encryption. Encryption means garbling of data with the help of a secret "encryption key" and ungarbling it using a secret (of course) "decryption key".&lt;br /&gt;When encryption key == decryption key, this is called Symmetric Key encryption.&lt;br /&gt;When encryption key != decryption key, this is called Asymmetric Key (or Public Key) encryption.&lt;br /&gt;You need to decide first whether your application will use symmetric or asymmetric key encryption. Each of these have their +/- but you need to decide which one to use. [Note: When you use asymmetric key encryption, you often end up using symmetric key but that's another story]&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;3. What encryption algorithm will you use for encryption?&lt;br /&gt;&lt;/span&gt;Algorithms are nothing but the sequence of steps to be carried out when encrypting data and decrypting (usually the reverse) previously encrypted data. Enough has been written about not using home-grown encryption algorithms, so lets assume that you are planning to use a standard and tested algorithm. Here's what I recommend -&lt;br /&gt;Symmetric key encryption - Use AES (Rijndael - pronounced "Rhine doll")&lt;br /&gt;Aysmmetric key encryption - Use ECC, else use the prolific RSA algorithm.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;4. What are the recommended key sizes to be used?&lt;/span&gt;&lt;br /&gt;This is a function of the application's security requirements. If you are protecting low-worth data you can can settle for smaller key sizes than when protecting high-worth data. But there are two important points to remember:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Key sizes for symmetric and asymmetric algorithms vary greatly from each other.&lt;/li&gt;&lt;li&gt;When using a &lt;span style="FONT-WEIGHT: bold"&gt;both &lt;/span&gt;symmetric and asymmetric algorithms, ensure that the crack resistivity provided by the combination is equivalent or higher than that required by the application.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115572936637255293?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115572936637255293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115572936637255293' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115572936637255293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115572936637255293'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/encryption-considerations-in-software.html' title='Encryption considerations in software applications'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115570559286134742</id><published>2006-08-16T10:49:00.000+05:30</published><updated>2006-08-16T10:49:52.876+05:30</updated><title type='text'>What is a security pattern?</title><content type='html'>Security patterns are nothing but established ways of implementing security features in applications. Lets try and understand why we need security patterns. More than often, developers are confronted with a situation in which only the application features to be implemented are given to them, leaving them with the onerous task of implementing those features. Now there is nothing wrong with that, except that security of the feature take a back seat. Lets take a simple example. Say, you have been asked to develop a user login module. This module accepts a user name and password from the user and authenticates the user against the password stored in database. When the developer begins to code this feature he will naturally focus only on the functionality and the means to the end. He will care little (and it is not in his interest to) about the security best practices to be followed, both in design and coding. Clearly something is missing. Consider the following. What if...&lt;br /&gt;the developer had a pre-existing security design that he could use for implementing a feature? A design that was resilient to the possible attacks on his module and that incorporated globally-accepted best practices.&lt;br /&gt;he was not required to worry about the "hows", "whys" and "whats" of security for that feature?&lt;br /&gt;Security patterns come in and fulfil that need. [Btw, this blog contains several such security patterns and best practices that you can use to develop more secure applications. Have fun.]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115570559286134742?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115570559286134742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115570559286134742' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115570559286134742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115570559286134742'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/what-is-security-pattern.html' title='What is a security pattern?'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115527149889631747</id><published>2006-08-11T10:04:00.000+05:30</published><updated>2006-08-13T06:34:17.566+05:30</updated><title type='text'>Application Database Security</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3372/3554/1600/Database%20Security.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3372/3554/400/Database%20Security.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In this post, I shall discuss the significance of database security and the security gotchas to consider. [I shall discuss the steps to take to mitigate these security risks in a separate post.]&lt;br /&gt;&lt;br /&gt;Refer to the figure above. Note the following when viewing the figure:&lt;br /&gt;a) The lower two machines viz. the bonafide client and the bonafide server represent the trustworthy systems.&lt;br /&gt;b) The upper two machines represent bogus machines either physically or logically placed in your application environment.&lt;br /&gt;c) Security considerations appear in red circles with numbers in them. viz. 1 through 6.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Security Considerations&lt;/span&gt;&lt;br /&gt;(1) Database client subversion&lt;br /&gt;(2) Database client impersonation (masquerade)&lt;br /&gt;(3) Database server subversion&lt;br /&gt;(4) Database server impersonation (masquerade)&lt;br /&gt;(5) Vulnerabilities related to data flowing between the client and the server&lt;br /&gt;(6) Vulnerabilities related to data stored on the database server&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115527149889631747?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115527149889631747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115527149889631747' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115527149889631747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115527149889631747'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/application-database-security.html' title='Application Database Security'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115521111487925266</id><published>2006-08-10T17:24:00.000+05:30</published><updated>2006-08-10T17:28:34.880+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='AppSecBestPractice'/><title type='text'>AppSec Best Practice#1 - User Account Lockouts</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3372/3554/1600/ImplementingAccountLockoutsInSoftwareApplications_RichardLewis.0.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3372/3554/320/ImplementingAccountLockoutsInSoftwareApplications_RichardLewis.0.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;User account lockouts should be designed with caution. Take a look at what you must do - a programmers perspective. Note that this is agnostic of application types viz. web, desktop etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115521111487925266?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115521111487925266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115521111487925266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115521111487925266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115521111487925266'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/appsec-best-practice1-user-account.html' title='AppSec Best Practice#1 - User Account Lockouts'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115521074242017386</id><published>2006-08-10T16:22:00.000+05:30</published><updated>2006-08-10T17:22:22.430+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='AppSec Buzzwords'/><title type='text'>Single Sign-On (SSO) and SAML (Security Assertion Markup Language)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;What is SSO?&lt;/span&gt;&lt;br /&gt;&lt;span lang="EN-GB"&gt;Single Sign-On (SSO) requires a user to authenticate himself to a service&lt;i style=""&gt; one time &lt;/i&gt;and does not require reauthentication for other services of the system linked by the SSO framework.&lt;/span&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span lang="EN-GB"&gt;SSO addresses a common issue – that of requiring users to manage and remember authentication credentials (usually a username/password pair) for every service or application they have been subscribed to. &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span lang="EN-GB"&gt;SSO requires that users need remember only one set of authentication credentials. This set of authentication credentials is “passed-on” to other SSO-enabled services (or applications) so that the user can use them transparently without having to reauthenticate.&lt;/span&gt;&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger2/5201/3967/1600/SAML.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger2/5201/3967/320/SAML.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-weight: bold;" lang="EN-GB"&gt;How is SSO &lt;/span&gt;&lt;span lang="EN-GB"&gt;&lt;span style="font-weight: bold;"&gt;typically implemented&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;You can implement SSO using your own bespoke SSO logic implementation or you can use a standards-based technique. Either option has it’s own advantages and disadvantages.&lt;br /&gt;Advantages of bespoke programming means that you have a lot of versatility and you are in the driver’s seat when deciding the level of SSO you are looking at. There are disadvantages too, however. Chief among them are reliance on in-house expertise (which is often not available or insufficient) and lack of scalability, extensibility and performance.&lt;br /&gt;On the other hand if you adopt standards-based techniques you are assured of an industry-accepted solution which augurs well for the reliability, scalability, extensibility and performance of the application. Disadvantages, typically, are associated with implementation teams having to learn “another new” standard and code to the specification, although one may counter-argue that implementations may already exist in the market.&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Techniques used for SSO&lt;/span&gt;&lt;br /&gt;Proxy-based SSO and SAML-based SSO are two most common techniques used for SSL implementation. This article does not go into the details of proxy-based SSO.&lt;/p&gt;&lt;span style="font-weight: bold;"&gt;Enter SAML&lt;/span&gt;&lt;br /&gt;SAML is yet another acronym for you to remember. It stands for &lt;span style="font-style: italic;"&gt;Security Assertion Markup Language&lt;/span&gt;. The ‘ML’ in the name gives away that SAML is XML based.&lt;br /&gt;Here’s the single important reason why applications need SAML – SAML allows seamless inter-domain sharing of security information. This was not easy before SAML was created.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Thumb-rule for determining if my application requires SAML&lt;/span&gt;&lt;br /&gt;This answer is answered by asking this simple question:&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Does your application, either currently or in the near future, have a business need for offering a seamless user experience of service usage across business partners and other 3rd party service providers?&lt;/span&gt;&lt;br /&gt;If the answer to the above question is ‘Yes’, your application needs SAML&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Some advantages afforded by SAML?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;1.    Platform neutrality &lt;/span&gt;&lt;br /&gt;SAML abstracts the security framework away from platform architectures and particular vendor implementations. This makes security more independent of application logic which is an important tenet of Service-Oriented Architecture.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;2.    Loose coupling of directories/databases&lt;/span&gt;&lt;br /&gt;SAML does not require user information to be maintained and synchronized between directories/databases.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;3.    Improved online experience for end users &lt;/span&gt;&lt;br /&gt;SAML enables single sign-on by allowing users to authenticate at an identity provider and then access service providers without additional authentication. In addition, identity federation (linking of multiple identities) with SAML allows for a better-customized user experience at each service while promoting privacy.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;4.    Reduced administrative costs for service providers &lt;/span&gt;&lt;br /&gt;Using SAML to "reuse" a single act of authentication (such as logging in with a username and password) multiple times across multiple services can reduce the cost of maintaining account information. This burden is transferred to the identity provider.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;5.    Risk transference &lt;/span&gt;&lt;br /&gt;SAML can act to push responsibility for proper management of identities to the identity provider, which is more often compatible with its business model.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115521074242017386?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115521074242017386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115521074242017386' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115521074242017386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115521074242017386'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/single-sign-on-sso-and-saml-security.html' title='Single Sign-On (SSO) and SAML (Security Assertion Markup Language)'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115520648412441499</id><published>2006-08-10T16:02:00.001+05:30</published><updated>2006-08-10T16:13:21.176+05:30</updated><title type='text'>OWASP, Mumbai Chapter  - 2nd Meet - 31-July -06</title><content type='html'>I spoke on the &lt;span style="font-weight: bold;"&gt;Significance of Random Numbers in Application Security&lt;/span&gt;. I started off with the practical usage of random numbers. I explained how good random number generation prevents applications from malfunctioning, increases strength of cryptographic operations which in turn increases entropy associated with the key.&lt;br /&gt;I went on to explain how random numbers automate otherwise manual tasks and how it increases the security of application. Explaining the concepts of entropy and seeds I explained the level it should be reached in an application. Finally, I spoke about the various sources of random numbers.I also showed developers the simple mathematics required to calculate minimum password lengths, given the security requirements.&lt;br /&gt;&lt;br /&gt;You can find my presentation &lt;a href="http://owasp.mumbai.googlepages.com/RichardLewis_RandomNumberSignificance.ppt"&gt;here.&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.owasp.org/images/2/28/RichardLewis_SecureCodingFundamentals.ppt"&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115520648412441499?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115520648412441499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115520648412441499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520648412441499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520648412441499'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/owasp-mumbai-chapter-2nd-meet-31-july.html' title='OWASP, Mumbai Chapter  - 2nd Meet - 31-July -06'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115520633464818836</id><published>2006-08-10T16:02:00.000+05:30</published><updated>2006-08-10T16:12:32.270+05:30</updated><title type='text'>OWASP, Mumbai Chapter  - 1st Meet - 24-June-06</title><content type='html'>&lt;p&gt;I presented on &lt;span style="font-weight: bold;"&gt;Secure Coding Fundamentals&lt;/span&gt; and elucidated the Cost factor inculcated due to insecure code resulting in Network Cost, Productivity Cost and so on. Further explaining the basic reasons of threat to code, I explained how the mistakes done by the Programmers, I/O, API Abuse, Environment &amp; Configuration and Time &amp;amp; State were responsible for Security flaws in an application. Moving ahead, I laid down a few principles to be followed as Secure Coding – General Guidelines for all the languages and specific Secure Coding Guidelines for C &amp;amp; C++, Java and .NET &lt;/p&gt;You can get my presentation &lt;a href="http://www.owasp.org/images/2/28/RichardLewis_SecureCodingFundamentals.ppt"&gt;here.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115520633464818836?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115520633464818836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115520633464818836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520633464818836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520633464818836'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/owasp-mumbai-chapter-1st-meet-24-june.html' title='OWASP, Mumbai Chapter  - 1st Meet - 24-June-06'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115520541927133836</id><published>2006-08-10T15:52:00.000+05:30</published><updated>2006-08-10T15:53:39.280+05:30</updated><title type='text'>Memory Allocation Best Practices in C and C++</title><content type='html'>&lt;h2&gt;Introduction&lt;/h2&gt; &lt;p&gt;Tomes (and I'm talking of real big tomes) are available on secure coding in C and C++. They describe the details of the language, why C,C++ are so insecure and coding patterns and anti-patterns. They tell you what to chew and what to eschew. At the end of it all - when you come down to writing code - how many of these best practices do you remember? &lt;/p&gt; &lt;p&gt;The answer to the above questions is best left to your judgement. In this secure programming series, I intend to bring before you collections of programming best practices collected from the following sources:&lt;br /&gt;1. My own experience and the invaluable experience that I have obtained when reviewing source code.&lt;br /&gt;2. Numerous books available on the topic (my favourite being &lt;i&gt;Secure Programming in C and C++&lt;/i&gt; by &lt;i&gt;Robert Seacord&lt;/i&gt;). I recently picked up &lt;em&gt;Exceptional C++&lt;/em&gt; and &lt;em&gt;More Exceptional C++&lt;/em&gt; by &lt;em&gt;Herb Sutter &lt;/em&gt;and wonder how I did without these ones!&lt;/p&gt; &lt;p&gt;This article gives you tips to follow when allocating and deallocating memory in C and C++. If your code does not follow them, then you run a risk of making your programs susceptible to all types of attacks (describing the attacks does not fall in the scope of the article)&lt;/p&gt; &lt;p&gt;Without wasting any more of your time (or mine) let us dig in.&lt;/p&gt; &lt;h2&gt;Secure Memory Allocation Tips Common to C and C++&lt;/h2&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 1&lt;/b&gt; - Use static buffers wherever possible. The compiler automatically frees such memory. &lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 2 - &lt;/b&gt;Previously allocated memory should be manually freed, after it is no longer required.&lt;br /&gt;&lt;i&gt;Dont laugh, meet someone who's making a switch from Java into C,C++ and you'll know what I'm talking about.&lt;/i&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip 3 - &lt;/strong&gt;Given an option to choose between &lt;strong&gt;calloc/malloc &lt;/strong&gt;or &lt;strong&gt;new &lt;/strong&gt;to allocate memory, go in for the latter - use &lt;strong&gt;new&lt;/strong&gt;, dont use &lt;strong&gt;calloc/malloc&lt;/strong&gt;.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 4 - &lt;/b&gt;When using C and C++ code together, if &lt;b&gt;new &lt;/b&gt;has been used to allocate memory, use &lt;b&gt;delete &lt;/b&gt;to free it. Do not use &lt;b&gt;free&lt;/b&gt;. Likewise, if &lt;b&gt;malloc &lt;/b&gt;or &lt;b&gt;calloc &lt;/b&gt;has been used to allocate memory, use &lt;b&gt;free &lt;/b&gt;when deallocating. Do not use &lt;b&gt;delete&lt;/b&gt;.&lt;br /&gt;&lt;i&gt;Unfortunately, many programmers feel they can get away with using &lt;strong&gt;free &lt;/strong&gt;when allocation has been done by &lt;strong&gt;new &lt;/strong&gt;(and vice versa) because they discovered while debugging that &lt;strong&gt;new &lt;/strong&gt;was implemented using &lt;strong&gt;malloc &lt;/strong&gt;and that &lt;strong&gt;delete &lt;/strong&gt;was implemented using &lt;strong&gt;free! &lt;/strong&gt;Don't fall in this trap.&lt;/i&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip 5 - &lt;/strong&gt;Often a function requires to set a buffer supplied by the caller. The length of the buffer may be unknown to the caller so the caller may not know how much memory to allocate before supplying that buffer to the function. In such cases the function should provide a means for the caller to determine how many bytes are required to be allocated.&lt;br /&gt;A common way to do this is by allowing the caller to call the function with a special argument so that it will return the number of bytes the caller must allocate for the buffer.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 6 - &lt;/b&gt;When shipping code libraries (or SDKs as they are called) provide wrapper functions that encapsulate &lt;strong&gt;new &lt;/strong&gt;and &lt;strong&gt;delete&lt;/strong&gt;. This helps prevent single-threaded and multi-threaded runtime issues.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 7 - &lt;/b&gt;Use &lt;em&gt;unsigned integer &lt;/em&gt;types to hold the number of bytes to be allocated, when allocating memory dynamically. This weeds out negative numbers. Also check the length of memory allocated against a maximum value.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 8 - &lt;/b&gt;Do not allocate and deallocate memory in a loop as this may slow down the program and may sometime cause security malfunctions.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 9 - &lt;/b&gt;Assign &lt;em&gt;NULL &lt;/em&gt;to a pointer after freeing (or deleting) it. This prevents the program from crashing should the pointer be accidentally freed again. Calling free or delete on NULL pointers is guaranteed not to cause a problem.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 10 - &lt;/b&gt;Compilers are known to vaporise calls to &lt;strong&gt;memset()&lt;/strong&gt; that appear after all modifications to the memory location is complete for that flow. Use &lt;strong&gt;SecureZeroMemory() &lt;/strong&gt;to prevent this from happening.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip 11 - &lt;/strong&gt;When storing secrets such as passwords in memory, overwrite them with random data before deleting them. Need to note that &lt;strong&gt;free &lt;/strong&gt;and &lt;strong&gt;delete &lt;/strong&gt;merely make previously allocated memory unavailable, they dont really 'delete' data contained in that memory.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip 12 -&lt;/strong&gt; An easy way to find out if your code is leaking memory is by executing it and examining its memory usage either using &lt;strong&gt;Task Manager&lt;/strong&gt; on Windows or &lt;strong&gt;top&lt;/strong&gt; on Linux.&lt;/p&gt; &lt;h2&gt;Secure Memory Allocation Tips in C&lt;/h2&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 1 - &lt;/b&gt;Ensure that 0 (zero) bytes are not allocated using malloc According to the documentation, behaviour for malloc( ) for this case is undefined.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 2 - &lt;/b&gt;Always check the pointer to the memory returned by &lt;b&gt;calloc/malloc&lt;/b&gt;. If this pointer turn out to be NULL, the memory allocation should be considered unsuccessful and no operations should be performed using that pointer. &lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 3 - &lt;/b&gt;When allocating an array of objects, remember to free the array in a loop.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip 4 - &lt;/strong&gt;Do not use &lt;strong&gt;realloc &lt;/strong&gt;when allocating buffers that will store sensitive data in them. The implementation of &lt;strong&gt;realloc &lt;/strong&gt;copies and moves around the data based on your reallocations. This implies that your sensitive data ends up in several other areas in memory which you would have no means of "scrubbing".&lt;/p&gt; &lt;h2&gt;Secure Memory Allocation Tips in C++&lt;/h2&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 1 - &lt;/b&gt;When allocating collections use&lt;br /&gt;std::vector&lt;thing&gt; vt(100,thing());.&lt;br /&gt;rather than&lt;br /&gt;thing* pt = new thing[100];&lt;br /&gt;The vector defined above is clearly defined on the stack and therefore memory deallocation will be handled by the compiler. If the storage needs a longer lifetime, say as part of a larger class instance, then make it a member variable and initialize the storage with assign() when required.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 2- &lt;/b&gt;When using new to allocate an array of objects, use the &lt;strong&gt;delete [ ]&lt;/strong&gt; convention when freeing memory. Using delete without the subscript operator &lt;strong&gt;[ ]&lt;/strong&gt; will result in a memory leak.&lt;/p&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 3 - &lt;/b&gt;Use &lt;strong&gt;auto_ptr&lt;/strong&gt; more often than you currently do when allocating so that deallocation is handled automatically. Remember the following guidelines when dealing with &lt;strong&gt;auto_ptr&lt;/strong&gt;s.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;An existing non-const &lt;strong&gt;auto_ptr &lt;/strong&gt;can be reassigned to own a different object by using its &lt;strong&gt;reset() &lt;/strong&gt;function.   &lt;/li&gt;&lt;li&gt;The &lt;strong&gt;auto_ptr::reset() &lt;/strong&gt;function deletes the existing owned object before owning the new one.  &lt;/li&gt;&lt;li&gt;Only one &lt;strong&gt;auto_ptr &lt;/strong&gt;can own an object. So after one &lt;strong&gt;auto_ptr &lt;/strong&gt;(say, P1) has been assigned to another &lt;strong&gt;auto_ptr &lt;/strong&gt;(say, P2) do not use P1 any longer to call a method on the object as P1 is reset to &lt;strong&gt;NULL&lt;/strong&gt;. Remember that the copy of an &lt;strong&gt;auto_ptr &lt;/strong&gt;is not equivalent to the original.  &lt;/li&gt;&lt;li&gt;Do not put &lt;strong&gt;auto_ptr&lt;/strong&gt;s into standard containers. This is because doing this creates a copy of the &lt;strong&gt;auto_ptr &lt;/strong&gt;and as mentioned above the copy of an &lt;strong&gt;auto_ptr &lt;/strong&gt;is not equivalent to the original.  &lt;/li&gt;&lt;li&gt;Dereferencing an &lt;strong&gt;auto_ptr &lt;/strong&gt;is the only allowed operation on a &lt;strong&gt;const auto_ptr&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;auto_ptr &lt;/strong&gt;cannot be used to manage arrays.&lt;/li&gt;&lt;/ul&gt;&lt;b&gt; &lt;/b&gt;&lt;p&gt;&lt;b&gt;Tip 4 - &lt;/b&gt;When using &lt;b&gt;new &lt;/b&gt;enclose it within a &lt;b&gt;try-catch &lt;/b&gt;block. The &lt;b&gt;new &lt;/b&gt;operator throws an exception and does not return a value. To force the new operator to return a value use the &lt;b&gt;nothrow &lt;/b&gt;qualifie as shown below:&lt;br /&gt;thing * pt = new (std::nothrow) thing[100]; &lt;/p&gt; &lt;h2&gt;Finally...&lt;/h2&gt; &lt;p&gt;I hope you enjoyed reading these tips. If you did, please vote and rate this article below. I shall wait for your comments and feedback. I will collate comments from all of you and update the article - not to mention - and give you all credits. Please feel free to write me at &lt;u&gt;&lt;span style="color:#0000ff;"&gt;richiehere @ hotmail . com&lt;/span&gt;&lt;/u&gt;. Good luck and secure programming!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115520541927133836?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115520541927133836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115520541927133836' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520541927133836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520541927133836'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/memory-allocation-best-practices-in-c.html' title='Memory Allocation Best Practices in C and C++'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-32502865.post-115520483084157131</id><published>2006-08-10T15:41:00.000+05:30</published><updated>2006-08-10T15:45:20.023+05:30</updated><title type='text'>Securing user enrollments in applications</title><content type='html'>&lt;span style="font-weight: bold;"&gt;What is User Registration?&lt;/span&gt;&lt;br /&gt;User registration simply means introducing intended users to the software for the first time. User registration is typically a one-time operation. Post-user registration users start using the services of the software. User registration should be given more attention when designing your applications.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Why is User Registration Important?&lt;/span&gt;&lt;br /&gt;User registration is important because it...&lt;br /&gt;1. provides assurance that only bonafide users are added to the system.&lt;br /&gt;2. provides accountability by reducing chances of backdoor entry into the system.&lt;br /&gt;3. allows trust to be transferred from the software to the intended users of the software.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What kind of applications require User Registration?&lt;/span&gt;&lt;br /&gt;Some examples of applications requiring User Registration are:&lt;br /&gt;a) A customer-service portal for a telephone company&lt;br /&gt;b) An online banking website for a bank&lt;br /&gt;c) An extranet website hosted by a company&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What security problems are caused due to poor User Registration?&lt;/span&gt;&lt;br /&gt;Some problems associated with poor user registration are:&lt;br /&gt;a) Introduction of ghost users in the system&lt;br /&gt;b) Easy subversion of the user creation logistics&lt;br /&gt;c) Confusing forensic paths which make it difficult to pin down hacking attempts to a process employed by the system&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;User registration consists of three distinct parts:&lt;/span&gt;&lt;br /&gt;1. Create User - Creating users at the software console&lt;br /&gt;2. Link User - Associate physical people with the created users&lt;br /&gt;3. Transfer Control - Handing over initial credentials to the linked physical users.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32502865-115520483084157131?l=secureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://secureapps.blogspot.com/feeds/115520483084157131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=32502865&amp;postID=115520483084157131' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520483084157131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/32502865/posts/default/115520483084157131'/><link rel='alternate' type='text/html' href='http://secureapps.blogspot.com/2006/08/securing-user-enrollments-in.html' title='Securing user enrollments in applications'/><author><name>Richard Lewis</name><uri>http://www.blogger.com/profile/11211236642251199864</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
