Security Programming in .Net

security programming in .net

security image taken from

These are few tips how to add security programming in  .net app on code level. Version Disclosure

<httpRuntime  enableVersionHeader="false" />

Set Cookie to HttpOnly

<httpCookies httpOnlyCookies="true"/>

Set Custom Error

<customErrors mode="On" defaultRedirect="~/Controller/ErrorPage"></customErrors>

Custom Error Disabled

<customErrors mode="RemoteOnly">

Leaving Tracing Enabled in Web-Based Applications

<trace enabled="false" localOnly="true">

Disabled Debugging

<compilation debug="false">

Disabled Cookieless Session States

<sessionState cookieless="UseCookies"> 

Input Validation :  A set of controls that verify the properties of all input data matches what is expected by the application including types, lengths, ranges, acceptable character sets and does not include known hazardous characters.

If any potentially hazardous characters must be allowed as input, be sure that you implement additional controls like output encoding, secure task specific APIs and accounting for the utilization of that data throughout the application . Examples of common hazardous characters include: < > ” ‘ % ( ) & + \ \’ \”

Output Encoding

  1. Encode all characters unless they are known to be safe for the intended interpreter
  2. Contextually sanitize all output of un-trusted data to queries for SQL, XML, and LDAP
  3. Sanitize all output of un-trusted data to operating system commands

Error Handling and Logging

  1. Do not disclose sensitive information in error responses, including system details, session identifiers or account information
  2. Use error handlers that do not display debugging or stack trace information
  3. Implement generic error messages and use custom error pages

Database Security

  1. Use strongly typed parameterized queries
  2. Utilize input validation and output encoding and be sure to address meta characters. If these fail, do not run the database command
  3. Ensure that variables are strongly typed

HTML Entity Encode: The process of replacing certain ASCII characters with their HTML entity equivalents. For example, encoding would replace the less than character “<” with the HTML equivalent “<“. HTML entities are ‘inert’ in most interpreters, especially browsers, which can mitigate certain client side attacks.

Prevent ClickJacking
More Info:

Hopefully these few tips can be apply to improve security in  programming especially in .net

Here also few post regarding programming that you might interested

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *