<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mostly Client Side &#187; Code Practices</title>
	<atom:link href="http://www.mostlyclientside.com/category/code-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mostlyclientside.com</link>
	<description>But A Lot Of Server Side Stuff Too</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:12:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Get $125 Extra In Vasectomy-Related Payment With This 4-Step Coding Process</title>
		<link>http://www.mostlyclientside.com/get-125-extra-in-vasectomy-related-payment-with-this-4-step-coding-process/</link>
		<comments>http://www.mostlyclientside.com/get-125-extra-in-vasectomy-related-payment-with-this-4-step-coding-process/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:32:21 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Practices]]></category>
		<category><![CDATA[Code Option]]></category>
		<category><![CDATA[Consultation Visit]]></category>
		<category><![CDATA[Conversion Rate]]></category>
		<category><![CDATA[Diagnosis Code]]></category>
		<category><![CDATA[Extra]]></category>
		<category><![CDATA[Four Steps]]></category>
		<category><![CDATA[Hurry]]></category>
		<category><![CDATA[Office Consultation]]></category>
		<category><![CDATA[Outpatient Visit]]></category>
		<category><![CDATA[Patient Visit]]></category>
		<category><![CDATA[Scottsdale Ariz]]></category>
		<category><![CDATA[Scottsdale Center]]></category>
		<category><![CDATA[Sterilization]]></category>
		<category><![CDATA[Urologist]]></category>
		<category><![CDATA[Urologists]]></category>
		<category><![CDATA[Urology Practices]]></category>
		<category><![CDATA[Vasectomies]]></category>
		<category><![CDATA[Vasectomy]]></category>

		<guid isPermaLink="false">http://www.mostlyclientside.com/get-125-extra-in-vasectomy-related-payment-with-this-4-step-coding-process/</guid>
		<description><![CDATA[Turn to V25.x for your diagnosis code option. Vasectomies are very common in most urology practices. But choosing the proper codes to report can sometimes prove very challenging, right from the pre-vasectomy &#8220;consultation&#8221; visit that most urologists perform. You could be costing your practice hundreds over the course of one year if you&#8217;re not billing [...]]]></description>
			<content:encoded><![CDATA[<p>
              <b>Turn to V25.x for your diagnosis code option. </b></p>
<p>Vasectomies are very common in most urology practices. But choosing the proper codes to report can sometimes prove very challenging, right from the pre-vasectomy &#8220;consultation&#8221; visit that most urologists perform. You could be costing your practice hundreds over the course of one year if you&#8217;re not billing out each piece of the vasectomy process. Here are four steps to ensure that you capture all the reimbursement your urologist deserves. </p>
<p>1. <b>Don&#8217;t be in a hurry to assign consult codes for the first visit </b></p>
<p>Prior to performing a vasectomy process a urologist meets with the patient to discuss the procedure and makes sure that the patient understands the outcome of the procedure and then undergo this elective sterilization. You should report this office visit using the appropriate E/M code, says Kelly Young, a coder with Scottsdale Center for Urology in Scottsdale, Ariz. </p>
<p>The real challenge comes when you try to figure out whether you should report an office visit E/M code or a consultation code. </p>
<p>Depending on your urologist&#8217;s documentation, you can choose from the consultation codes (99241-99245, Office consultation for a new or established patient …), a new patient (99201-99205, Office or other outpatient visit for the evaluation and management of a new patient …), or established patient (99211-99215, Office or other outpatient visit for the evaluation and management of an established patient …) codes. </p>
<p><b>Don&#8217;t lose out on your Dollars</b>: You would be sacrificing on your Dollars if you skip reporting the pre-vasectomy office visit. Suppose, your urologist performs a level-three new patient visit (99203), you&#8217;ll earn $91.97 (the unadjusted fee for 99203, 2.55 RVUs, times the 2009 conversion rate of $36.0666) in addition to the procedure code, and if your urologist performs a level-three consultation, you&#8217;ll earn $125.15 (the unadjusted fee for 99203, 3.47 RVUs, times the 2009 conversion rate of $36.0666) in addition to the procedure code. </p>
<p><b>Remember</b>: If the patient is new to your office, report a new patient visit using codes 99201-99205. However, if the urologist (or another urologist in the same practice) has seen the patient within the past three years, report an established patient office visit (99211-99215), and not a new patient visit. </p>
<p><b>Beware</b>: Don&#8217;t let the term &#8220;consultation&#8221; in the physician&#8217;s documentation trick you. Often practices, physicians, and even patients refer to the pre-vasectomy visit as a consultation. However, to report a consultation code (99241-99245), the visit must meet the requirements of a consultation. There must be a documented request from the requesting physician; a record of the urologist stating his findings, opinions, and advice in the patient&#8217;s chart; and a report that&#8217;s sent back to the requesting doctor. </p>
<p>Michael A. Ferragamo MD, FACS, clinical assistant professor of urology, State University of New York, Stony Brook says, &#8220;Since the recent rule changes for consultations come from Medicare 2006 policy changes (Transmittal 788) and since most men seeking vasectomies for sterilization do not have Medicare as their primary insurance carrier, the patients sent to urologists by physicians most often represent consultation requests , hence, they should be billed and coded accordingly if all criteria for a consultation are met.&#8221; </p>
<p><b>Diagnosis aid</b>: The most appropriate ICD-9 code for the pre-vasectomy examination, whether it&#8217;s a consultation or a new/established patient visit is V25.09 (Encounter for contraceptive management; general counseling and advice; other). </p>
<p><b>Important point</b>: Many payers have a perception that code V25.09 is a &#8220;family planning advice,&#8221; and pertain only to the female partner, and hence, they will deny payment for any pre-vasectomy examination of the male when you use this diagnosis. So use V25.2 (Encounter for contraceptive management; sterilization, admission for interruption of …vas deferens) in its place, with this you can expect payment for a pre-vasectomy service in most cases. </p>
<p>Check, which diagnostic code is preferred by your payer. The Scottsdale Center for Urology uses V25.2 as the diagnosis code. However, &#8220;we bill … with V25.09,&#8221; says Kim Kerckhoff, CCA, coder for Alpine Urology in Anchorage, Alaska. </p>
<p>2. <b>Use modifier 57 for Same-Day E/M and Procedure</b> </p>
<p>If your urologist performs the vasectomy procedure on the same day as the pre-vasectomy office visit make sure that you append modifier 57 (Decision for surgery) to the E/M code you report. Also ensure that the urologist&#8217;s documentation supports a separate E/M code, the E/M service must go above and beyond the E/M that&#8217;s inherent to the procedure. </p>
<p><b>Avoid bundled payment</b>: Your urologist can conduct the service on separate days if you want to make sure that your payer will not bundle the pre-vasectomy visit with the vasectomy procedure. Many urologists do this anyway to give the patient time to review his options and make the final decision about surgery. Above that, your office will have time to review the patient&#8217;s benefits. </p>
<p>Alice Kater, CPC, PCS, coder for Urology Associates of South Bend, Ind says, &#8220;We never perform the procedure the same day as the vas consultation. The patient and wife/partner will come in for the consult, view a movie, and speak extensively with the physician following the examination and review of systems. When they leave the physician, they schedule their procedure for the next available, and convenient, vas opening.&#8221; </p>
<p>3. <b>Select a Code Based on the Type of Procedure</b> </p>
<p>You&#8217;ll have to go through the documentation to see which technique your urologist used, so that you can report the actual vasectomy procedure. Then choose one of these three codes: </p>
<p> 55250 — Vasectomy, unilateral or bilateral (separate procedure), including postoperative semen examination(s). &#8220;This CPT Codes is the most common code used for vasectomy for voluntary sterilization,&#8221; Ferragamo explains. 55450 — Ligation (percutaneous) of vas deferens, unilateral or bilateral (separate procedure). &#8220;Coders rarely use this code for a vasectomy for voluntary sterilization,&#8221; Ferragamo says. 55559 — Unlisted laparoscopy procedure, spermatic cord for a laparoscopic vasectomy. Add V25.2 to the vasectomy procedure, says Kerckhoff. Clue: You should report 55250, 55450, or 55559 just once per patient regardless of whether the urologist performs the procedure on one or both sides. The urologist usually, but not always, performs the procedure, cutting the vas deferens and suturing the ends, on both the left and right sides. So don&#8217;t change your urology coding even if your urologist cuts and sutures only one side (for a patient having only one testicle). Note: These codes also include the local or regional anesthesia that the urologist administers, so do not code any local anesthesia administered for those services separately. Surgical trays: Use the HCPCS code A4550 (Surgical trays) or CPT code 99070 (Supplies and materials [except spectacles], provided by the physician over and above those usually included with the office visit or other services rendered [list drugs, trays, supplies, or materials provided]) for private or commercial payers, few of them reimburse for a surgical tray/supplies. &#8220;Medicare will not reimburse for anesthesia administered by the surgeon or urologist, or for tray charges,&#8221; Ferragamo warns. &#8220;However, there are a few commercial carriers that will still reimburse for local anesthesia administered by the urologist and for a tray charge. Check with the specific carrier. One may bill private or commercial carriers HCPCS code S0020 (Injection, bupivicaine HCL, 30 ml) for reimbursement of the anesthetic agent used,&#8221; he adds. There is no CPT code for laparoscopic vasectomy so when your urologist performs this procedure, usually at the same time a general surgeon is performing a laparoscopic hernia repair, report the unlisted code 55559. Hint: Make sure that you submit a detailed report to your payer and compare, or benchmark, the laparoscopic vasectomy to 55550 (Laparoscopy, surgical, with ligation of spermatic veins for varicocele), with respect to the surgical work, technology, equipment used, and time involved. 4. Include Semen Analysis in the Procedure Code After the vasectomy, the urologist must examine the semen to determine the eventual absence of sperm. These examinations are included in the procedure code, so your urologist should document the service, but you should not report them separately. If your office laboratory is not credentialed (CLIA certification) to perform these post-vasectomy semen analyses, outside laboratory evaluations will be necessary and that would result in an additional cost to the patient. However, under these circumstances your urologist should never lower his fee or modify his urology coding. Practices often make special arrangements with most laboratories for a reduced fee for a limited semen examination looking only for the presence or absence of sperm.          <span style="font-size:80%;font-style:italic">Leesa A. Israel, CPC, CUC, CMBS, specializes in <a rel="nofollow" target="_blank" href="">medical coding</a> and reimbursement for urology and general surgery, as well as billing and collections policies and strategies for physician practices. More of her how-to <a rel="nofollow" target="_blank" href="">medical coding and billing</a> articles are available on Supercoder.com. <br class="clear" /><a rel="dofollow" target="_blank" href="http://www.articlesbase.com/health-articles/get-125-extra-in-vasectomyrelated-payment-with-this-4step-coding-process-2070739.html">Article Source</a></span></p>
   What are your thoughts on the subject?]]></content:encoded>
			<wfw:commentRss>http://www.mostlyclientside.com/get-125-extra-in-vasectomy-related-payment-with-this-4-step-coding-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All About Code Coverage &#8211; a White Box Testing Technique</title>
		<link>http://www.mostlyclientside.com/all-about-code-coverage-a-white-box-testing-technique/</link>
		<comments>http://www.mostlyclientside.com/all-about-code-coverage-a-white-box-testing-technique/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 06:06:03 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Practices]]></category>
		<category><![CDATA[Adequate Number]]></category>
		<category><![CDATA[Amp]]></category>
		<category><![CDATA[Branch Coverage]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Code Coverage]]></category>
		<category><![CDATA[Compliance]]></category>
		<category><![CDATA[Confirmation]]></category>
		<category><![CDATA[Coverage Criteria]]></category>
		<category><![CDATA[Coverage Measurement]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Execution]]></category>
		<category><![CDATA[Instrumentation]]></category>
		<category><![CDATA[Key Point]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[Program Performance]]></category>
		<category><![CDATA[Software Application]]></category>
		<category><![CDATA[Statement Coverage]]></category>
		<category><![CDATA[Surety]]></category>
		<category><![CDATA[Test Cases]]></category>

		<guid isPermaLink="false">http://www.mostlyclientside.com/all-about-code-coverage-a-white-box-testing-technique/</guid>
		<description><![CDATA[Let us firstly try to understand as to what is Code coverage.It is a sort of metric meant for the measurement of the testing effort applied to the software application. How do we capture the metrics of code coverage? The process involves Instrumentation of the program and execution of the tests. This way we can [...]]]></description>
			<content:encoded><![CDATA[
<p><strong>Let us firstly try to understand as to what is Code coverage.<strong><strong></strong><br /></strong></strong><br />It is a sort of metric meant for the measurement of the testing effort applied to the software application.</p>
<p>
</p>
<p>How do we capture the metrics of code coverage?</p>
<p>
<p>The process involves Instrumentation of the program and execution of the tests. This way we can identify the code which had been executed &amp; which had been left out. We can see that unit Testing &amp; code coverage are complementary to each other. Unit testing confirms the compliance of program performance with respect to the requirements, whereas code coverage reveals the areas left out of the testing.</p>
<p>The process of development of software is aimed to have coverage measurement by way of defining the</p>
<p>number of branches or statements covered under the test. Even after having complete branch coverage or the statement coverage, there is no surety of absence of some key bugs in the code. Hence 100% branch coverage or the statement coverage remain quite illusive &amp; does not provide any surety of perfection to both developers and the managers</p>
<p>
<p>Now the key point of discussion remains that having complete coverage remains inadequate. Reason being branch coverage as well as statement coverage do not provide any confirmation of execution of the logic of the code. Both branch coverage and statement coverage are helpful in identifying major problems in portion of the code left out of execution. </p>
<p>However Path coverage technique is comparatively much more rugged &amp; helps us in revealing the defects during the early stages. Before we go deeper into path coverage, let us analyze some of the drawbacks of branch coverage and statement coverage techniques.</p>
<p>Statement Coverage:
<p>Major benefit of statement coverage is that it is greatly able to isolate the portion of code, which could not be executed. Statement coverage criteria call for having adequate number of test cases for the program to ensure execution of every statement at least once. In spite of achieving 100% statement coverage, there is every likelihood of having many undetected bugs.</p>
<p>
<p>Thus s coverage report indicating 100% statement coverage will mislead the manager to feel happy with a false temptation of terminating further testing which can lead to release a defective code into mass production. Thus we can not view 100% statement coverage sufficient to build a reasonable amount of confidence on the perfect behavior of the application.</p>
<p>Since 100% statement coverage tends to become expensive, the developers chose a better testing technique called branch coverage.</p>
<p><strong></p>
<p>Branch Coverage <strong>or Decision Coverage:</strong></p>
<p>
<p>Branch coverage is more impressive since it tends to go deeper into the code as compared to the statement coverage technique. Branch coverage is a metric for measurement of outcomes of decisions subjected to testing. Branch coverage criteria call for having adequate number of test cases for every program to ensure execution of every decision or branch at least once. In majority of the products branch coverage is viewed as the bare minimum coverage. Thus this is better than statement coverage, still it is not adequate for applications needing higher integrity.</p>
<p>
<p>It is easy to determine as to how many branches a method shall have. Simple method of working out the decision outcomes, a method can have, is counting the quantity of branches expected to be covered along with addition of one more entry branch in it.</p>
<p>
<p>It has been seen that even 100% attainment of statement coverage as well as branch coverage is not sufficient. Moreover for complex methods, it is practically not feasible to perform testing of each &amp; every path. This calls for a need for a better alternative of testing i.e basis path coverage.</p>
<p>Basis Path Coverage:
<p>A path is nothing but the way execution proceeds across a method right from its beginning to its end. Paths, which are Independent, are known as basis sets as well. In other words, basis set is the smallest group of paths grouped together to form all possible combinations of paths across the method.</p>
<p>Path coverage criteria call for having adequate number of test cases for every feasible path, basis paths to ensure execution of every path at least once in the program segment.</p>
<p>
<p>If there are say N number of decisions in a method, then it could have 2^N number of paths. However in case of a method having loop, the number of paths can become infinite. Due to extremely large number of paths in the application, path coverage also tend to become difficult. To reduce the number of paths for testing, we can take the help of the metric known as Cyclomatic Complexity. The question as to how much path coverage is needed is answered depending upon the complexity or the risk factor involved in the application under test.</p>
<p>
<p>Basis path coverage is similar to branch coverage in a way that it ensures testing / execution of every decision outcome. Still there is a point of difference compared to branch coverage in a way that every decision outcome is tested independent of each other. It involves flipping of the decision executed just before it, while leaving remaining executed branches intact. Since basis path coverage takes care of all statements as well as branches across a method, this is an effective substitute of branch coverage as well as statement coverage. This is the reason of basis path coverage being viewed as much more robust as compared to the branch coverage.</p>
<p>How to Create Data for Testing:
<p>In simple examples it may be is easy to achieve full basis path coverage, whereas in real world scenarios full testing of basis paths becomes extremely challenging, may be even impossible. One of the reasons of this is, the necessity of having test data, which should be able to execute a particular path by testing the interaction between various decisions across a method. It is not a simple process to introduce some data which could further lead to execution of a particular path.<strong></strong></p>
<p>1) Keep a simple code.</p>
<p>2) Try not to use methods having Cyclomatic complexity more than ten. </p>
<p>3) Do not have more basis paths in number.</p>
<p>4) Have less number of decisions for every path.</p>
<p>
<p>5) Do not have duplicating decisions.</p>
<p>
<p>6) Try not to have data dependency </p>
<p>Conclusion:
<p>Statement coverage as well as branch coverage criteria though being simple for execution but have a drawback that some of the major defects tend to remain undetected, due to which project managers, developers and testers are liable to draw erratic conclusions of perfection, while the fact might be something else.</p>
<p>Whereas basis path coverage is a more rugged</p>
<p>
<p>approach which is able to identify such defects which otherwise could have gone unnoticed.</p>
<p>
<p>It is aimed at inspecting the code directly and is therefore a form of white box testing.</p>
<p>However following best coding practices can be helpful for simplifying the process of testing.</p>
<p></strong>          <span style="font-size:80%;font-style:italic">http://www.softwaretestinggenius.com<br />
A Storehouse of Complete Knowledge on Software Testing &amp; QA under one Roof <br class="clear" /><a rel="dofollow" target="_blank" href="http://www.articlesbase.com/software-articles/all-about-code-coverage-a-white-box-testing-technique-685653.html">Article Source</a></span></p>
   What are your thoughts on the subject?]]></content:encoded>
			<wfw:commentRss>http://www.mostlyclientside.com/all-about-code-coverage-a-white-box-testing-technique/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure ASP.NET coding practice for three most critical vulnerabilities in Web Application</title>
		<link>http://www.mostlyclientside.com/secure-asp-net-coding-practice-for-three-most-critical-vulnerabilities-in-web-application/</link>
		<comments>http://www.mostlyclientside.com/secure-asp-net-coding-practice-for-three-most-critical-vulnerabilities-in-web-application/#comments</comments>
		<pubDate>Fri, 28 May 2010 07:42:55 +0000</pubDate>
		<dc:creator>Michael B Humphrey</dc:creator>
				<category><![CDATA[Code Practices]]></category>
		<category><![CDATA[Application Code]]></category>
		<category><![CDATA[Attacker]]></category>
		<category><![CDATA[Chunk]]></category>
		<category><![CDATA[Code Lt]]></category>
		<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Html Response]]></category>
		<category><![CDATA[Information Leakage]]></category>
		<category><![CDATA[Input Validation]]></category>
		<category><![CDATA[Malicious User]]></category>
		<category><![CDATA[Mitigation]]></category>
		<category><![CDATA[Neogi]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Script Injection]]></category>
		<category><![CDATA[Security Approach]]></category>
		<category><![CDATA[Security Controls]]></category>
		<category><![CDATA[Server Text]]></category>
		<category><![CDATA[Vulnerabilities]]></category>
		<category><![CDATA[Web application]]></category>
		<category><![CDATA[Write Comment]]></category>

		<guid isPermaLink="false">http://www.mostlyclientside.com/secure-asp-net-coding-practice-for-three-most-critical-vulnerabilities-in-web-application/</guid>
		<description><![CDATA[Secure ASP.NET coding practice for 3 most critical vulnerabilities in Web Application www.ivizsecurity.com Somnath Guha Neogi (OSCP,CNSM) Introduction: ASP.NET provides several exciting security controls, but these need to be understood properly and used wisely. Failing to use the ASP.NET functions properly results in an insecure web application. We see therefore that ASP.NET does not exempt [...]]]></description>
			<content:encoded><![CDATA[
<p>Secure ASP.NET coding practice for 3 most critical vulnerabilities in Web Application</p>
<p>www.ivizsecurity.com</p>
<p><strong>Somnath Guha Neogi (OSCP,CNSM)</strong></p>
<p>        <a>Introduction:</a>
<p>ASP.NET provides several exciting security controls, but these need to be understood properly and used wisely. Failing to use the ASP.NET functions properly results in an insecure web application. We see therefore that ASP.NET does not exempt the programmer from following coding standards and procedures in order to write safe and secure application code.</p>
<p>In this paper we will discuss about the code level mitigation for three most frequently found vulnerabilities:</p>
<p>Cross Site Scripting</p>
<p>SQL Injection</p>
<p>Information Leakage</p>
<p>  <a>Cross Site Scripting:</a>
<p>An application is vulnerable to Cross Site Scripting if malicious user input is embedded in the HTML response without passing through any particular validation process. Let’s take a look on a vulnerable chunk of code</p>
<p><strong>&lt;%@ Page ValidateRequest=&#8221;false&#8221; %&gt;</strong></p>
<p><strong>&lt;html&gt;</strong></p>
<p><strong> &lt;script runat=&#8221;server&#8221;&gt;</strong></p>
<p><strong> void buttonsubmit_Click(Object sender, EventArgs e)</strong></p>
<p><strong> {</strong></p>
<p><strong> Response.Write(comment.Text);</strong></p>
<p><strong> }</strong></p>
<p><strong> &lt;/script&gt;</strong></p>
<p><strong> &lt;body&gt;</strong></p>
<p><strong> &lt;form runat=&#8221;server&#8221;&gt;</strong></p>
<p><strong> &lt;asp:TextBox runat=&#8221;server&#8221; /&gt;</strong></p>
<p><strong> &lt;asp:Button runat=&#8221;server&#8221; </strong></p>
<p><strong> </strong></p>
<p><strong> Text=&#8221;SubmitComment&#8221; /&gt;</strong></p>
<p><strong> &lt;/form&gt;</strong></p>
<p><strong> &lt;/body&gt;</strong></p>
<p><strong>&lt;/html&gt;</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Now an attacker can send malicious request with embedded JavaScript through the comment textbox which will be executed at the client’s browser. To see that this is possible, the above vulnerable script can be fed with the following input:</p>
<p><strong>&lt;script&gt;alert([removed])&lt;/script&gt;</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Now this type of script injection attack can be mitigated by adopting a two tire security approach. User input validation will form the first tire of security while HTML-encoding on outgoing user data will form a second layer of security. So we can start assuming that all user input is malicious and to safely allow restricted HTML input developers/testers should adopt three security approaches as follows:</p>
<p>a)      Add the <strong>ValidateRequest=&#8221;false&#8221;</strong> attribute to the <strong>@ Page</strong> directive to disable the ASP.NET request validation.</p>
<p>b)      Encode the string input with HtmlEncode function.</p>
<p>c)       White listing approach can be adopted by using a String Builder and calling its Replace method to selectively remove the encoding on the HTML elements that you want to permit.</p>
<p>The following .aspx code depicts this as an example.</p>
<p><strong>&lt;%@ Page ValidateRequest=&#8221;false&#8221;%&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>&lt;script runat=&#8221;server&#8221;&gt;</strong></p>
<p><strong> </strong></p>
<p><strong> void submitbutton_Click(object sender, EventArgs e)</strong></p>
<p><strong> {</strong></p>
<p><strong> </strong></p>
<p><strong> StringBuilder stringbuilder1 = new StringBuilder(</strong></p>
<p><strong> HttpUtility.HtmlEncode(Txt1.Text));</strong></p>
<p><strong> // Selectively allow </strong> &lt;b&gt; and &lt;i&gt;<strong></strong></p>
<p> stringbuilder1.Replace(&#8220;&amp;lt;b&amp;gt;&#8221;, &#8220;&lt;b&gt;&#8221;);<strong></strong></p>
<p> stringbuilder1.Replace(&#8220;&amp;lt;/b&amp;gt;&#8221;, &#8220;<strong>&#8220;);</strong></p>
<p><strong> </strong>stringbuilder1<strong>.Replace(&#8220;&amp;lt;i&amp;gt;&#8221;, &#8220;&lt;i&gt;&#8221;);</strong></p>
<p><strong> </strong>stringbuilder1<strong>.Replace(&#8220;&amp;lt;/i&amp;gt;&#8221;, &#8220;&#8221;);</strong></p>
<p><strong> Response.Write(</strong>stringbuilder1<strong>.ToString());</strong></p>
<p><strong> }</strong></p>
<p><strong>&lt;/script&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>&lt;html&gt;</strong></p>
<p><strong> &lt;body&gt;</strong></p>
<p><strong> &lt;form runat=&#8221;server&#8221;&gt;</strong></p>
<p><strong> &lt;div&gt;</strong></p>
<p><strong> &lt;asp:TextBox Runat=&#8221;server&#8221; </strong></p>
<p><strong> TextMode=&#8221;MultiLine&#8221; Width=&#8221;318px&#8221;</strong></p>
<p><strong> Height=&#8221;168px&#8221;&gt;&lt;/asp:TextBox&gt;</strong></p>
<p><strong> &lt;asp:Button Runat=&#8221;server&#8221; </strong></p>
<p><strong> Text=&#8221;Submit&#8221; OnClick=&#8221;submitbutton_Click&#8221; /&gt;</strong></p>
<p><strong> &lt;/div&gt;</strong></p>
<p><strong> &lt;/form&gt;</strong></p>
<p><strong> &lt;/body&gt;</strong></p>
<p><strong> </strong></p>
<p>The above .aspx page code shows this approach. The page disables ASP.NET request validation by setting <strong>ValidateRequest=&#8221;false&#8221;</strong>. It HTML-encodes the input and then selectively allows the &lt;<strong>b</strong>&gt; and &lt;<strong>i</strong>&gt; HTML elements to support simple text formatting.<strong></strong></p>
<p>Now the second tire of security can be brought into the frame by encoding the output to know that the text contains HTML special characters or not.</p>
<p>  <strong>Response.Write(HttpUtility.HtmlEncode(Request.Form["text"]));</strong> <strong> </strong> Or in case of URL strings that contain input to the client. <strong> </strong>
<p><strong>Response.Write(HttpUtility.UrlEncode(urlString));</strong></p>
<p> <strong> </strong>
<p>As a result, the HTML response stream of the malicious input <strong>&lt;script&gt;alert([removed])&lt;/script&gt; </strong>will look like this<strong></strong></p>
<p><strong>&amp;lt;script&amp;gt;alert([removed])&amp;lt;/script&amp;gt;</strong></p>
<p>This will ultimately restrict the browser to execute the Javascript code because no HTL &lt;script&gt; tag is present any more in the response.The greater-than and less-than symbols are replaced by their HTML-encoded output,&amp;lt; and &amp;gt; respectively.</p>
<p>In addition to this two tire security approach discussed above, we can also use the following countermeasures to prevent cross site scripting as further safe guards.</p>
<p><strong>Setting the correct character encoding:</strong></p>
<p>Character encoding can be done in page level or in configuration level. To set the Character encoding at the page level we can use <strong>&lt;meta&gt;</strong> element or the <strong>ResponseEncoding</strong> page-level attribute as follows:</p>
<p>  <strong>&lt;% @ Page ResponseEncoding=&#8221;iso-8859-1&#8243; %&gt;</strong> <strong>R</strong> <strong>&lt;meta http-equiv=&#8221;Content Type&#8221; </strong> <strong>      content=&#8221;text/html; charset=ISO-8859-1&#8243; /&gt;</strong> <strong> </strong>
<p>To set the Character encoding at the configuration level we have to bring certain changes in Web.config file as follows:</p>
<p>  <strong>&lt;configuration&gt;</strong> <strong>   &lt;system.web&gt;</strong> <strong>      &lt;globalization </strong> <strong>         requestEncoding=&#8221;iso-8859-1&#8243;</strong> <strong>         responseEncoding=&#8221;iso-8859-1&#8243;/&gt;</strong> <strong>   &lt;/system.web&gt;</strong> <strong>&lt;/configuration&gt;</strong>
<p><strong>Use white listing approach rather than black listing:</strong></p>
<p>Sanitizing user input by filtering out known malicious characters is a common practice. But we should not rely on this approach because an attacker can usually find an alternative means of bypassing your validation. Instead, your code should check for known secure, safe input. There are other safe ways of representing these malicious characters. For example &lt; (less than) and &gt; (greater than) can be represented as &amp;lt; and &amp;gt; respectively.</p>
<p><strong>Using the HttpOnly Cookie Option:</strong></p>
<p>HttpOnly cookie attribute is supported by Internet Explorer 6 Service Pack 1 and later, which prevents client-side scripts from accessing a cookie from the [removed] property. Instead, the script returns an empty string. The cookie is still sent to the server whenever the user browses to a Web site in the current domain.</p>
<p><a><strong>SQL Injection:</strong></a><strong></strong></p>
<p>Secure coding practice in ASP.NET against SQL injection vulnerability should focus on the following countermeasures:</p>
<p><strong>Constrain user supplied input</strong></p>
<p>Before applying any countermeasure at the code level we should be concerned about the potential risk associated with denying a list of unacceptable characters (blacklisting) because it is always possible to overlook an unacceptable character when defining the list. Also this kind of validation approach can be easily bypassed by representing an unacceptable character in an alternate format.</p>
<p>ASP.NET server side validator controls, such as the <strong>RegularExpressionValidator</strong> and <strong>RangeValidator</strong> controls can be used to constrain input. Alternatively we can also the <strong>Regex</strong> class in our server-side code to constrain input.</p>
<p>When user input is captured by an ASP.NET <strong>TextBox</strong> control, we can constrain its input by using a <strong>RegularExpressionValidator</strong> control as shown in the following aspx code..</p>
<p> <strong>&lt;%@ %&gt;</strong> <strong>&lt;form runat=&#8221;server&#8221;&gt;</strong> <strong>    &lt;asp:TextBox runat=&#8221;server&#8221;/&gt;</strong> <strong>    &lt;asp:RegularExpressionValidator runat=&#8221;server&#8221;         </strong> <strong>                                    ErrorMessage=&#8221;Incorrect data&#8221; </strong> <strong>                                    ControlToValidate=&#8221;text1&#8243;         </strong> <strong>                                    ValidationExpression=&#8221;^d{3}-d{2}-d{4}$&#8221; /&gt;</strong> <strong>&lt;/form&gt;</strong> <strong> </strong> If the user input is from another source, such as an HTML control, a query string parameter, or a cookie, you can constrain it by using the <strong>Regex</strong> class from the <strong>System.Text.RegularExpressions</strong> namespace. The following example assumes that the input is obtained from a cookie.   <strong>if (Regex.IsMatch(Request.Cookies["SSN"], &#8220;^d{3}-d{2}-d{4}$&#8221;))</strong> <strong>{</strong> <strong>    // perform the database task</strong> <strong>}</strong> <strong>else</strong> <strong>{</strong> <strong>    // handle exception</strong> <strong>}</strong>  
<p>User supplied input parameters need to be validated before being used in SQL statements. The following data access routine can be taken as an example of how validate user input parameters.</p>
<p> <strong> </strong> <strong>using System;</strong> <strong>using System.Text.RegularExpressions;</strong> <strong>public void useraccount(string username, string password)</strong> <strong>{</strong> <strong>    // check username contains only lower case or upper case letters, </strong> <strong>    // the apostrophe, a dot, or white space. Also check it is </strong> <strong>    // between 1 and 40 characters long</strong> <strong>    if ( !Regex.IsMatch(userIDTxt.Text, @&#8221;^[a-zA-Z'./s]{1,40}$&#8221;))</strong> <strong>      throw new FormatException(&#8220;Invalid username format&#8221;);</strong> <strong> </strong> <strong>    // Check password contains at least one digit, one lower case </strong> <strong>    // letter, one uppercase letter, and is between 8 and 10 </strong> <strong>    // characters long</strong> <strong>    if ( !Regex.IsMatch(passwordTxt.Text, </strong> <strong>                      @&#8221;^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$&#8221; ))</strong> <strong>      throw new FormatException(&#8220;Invalid password format&#8221;);</strong> <strong> </strong> <strong>    // Perform data access operation (using type safe parameters)</strong> <strong>    &#8230;</strong> <strong>}</strong> <strong> </strong>
<p><strong>Use parameterized stored procedures:</strong></p>
<p>The following code shows how to use parameters with stored procedures.</p>
<p> <strong>using System.Data;</strong> <strong>using System.Data.SqlClient;</strong> <strong> </strong> <strong>using (SqlConnection connection = new SqlConnection(connectionString))</strong> <strong>{</strong> <strong>  DataSet userDataset = new DataSet();</strong> <strong>  SqlDataAdapter myCommand = new SqlDataAdapter( </strong> <strong>             &#8221;LoginStoredProcedure&#8221;, connection);</strong> <strong>  myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;</strong> <strong>  myCommand.SelectCommand.Parameters.Add(&#8220;@au_id&#8221;, SqlDbType.VarChar, 12);</strong> <strong>  myCommand.SelectCommand.Parameters["@au_id"].Value = SSN.Text;</strong> <strong> </strong> <strong>  myCommand.Fill(userDataset);</strong> <strong>}</strong> <strong> </strong> In the above example the <strong>@au_id</strong> parameter is treated as a literal value and not as executable code. Also, the parameter is checked for type and length. In the preceding code example, the input value cannot be longer than 12 characters. If the data does not conform to the type or length defined by the parameter, the <strong>SqlParameter</strong> class throws an exception.<strong></strong>
<p>Note: Using stored procedure with parameters does not necessarily prevent SQL injection.Take a look at the following stored procedure:</p>
<p> <strong> </strong> <strong> </strong> <strong>CREATE PROCEDURE dbo.RunQuery</strong> <strong>@var ntext</strong> <strong>AS</strong> <strong>        exec sp_executesql @var</strong> <strong>GO</strong>
<p>Now despite being a parameterized stored procedure , this one executes whatever is passed to it.Consider the @var variable being set to:</p>
<p><strong>DROP TABLE USERS;</strong></p>
<p><strong>Use parameterized dynamic sql:</strong></p>
<p>Now if you are not using stored procedure, you still should use parameters when constructing dynamic SQL statements. The following code shows how to use parameters with dynamic SQL statement.</p>
<p> <strong>using System.Data;</strong> <strong>using System.Data.SqlClient;</strong> <strong> </strong> <strong>using (SqlConnection connection = new SqlConnection(connectionString))</strong> <strong>{</strong> <strong>  DataSet userDataset = new DataSet();</strong> <strong>  SqlDataAdapter myDataAdapter = new SqlDataAdapter(</strong> <strong>         &#8220;SELECT au_lname, au_fname FROM Authors WHERE au_id = @au_id&#8221;, </strong> <strong>         connection);                </strong> <strong>  myCommand.SelectCommand.Parameters.Add(&#8220;@au_id&#8221;, SqlDbType.VarChar, 11);</strong> <strong>  myCommand.SelectCommand.Parameters["@au_id"].Value = SSN.Text;</strong> <strong>  myDataAdapter.Fill(userDataset);</strong> <strong>}</strong> <strong> </strong>
<p><strong>Using a least privileged database account:</strong></p>
<p>Your application should connect to the database by using a least-privileged account. If you use Windows authentication to connect, the Windows account should be least-privileged from an operating system perspective and should have limited privileges and limited ability to access Windows resources. Additionally, whether or not you use Windows authentication or SQL authentication, the corresponding SQL Server login should be restricted by permissions in the database.</p>
<p>If your ASP.NET application only performs database lookups and does not update any data, you only need to grant read access to the tables. This limits the damage that an attacker can cause if the attacker succeeds in a SQL injection attack.</p>
<p> <a>Avoid Disclosing Error Information</a>
<p>Use structured exception handling to catch errors and prevent them from propagating back to the client. Log detailed error information locally, but return limited error details to the client.</p>
<p>If errors occur while the user is connecting to the database, be sure that you provide only limited information about the nature of the error to the user. If you disclose information related to data access and database errors, you could provide a malicious user with useful information that he or she can use to compromise your database security. Attackers use the information in detailed error messages to help deconstruct a SQL query that they are trying to inject with malicious code. A detailed error message may reveal valuable information such as the connection string, SQL server name, or table and database naming conventions.</p>
<p><strong>Information leakage: Remember that __VIEWSTATE data can be viewed</strong></p>
<p>The __VIEWSTATE’s Base64 encoding can be easily decoded, and the __VIEWSTATE data can be exposed with minimal effort. Now the attacker can see the information that may be sensitive, such as internal state data of the application.To encrypt the __VIEWSTATE data we have to add the machineKey attribute in web.config  file as follows:</p>
<p><strong>&lt;configuration&gt;</strong></p>
<p><strong>&lt;system.web&gt;</strong></p>
<p><strong>&lt;machineKey validation=&#8221;3DES&#8221;/&gt;</strong></p>
<p><strong>&lt;/system.web&gt;</strong></p>
<p><strong>&lt;/configuration&gt;</strong></p>
<p>          <span style="">Somnath has been working as an Information Security Consultant iViZ Techno Solutions,India and have successfully carried out countless assignments on vulnerability assessment, penetration testing, web application security, Threat modeling,PCI DSS Compliance for various Banking sector firms, financial institutions, Govt. organizations, Defense, Software development Companies, leading BPOs and various small-mid-large industries.He holds security certifications like OSCP and CNSM. <br class="clear" /><a rel="dofollow" target="_blank" href="http://www.articlesbase.com/security-articles/secure-aspnet-coding-practice-for-three-most-critical-vulnerabilities-in-web-application-889853.html">Article Source</a></span></p>
   Any ideas?]]></content:encoded>
			<wfw:commentRss>http://www.mostlyclientside.com/secure-asp-net-coding-practice-for-three-most-critical-vulnerabilities-in-web-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To #Region Or Not To #Region</title>
		<link>http://www.mostlyclientside.com/to-region-or-not-to-region/</link>
		<comments>http://www.mostlyclientside.com/to-region-or-not-to-region/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 08:22:19 +0000</pubDate>
		<dc:creator>Michael B Humphrey</dc:creator>
				<category><![CDATA[Code Practices]]></category>
		<category><![CDATA[4 Digits]]></category>
		<category><![CDATA[Boss]]></category>
		<category><![CDATA[Co Worker]]></category>
		<category><![CDATA[Functionality]]></category>
		<category><![CDATA[Lot]]></category>
		<category><![CDATA[Quiz]]></category>
		<category><![CDATA[Regions]]></category>

		<guid isPermaLink="false">http://www.mostlyclientside.com/?p=10</guid>
		<description><![CDATA[That truly is the question. A question that has surfaced today when a co-worker started bitching about the 4 layers of embedded regions in the code he was working on. If you&#8217;re not familiar with regions here&#8217;s a short explanation. In .NET you can surround your code with #Region and #Endregion to make it possible [...]]]></description>
			<content:encoded><![CDATA[<p>That truly is the question. A question that has surfaced today when a co-worker started bitching about the 4 layers of embedded regions in the code he was working on. If you&#8217;re not familiar with regions here&#8217;s a short explanation. In .NET you can surround your code with <code>#Region</code> and <code>#Endregion</code> to make it possible to hide those lines of code. The purpose is to make the code clearer by occupying fewer lines.</p>
<p><span id="more-10"></span></p>
<h3>Use Fewer Lines Of Code!</h3>
<p>As neat as that functionality is I have a better idea. User fewer lines of code. That will not only make it clearer, but it will most likely perform better as well. The long term advantages of minimizing the amount of code you use cannot be exaggerated.</p>
<p>Here&#8217;s an example and a quiz.</p>
<p>Your boss hands you a new assignment. Shockingly an end user has found a bug in your software. He needs you fix it. It&#8217;s not too hard for you to discern the location of the bug. Now here&#8217;s the quiz. Would you like to work on a bug in a file with:</p>
<ol>
<li>488 lines of code</li>
<li>3627 lines of code</li>
</ol>
<p>Yeah! That&#8217;s what I thought. Quantity is not the same as quality.</p>
<p>As luck would have it the file you&#8217;re working on has 3627 lines of code. It happens and as usual you don&#8217;t have time to refactor the code. Do you think it will be helpful to have 20+ regions in the code?</p>
<p>Not really, regions may have their purpose, but I&#8217;d rather have fewer code lines with useful comments.  To be conservative I would say that anymore 4 digits on the line count is too much, personally I&#8217;d prefer to keep it below 500, but that&#8217;s just me. So do me a favor the next time you have to scroll for several minutes before you reach the bottom of your code, try to see if you can refactor some bits here and there. There&#8217;s a lot to gain from doing so.</p>
   Participate in the conversation by leaving your comment below.]]></content:encoded>
			<wfw:commentRss>http://www.mostlyclientside.com/to-region-or-not-to-region/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
