<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[[SecurityRatty] tag: buffer-overflow]]></title>
    <link>http://securityratty.com/tag/buffer-overflow</link>
    <description></description>
    <pubDate>Thu, 15 May 2008 14:45:00 +0000</pubDate>
    <generator>iRatty Engine</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Good hygiene and Banned APIs]]></title>
      <link>http://securityratty.com/article/76a6df21c84c03ac4f35261fb88bd645</link>
      <guid>http://securityratty.com/article/76a6df21c84c03ac4f35261fb88bd645</guid>
      <description><![CDATA[Jeremy Dallman here with a quick note about a code sanitizing tool we are making available to support one of the SDL requirements Remove all Banned APIs from your code
This requirement was put in...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>Jeremy Dallman here with a quick note about&nbsp;a code sanitizing tool we are making available to support one of the SDL requirements – Remove all Banned APIs from your code. </FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>This requirement was put in place to prevent use of certain older C runtime functions that lead to buffer overrun flaws and have been deprecated. In the Security Development Lifecycle book, an entire chapter is dedicated to the topic of banned function calls. In the book, we also provide a copy of the banned.h header file on the companion CD. This header file allows you to locate any banned functions in your code.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>On MSDN, we have document the </FONT><A href="http://msdn.microsoft.com/en-us/library/bb288454.aspx"><FONT face=Calibri size=3>SDL list of Banned Function Calls</FONT></A><FONT face=Calibri size=3>, but the header file has not been publicly available outside the SDL book until now. Today, we are providing the banned.h header on the Microsoft Download Center. </FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><A href="http://download.microsoft.com/download/2/e/b/2ebac853-63b7-49b4-b66f-9fd85f37c0f5/banned.h"><FONT face=Calibri size=3>Find the banned.h header here</FONT></A></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>By including this header file, then using #include “banned.h”; you will be able to locate any banned functions in your code. The full list of banned APIs is also included in the header file.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>Alternately, if you are using the compiler in Visual Studio 2005 or later, you have a built-in way to check for these banned functions. To catch banned C runtime functions, you can compile with /W4 and then triage all C4996 warnings. In code reviews, you should always remove any code that disables the C4996 warnings&nbsp;- e.g.: #pragma warning(disable:4996). This is one simple way to ensure your code is released without banned functions.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>Sanitizing your code to remove potentially insecure APIs is a vital protection. Whether you include the banned.h header file or leverage the /W4-C4996 warnings in the Visual Studio 2005 compiler, you now have two ways to check your code and meet another SDL requirement in your development phase.</FONT></P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9011814" width="1" height="1">]]></content:encoded>
      <pubDate>Wed, 22 Oct 2008 18:08:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/header file">header file</category>
      <category domain="http://securityratty.com/tag/header">header</category>
      <category domain="http://securityratty.com/tag/code">code</category>
      <category domain="http://securityratty.com/tag/code reviews">code reviews</category>
      <category domain="http://securityratty.com/tag/runtime functions">runtime functions</category>
      <category domain="http://securityratty.com/tag/functions">functions</category>
      <category domain="http://securityratty.com/tag/apis">apis</category>
      <category domain="http://securityratty.com/tag/w4-c4996 warnings">w4-c4996 warnings</category>
      <category domain="http://securityratty.com/tag/c4996 warnings">c4996 warnings</category>
      <source url="http://blogs.msdn.com/sdl/archive/2008/10/22/good-hygiene-and-banned-apis.aspx">Good hygiene and Banned APIs</source>
    </item>
    <item>
      <title><![CDATA[SQL Server 2008 - DBCC BYTES]]></title>
      <link>http://securityratty.com/article/16e1ab517124268d885c89a8dea4520c</link>
      <guid>http://securityratty.com/article/16e1ab517124268d885c89a8dea4520c</guid>
      <description><![CDATA[Ive just noticed that Microsoft had removed the DBCC BYTES command from DBCC. On 2005: DBCC TRACEON(2588) DBCC HELP (?') GO activecursors addextendedproc addinstance auditevent autopilot buffer bytes...]]></description>
      <content:encoded><![CDATA[I&#8217;ve just noticed that Microsoft had removed the DBCC BYTES command from DBCC.
On 2005:
DBCC TRACEON(2588)
DBCC HELP (&#8217;?')
GO
activecursors
addextendedproc
addinstance
auditevent
autopilot
buffer
bytes
cacheprofile
cachestats
callfulltext
checkalloc
checkcatalog
checkconstraints
checkdb
checkfilegroup
checkident
checkprimaryfile
checktable
cleantable
clearspacecaches
collectstats
concurrencyviolation
cursorstats
dbrecover
dbreindex
dbreindexall
dbrepair
debugbreak
deleteinstance
detachdb
dropcleanbuffers
dropextendedproc
config
dbinfo
dbtable
lock
log
page
resource
dumptrigger
errorlog
extentinfo
fileheader
fixallocation
flush
flushprocindb
forceghostcleanup
free
freeproccache
freesessioncache
freesystemcache
freeze_io
help
icecapquery
incrementinstance
ind
indexdefrag
inputbuffer
invalidate_textptr
invalidate_textptr_objid
latch
loginfo
mapallocunit
memobjlist
memorymap
memorystatus
metadata
movepage
no_textptr
opentran
optimizer_whatif
outputbuffer
perfmon
persiststackhash
pintable
proccache
prtipage
readpage
renamecolumn
ruleoff
ruleon
semetadata
setcpuweight
setinstance
setioweight
show_statistics
showcontig
showdbaffinity
showfilestats
showoffrules
showonrules
showtableaffinity
showtext
showweights
shrinkdatabase
shrinkfile
sqlmgrstats
sqlperf
stackdump
tec
thaw_io
traceoff
traceon
tracestatus
unpintable
updateusage
useplan
useroptions
writepage
cleanpage
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
While running the same thing on 2008 does not contain DBCC BYTES.
I wonder what&#8217;s the reason for this change (I&#8217;ve checked the binary and it does not contain [...]<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/slaviks-blog/WxxD?a=vcwkL"><img src="http://feeds.feedburner.com/~f/slaviks-blog/WxxD?i=vcwkL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/slaviks-blog/WxxD/~4/397341183" height="1" width="1"/>]]></content:encoded>
      <pubDate>Fri, 19 Sep 2008 12:24:22 +0000</pubDate>
      <category domain="http://securityratty.com/tag/dbcc">dbcc</category>
      <category domain="http://securityratty.com/tag/dbcc bytes">dbcc bytes</category>
      <category domain="http://securityratty.com/tag/dbcc bytes command">dbcc bytes command</category>
      <category domain="http://securityratty.com/tag/dbcc traceon">dbcc traceon</category>
      <category domain="http://securityratty.com/tag/ind indexdefrag inputbuffer">ind indexdefrag inputbuffer</category>
      <category domain="http://securityratty.com/tag/checkdb checkfilegroup checkident">checkdb checkfilegroup checkident</category>
      <category domain="http://securityratty.com/tag/free freeproccache">free freeproccache</category>
      <category domain="http://securityratty.com/tag/system administrator">system administrator</category>
      <category domain="http://securityratty.com/tag/error messages">error messages</category>
      <source url="http://feeds.feedburner.com/~r/slaviks-blog/WxxD/~3/397341183/">SQL Server 2008 - DBCC BYTES</source>
    </item>
    <item>
      <title><![CDATA[SDL and the XSS Filter]]></title>
      <link>http://securityratty.com/article/ce479edf032699e552a4cb52750d1f63</link>
      <guid>http://securityratty.com/article/ce479edf032699e552a4cb52750d1f63</guid>
      <description><![CDATA[Steve Lipner here. When the Internet Explorer team posted the announcement about the XSS Filter feature in IE8 I asked some other members of the SDL blog team why arent we talking about the new XSS...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Calibri size=3>Steve Lipner here.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>When the Internet Explorer team posted the announcement about the </FONT><A href="http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx"><FONT face=Calibri color=#0000ff size=3>XSS Filter feature in IE8</FONT></A><FONT size=3><FONT face=Calibri> <SPAN style="mso-spacerun: yes">&nbsp;</SPAN>I asked some other members of the SDL blog team “why aren’t we talking about the new XSS Filter feature on the SDL blog?” &nbsp;Bryan and Jeremy said something like “that’s a mitigation that only applies to specific clients and a subset of attacks”.&nbsp; So we didn’t cross-reference IE’s XSS Filter post on the SDL blog at the time.&nbsp; Instead, I agreed to write a subsequent post about the relationship of XSS Filter to the SDL and to the ways that our SDL and security science teams think about improving product security.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Calibri size=3>For those of you who aren’t familiar with XSS Filter, a brief summary is that it is a client-side defense against reflected cross-site scripting (XSS) attacks.&nbsp; It works by recognizing that reflected XSS attacks inject script into the string that the browser sends to the targeted web server.&nbsp; If the server doesn’t neuter or strip out the injected script, it gets sent back to the browser and executed in the context of the target web page.&nbsp; Bad things then happen.&nbsp; At a high level, XSS Filter remembers the string that the browser sent to the server, and looks at the server’s response to see if any of the script was actually in that string.&nbsp; If it was, then XSS Filter decides that it got there because it was injected by an XSS attack and blocks the script from executing.&nbsp; The rest of the web page renders as usual.&nbsp; This is a vastly oversimplified sketch of XSS Filter – for details, see the post by David Ross, inventor of XSS Filter on the </FONT><A href="http://blogs.technet.com/swi/archive/2008/08/19/ie-8-xss-filter-architecture-implementation.aspx"><FONT face=Calibri color=#0000ff size=3>Security Vulnerability Research and Defense blog</FONT></A><FONT size=3><FONT face=Calibri>.<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>So what does XSS Filter have to do with the SDL?&nbsp; Well, for almost nine years, since XSS was first discovered at Microsoft, we’ve been trying to figure out effective ways to reduce vulnerability to XSS attacks.&nbsp; Our focus has been on improving the ways that web page developers code their pages, and we’ve developed a lot of tools and techniques for making web content safer from XSS attacks and for detecting XSS vulnerabilities in live pages.&nbsp; The SDL requires the use of many of these tools and techniques, and we’re sure we’ve prevented a lot of XSS vulnerabilities from being introduced into Microsoft web pages as a result.&nbsp; <o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>But while we identify (and the SDL requires) measures that allow developers to avoid classes of vulnerabilities, we also look to identify more sweeping solutions that can either 1) eliminate classes of vulnerabilities, 2) reduce their severity, or 3) reduce the likelihood of attacks being successful.&nbsp; The process usually starts from deep understanding of a class of vulnerabilities and attacks, and then we broaden defenses from there.&nbsp; In the case of XSS Filter, David’s years of work researching XSS led him to come up with an approach that blocks many of the most common vulnerabilities to reflected attacks found on the web today.&nbsp; The solution is compatible with existing web pages (doesn’t “break the web”) and thus we were able to enable it by default for users of Internet Explorer 8.&nbsp; Because it’s a client-side mitigation, it will help protect users from attacks even though the sites they visit may be vulnerable to XSS.&nbsp; <o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Calibri size=3>Our work on buffer overrun defenses follows a somewhat similar pattern – we started by prescribing coding techniques, banning the use of some APIs, and building tools that detect coding constructs that look like buffer overruns.&nbsp; As we gained a deeper understanding of how buffer overruns can be exploited, we enhanced the </FONT><A href="http://msdn.microsoft.com/en-us/library/8dbf701c(VS.80).aspx"><FONT face=Calibri size=3>/GS compiler flag</FONT></A><FONT face=Calibri size=3> and added </FONT><A href="http://blogs.msdn.com/michael_howard/archive/2006/05/26/address-space-layout-randomization-in-windows-vista.aspx"><FONT face=Calibri color=#0000ff size=3>ASLR</FONT></A><FONT size=3><FONT face=Calibri> in a quest to cause classes of exploits to fail even if a buffer overrun remains.&nbsp; We’re not yet close to eliminating the SDL requirements for use of tools and coding techniques, but the SDL also requires the use of the mitigations to reduce the severity of vulnerabilities that slip past.&nbsp; Will we ever get to the point where the mitigating technologies are so strong that we can relax the coding requirements?&nbsp; Maybe not, but we will continue to introduce technologies that reduce the chances of a successful attack.<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Calibri size=3>Similarly, in the case of XSS, even after IE8 ships, the SDL will continue to require the use of safe web site coding practices and tools such as the </FONT><A href="http://msdn.microsoft.com/en-us/library/aa973813.aspx"><FONT face=Calibri color=#0000ff size=3>Anti-XSS library</FONT></A><FONT size=3><FONT face=Calibri> both to protect users of browsers other than IE8 and to provide protection in recognition of the fact that XSS Filter is a mitigation or defense in depth rather than a complete solution.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But we’ll also be keeping our eyes open (and doing active research) in the quest for an even more effective defense – whether client or server side – that eliminates XSS for good.<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Calibri size=3>This post is a little far afield from the normal content of the SDL blog, but I thought it was important to provide a picture of the role of security science and security research in defining SDL requirements and in making major improvements in software security.&nbsp; You can read more about our work in security science in the </FONT><A href="http://blogs.technet.com/swi/default.aspx"><FONT face=Calibri color=#0000ff size=3>Security Vulnerability Research and Defense blog</FONT></A><FONT size=3><FONT face=Calibri>.</FONT></FONT></P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8900490" width="1" height="1">]]></content:encoded>
      <pubDate>Wed, 27 Aug 2008 11:35:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/xss">xss</category>
      <category domain="http://securityratty.com/tag/xss filter">xss filter</category>
      <category domain="http://securityratty.com/tag/xss vulnerabilities">xss vulnerabilities</category>
      <category domain="http://securityratty.com/tag/xss led">xss led</category>
      <category domain="http://securityratty.com/tag/anti-xss library">anti-xss library</category>
      <category domain="http://securityratty.com/tag/xss attack">xss attack</category>
      <category domain="http://securityratty.com/tag/xss attacks">xss attacks</category>
      <category domain="http://securityratty.com/tag/attacks">attacks</category>
      <category domain="http://securityratty.com/tag/xss filter remembers">xss filter remembers</category>
      <source url="http://blogs.msdn.com/sdl/archive/2008/08/27/sdl-and-the-xss-filter.aspx">SDL and the XSS Filter</source>
    </item>
    <item>
      <title><![CDATA[Serializable XmlDocument]]></title>
      <link>http://securityratty.com/article/94c84cd2ea7a6ea71c9712991d27722d</link>
      <guid>http://securityratty.com/article/94c84cd2ea7a6ea71c9712991d27722d</guid>
      <description><![CDATA[It's surprising that XmlDocument isn't marked [Serializable], because it's very natural to serialize one into a stream. I wanted to put an object into ASP.NET ViewState the other day, and quickly ran...]]></description>
      <content:encoded><![CDATA[<p>It&#39;s surprising that XmlDocument isn&#39;t marked [Serializable], because it&#39;s very natural to serialize one into a stream. I wanted to put an object into ASP.NET ViewState the other day, and quickly ran into this roadblock, because part of the object included an XmlDocument, which is not serializable. A quick search revealed that most people deal with this problem by storing a string instead. Indeed, that was where I started, but I quickly realized that there are multiple places in my code where I want to do this sort of thing, and I don&#39;t want to have to mess with it in each data structure that contains an XmlDocument.</p>
<p>So I put together a simple class that holds an XmlDocument and implements ISerializable and called it SerializableXmlDocument. I&#39;m sharing the source code here in the hopes that</p>
<blockquote>
<p>a) somebody will find it useful, and</p>
<p>b) somebody smarter than I am will point out how I screwed it up and help me make it better.</p>
</blockquote>
<p>SerializableXmlDocument includes implicit conversion operators to make it easy to convert to/from an XmlDocument. It holds the actual document in a property called Value. This &quot;isomorph&quot; pattern is one that I picked up from <a href="http://www.pluralsight.com/community/blogs/craig/default.aspx" target="_blank">Craig</a>.</p>
<p>While writing this code, I also wrote a helpful extension method for getting a byte array out of a MemoryStream that is exactly the length of the data written to the stream so far (CopyUpToSeekPointer). So don&#39;t go looking in the docs for MemoryStream for this method :) This is obviously not the most efficient way to consume bytes written to a MemoryStream since it copies the data into a new byte array, but it&#39;s very convenient in many scenarios.</p>
<p>Here is SerializableXmlDocument.cs:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;<br /><span class="kwrd">using</span> System.Runtime.Serialization;<br /><span class="kwrd">using</span> System.Xml;<br /><span class="kwrd">using</span> System.IO;<br /><br /><span class="kwrd">namespace</span> Pluralsight.Samples<br />{<br />    [Serializable]<br />    <span class="kwrd">public</span> <span class="kwrd">class</span> SerializableXmlDocument : ISerializable<br />    {<br />        <span class="kwrd">public</span> SerializableXmlDocument() { }<br />        <span class="kwrd">public</span> SerializableXmlDocument(XmlDocument <span class="kwrd">value</span>)<br />        {<br />            <span class="kwrd">this</span>.Value = <span class="kwrd">value</span>;<br />        }<br /><br />        <span class="kwrd">public</span> XmlDocument Value { get; set; }<br /><br />        <span class="preproc">#region</span> ISerializable implementation<br />        <span class="kwrd">public</span> SerializableXmlDocument(SerializationInfo info,<br />                                       StreamingContext context)<br />        {<br />            <span class="kwrd">byte</span>[] serializedData = (<span class="kwrd">byte</span>[])info.GetValue(<span class="str">&quot;doc&quot;</span>,<br />                <span class="kwrd">typeof</span>(<span class="kwrd">byte</span>[]));<br />            <span class="kwrd">if</span> (<span class="kwrd">null</span> != serializedData)<br />                <span class="kwrd">this</span>.Value = Deserialize(serializedData);<br />        }<br /><br />        <span class="kwrd">public</span> <span class="kwrd">void</span> GetObjectData(SerializationInfo info,<br />                                  StreamingContext context)<br />        {<br />            <span class="kwrd">byte</span>[] serializedData = <span class="kwrd">null</span>;<br />            <span class="kwrd">if</span> (<span class="kwrd">null</span> != Value)<br />                serializedData = Serialize(Value);<br />            info.AddValue(<span class="str">&quot;doc&quot;</span>, serializedData);<br />        }<br />        <span class="preproc">#endregion</span><br /><br />        <span class="preproc">#region</span> <span class="kwrd">implicit</span> conversion to/from XmlDocument<br />        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">implicit</span> <span class="kwrd">operator</span> SerializableXmlDocument(<br />            XmlDocument doc)<br />        {<br />            <span class="kwrd">return</span> <span class="kwrd">new</span> SerializableXmlDocument(doc);<br />        }<br />        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">implicit</span> <span class="kwrd">operator</span> XmlDocument(<br />            SerializableXmlDocument sdoc)<br />        {<br />            <span class="kwrd">return</span> sdoc.Value;<br />        }<br />        <span class="preproc">#endregion</span><br /><br />        <span class="preproc">#region</span> Xml serialization helper methods<br />        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">byte</span>[] Serialize(XmlDocument doc)<br />        {<br />            MemoryStream stream = <span class="kwrd">new</span> MemoryStream();<br />            doc.Save(stream);<br />            <span class="kwrd">return</span> stream.CopyUpToSeekPointer();<br />        }<br />        <span class="kwrd">private</span> <span class="kwrd">static</span> XmlDocument Deserialize(<span class="kwrd">byte</span>[] serializedData)<br />        {<br />            XmlDocument doc = <span class="kwrd">new</span> XmlDocument();<br />            doc.Load(<span class="kwrd">new</span> MemoryStream(serializedData, <span class="kwrd">false</span>));<br />            <span class="kwrd">return</span> doc;<br />        }<br />        <span class="preproc">#endregion</span><br />    }<br />}</pre>
<p>...and here&#39;s the CopyUpToSeekPointer extension method for MemoryStream:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;<br /><span class="kwrd">using</span> System.IO;<br /><br /><span class="kwrd">namespace</span> Pluralsight.Samples<br />{<br />    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> MemoryStreamExtensionMethods<br />    {<br />        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">byte</span>[] CopyUpToSeekPointer(<br />            <span class="kwrd">this</span> MemoryStream stream)<br />        {<br />            <span class="rem">// copy only the part of the buffer</span><br />            <span class="rem">// that contains the serialized document</span><br />            <span class="kwrd">long</span> length = stream.Position;<br />            <span class="kwrd">byte</span>[] buffer = stream.GetBuffer();<br />            <span class="kwrd">byte</span>[] result = <span class="kwrd">new</span> <span class="kwrd">byte</span>[length];<br />            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; length; ++i)<br />                result[i] = buffer[i];<br />            <span class="kwrd">return</span> result;<br />        }<br />    }<br />}</pre>
<p>...and here&#39;s a sample object that uses SerializableXmlDocument:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;<br /><br /><span class="kwrd">namespace</span> Pluralsight.Samples<br />{<br />    [Serializable]<br />    <span class="kwrd">public</span> <span class="kwrd">class</span> Item<br />    {<br />        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }<br />        <span class="kwrd">public</span> SerializableXmlDocument Data { get; set; }<br /><br />        <span class="kwrd">public</span> <span class="kwrd">void</span> Print()<br />        {<br />            Console.WriteLine(<span class="str">&quot;Name: {0}&quot;</span>, Name);<br />            Console.WriteLine(Data.Value.OuterXml);<br />        }<br />    }<br />}</pre>
<p>...and here&#39;s a sample program that creates an instance of Item, serializes it, then deserializes it, printing diagnostics along the way to show that it&#39;s working properly.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;<br /><span class="kwrd">using</span> System.Xml;<br /><span class="kwrd">using</span> System.Runtime.Serialization.Formatters.Binary;<br /><span class="kwrd">using</span> System.IO;<br /><span class="kwrd">using</span> Pluralsight.Samples;<br /><br /><span class="kwrd">class</span> DemoProgram<br />{<br />    <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)<br />    {<br />        XmlDocument doc = <span class="kwrd">new</span> XmlDocument();<br />        doc.LoadXml(<span class="str">&quot;&lt;root&gt;&lt;child&gt;text&lt;/child&gt;&lt;/root&gt;&quot;</span>);<br /><br />        Item item = <span class="kwrd">new</span> Item<br />        {<br />            Name = <span class="str">&quot;Testing 123&quot;</span>,<br />            Data = doc,<br />        };<br /><br />        <span class="rem">// print object before serialization</span><br />        item.Print();<br /><br />        BinaryFormatter formatter = <span class="kwrd">new</span> BinaryFormatter();<br />        MemoryStream stream = <span class="kwrd">new</span> MemoryStream();<br />        formatter.Serialize(stream, item);<br /><br />        <span class="kwrd">byte</span>[] serializedItem = stream.CopyUpToSeekPointer();<br /><br />        Console.WriteLine(<span class="str">&quot;Serialized data (base64): {0}&quot;</span>,<br />            Convert.ToBase64String(serializedItem));<br /><br />        item = (Item)formatter.Deserialize(<br />            <span class="kwrd">new</span> MemoryStream(serializedItem, <span class="kwrd">false</span>));<br /><br />        <span class="rem">// print object after deserialization</span><br />        item.Print();<br />    }<br />}</pre>
<p>Here&#39;s the output of the previous sample program:</p>
<p><a href="http://www.pluralsight.com/community/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/keith/sample_2D00_output_5F00_2.jpg"><img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" alt="sample-output" src="http://www.pluralsight.com/community/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/keith/sample_2D00_output_5F00_thumb.jpg" width="422" border="0" height="214" /></a>&nbsp;</p>
<p>Flame away!</p><div style="clear:both;"></div><img src="http://www.pluralsight.com/community/aggbug.aspx?PostID=52538" width="1" height="1">]]></content:encoded>
      <pubDate>Mon, 18 Aug 2008 22:58:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/public class item">public class item</category>
      <category domain="http://securityratty.com/tag/public">public</category>
      <category domain="http://securityratty.com/tag/public void getobjectdata">public void getobjectdata</category>
      <category domain="http://securityratty.com/tag/public static byte">public static byte</category>
      <category domain="http://securityratty.com/tag/xmldocument">xmldocument</category>
      <category domain="http://securityratty.com/tag/return doc">return doc</category>
      <category domain="http://securityratty.com/tag/return">return</category>
      <category domain="http://securityratty.com/tag/static byte">static byte</category>
      <category domain="http://securityratty.com/tag/public class">public class</category>
      <source url="http://www.pluralsight.com/community/blogs/keith/archive/2008/08/18/serializable-xmldocument.aspx">Serializable XmlDocument</source>
    </item>
    <item>
      <title><![CDATA[Better exception reporting in ASP.NET part 2]]></title>
      <link>http://securityratty.com/article/b878f7921917b371086606df6d043229</link>
      <guid>http://securityratty.com/article/b878f7921917b371086606df6d043229</guid>
      <description><![CDATA[This is the third post in a series
The first post described the problem: ASP.NET wasn't reporting inner exception stack traces
The second post described my solution
This post shows the code I used to...]]></description>
      <content:encoded><![CDATA[<p>This is the third post in a series.</p> <p>The <a href="http://www.pluralsight.com/community/blogs/keith/archive/2008/08/01/asp-net-health-monitoring-doesn-t-log-inner-exception-stack-trace.aspx" target="_blank">first post</a> described the problem: ASP.NET wasn&#39;t reporting inner exception stack traces.</p> <p>The <a href="http://www.pluralsight.com/community/blogs/keith/archive/2008/08/01/better-exception-reporting-in-asp-net.aspx" target="_blank">second post</a> described my solution.</p> <p>This post shows the code I used to solve the problem: a custom email provider for the Health Monitoring system in ASP.NET. Enjoy!</p> <p>Here&#39;s the provider. Note that I opted *not* to build a buffering provider to keep things simple:</p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> MyMailWebEventProvider : WebEventProvider
{
    <span class="kwrd">string</span> to;
    <span class="kwrd">string</span> from;
    <span class="kwrd">string</span> subjectPrefix;

    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Initialize(<span class="kwrd">string</span> name,
        NameValueCollection config)
    {
        <span class="kwrd">base</span>.Initialize(name, config);

        to = GetAndRemoveStringAttribute(config, <span class="str">&quot;to&quot;</span>, <span class="kwrd">true</span>);
        from = GetAndRemoveStringAttribute(config, <span class="str">&quot;from&quot;</span>, <span class="kwrd">true</span>);
        subjectPrefix = GetAndRemoveStringAttribute(config,
            <span class="str">&quot;subjectPrefix&quot;</span>, <span class="kwrd">false</span>);
    }
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> ProcessEvent(WebBaseEvent raisedEvent)
    {
        SendMail(raisedEvent);
    }

    <span class="kwrd">private</span> <span class="kwrd">void</span> SendMail(WebBaseEvent raisedEvent)
    {
        <span class="kwrd">string</span> subject = ComputeEmailSubject(raisedEvent);
        <span class="kwrd">string</span> body = ComputeEmailBody(raisedEvent);

        MailMessage msg = <span class="kwrd">new</span> MailMessage(from, to, subject, body);
        <span class="kwrd">new</span> SmtpClient().Send(msg);
    }

    <span class="kwrd">private</span> <span class="kwrd">string</span> ComputeEmailBody(WebBaseEvent raisedEvent)
    {
        WebRequestErrorEvent errorEvent =
            raisedEvent <span class="kwrd">as</span> WebRequestErrorEvent;
        <span class="kwrd">if</span> (<span class="kwrd">null</span> != errorEvent)
            <span class="kwrd">return</span> ErrorEventFormattingHelper.FormatRequestErrorEvent(errorEvent);
        <span class="kwrd">else</span> <span class="kwrd">return</span> raisedEvent.ToString();
    }

    <span class="kwrd">private</span> <span class="kwrd">string</span> ComputeEmailSubject(WebBaseEvent raisedEvent)
    {
        StringBuilder subjectBuilder = <span class="kwrd">new</span> StringBuilder();

        <span class="rem">// surface some details in subject about error events</span>
        WebBaseErrorEvent errorEvent = raisedEvent <span class="kwrd">as</span> WebBaseErrorEvent;
        <span class="kwrd">if</span> (<span class="kwrd">null</span> != errorEvent)
        {
            Exception unhandledException = errorEvent.ErrorException;

            <span class="rem">// drill through reflection exceptions to show the root cause</span>
            TargetInvocationException invocationException =
                unhandledException <span class="kwrd">as</span> TargetInvocationException;
            <span class="kwrd">if</span> (<span class="kwrd">null</span> != invocationException)
            {
                Exception innerException =
                    DrillIntoTargetInvocationException(invocationException);
                subjectBuilder.AppendFormat(<span class="str">&quot;{0}&quot;</span>,
                    (innerException ?? invocationException).GetType().Name);
                <span class="kwrd">if</span> (<span class="kwrd">null</span> != innerException)
                    subjectBuilder.Append(<span class="str">&quot; (via reflection)&quot;</span>);
            }
            <span class="kwrd">else</span> subjectBuilder.Append(unhandledException.GetType().Name);
        }

        <span class="rem">// if we&#39;ve not got anything better</span>
        <span class="rem">// just show the event type in the subject</span>
        <span class="kwrd">if</span> (0 == subjectBuilder.Length)
            subjectBuilder.AppendFormat(<span class="str">&quot;Event type: {0}&quot;</span>,
                raisedEvent.GetType().Name);

        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(subjectPrefix)) {
            subjectBuilder.Insert(0, <span class="str">&#39; &#39;</span>);
            subjectBuilder.Insert(0, subjectPrefix);
        }
        <span class="kwrd">return</span> subjectBuilder.ToString();
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Reflection often hides exception details, so we try to drill down</span>
    <span class="rem">/// through the plumbing exceptions to find a likely cause</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">private</span> Exception DrillIntoTargetInvocationException(
        TargetInvocationException outerException)
    {
        Exception innerException = outerException.InnerException;
        TargetInvocationException innerInvocationException =
            innerException <span class="kwrd">as</span> TargetInvocationException;
        <span class="kwrd">if</span> (<span class="kwrd">null</span> != innerInvocationException)
            <span class="kwrd">return</span> DrillIntoTargetInvocationException(innerInvocationException);
        <span class="kwrd">else</span> <span class="kwrd">if</span> (<span class="kwrd">null</span> != innerException)
            <span class="kwrd">return</span> innerException;
        <span class="kwrd">else</span> <span class="kwrd">return</span> <span class="kwrd">null</span>;
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetAndRemoveStringAttribute(NameValueCollection config,
        <span class="kwrd">string</span> attributeName, <span class="kwrd">bool</span> required)
    {
        <span class="kwrd">string</span> <span class="kwrd">value</span> = config.Get(attributeName);
        <span class="kwrd">if</span> (required &amp;&amp; <span class="kwrd">string</span>.IsNullOrEmpty(<span class="kwrd">value</span>))
            <span class="kwrd">throw</span> <span class="kwrd">new</span> ConfigurationErrorsException(<span class="kwrd">string</span>.Format(
                <span class="str">&quot;Expected attribute {0}, which is missing or empty.&quot;</span>,
                attributeName));
        config.Remove(attributeName);
        <span class="kwrd">return</span> <span class="kwrd">value</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Flush()
    {
        <span class="rem">// nothing to do - this is not a buffering provider</span>
    }

    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Shutdown()
    {
        <span class="rem">// nothing to do here either</span>
    }
}</pre>
<p>Here&#39;s a helper class that formats the error messages the way I want to see them. Note that I&#39;ve omitted some fields that I personally didn&#39;t care about, and I&#39;ve reordered things a bit, so you might want to tweak this if you&#39;re going to use it in your own system.</p><pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">class</span> ErrorEventFormattingHelper
{
    <span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">string</span> FormatRequestErrorEvent(
        WebRequestErrorEvent errorEvent)
    {
        CustomEventFormatter formatter = 
            <span class="kwrd">new</span> CustomEventFormatter();

        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Unhandled Exception in {0}:&quot;</span>,
            WebBaseEvent.ApplicationInformation
            .ApplicationVirtualPath));
        formatter.Indent();
        EmitExceptionAtAGlance(formatter, 
            errorEvent.ErrorException);
        formatter.RevertIndent();

        formatter.AppendLine();
        formatter.AppendLine(<span class="str">&quot;Exception stack trace(s):&quot;</span>);
        EmitExceptionStackTrace(formatter, 
            errorEvent.ErrorException);

        formatter.AppendLine();
        formatter.AppendLine(<span class="str">&quot;Event information:&quot;</span>);
        formatter.Indent();
        EmitEventInfo(formatter, errorEvent);
        formatter.RevertIndent();

        formatter.AppendLine();
        formatter.AppendLine(<span class="str">&quot;Application information:&quot;</span>);
        formatter.Indent();
        EmitApplicationInfo(formatter, 
            WebBaseEvent.ApplicationInformation);
        formatter.RevertIndent();

        formatter.AppendLine();
        formatter.AppendLine(<span class="str">&quot;Process/thread information:&quot;</span>);
        formatter.Indent();
        EmitProcessInfo(formatter, 
            errorEvent.ProcessInformation);
        formatter.RevertIndent();

        formatter.AppendLine();
        formatter.AppendLine(<span class="str">&quot;Request information:&quot;</span>);
        formatter.Indent();
        EmitRequestInfo(formatter, 
            errorEvent.RequestInformation);
        formatter.RevertIndent();

        <span class="kwrd">return</span> formatter.ToString();
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitEventInfo(
        CustomEventFormatter formatter,
        WebBaseEvent theEvent)
    {
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Event code: {0}&quot;</span>,
            theEvent.EventCode.ToString(
            CultureInfo.InvariantCulture)));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Event message: {0}&quot;</span>, 
            theEvent.Message));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Event time: {0}&quot;</span>, 
            theEvent.EventTime.ToString(
            CultureInfo.InvariantCulture)));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Event ID: {0}&quot;</span>, 
            theEvent.EventID.ToString(<span class="str">&quot;N&quot;</span>, 
            CultureInfo.InvariantCulture)));
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitApplicationInfo(
        CustomEventFormatter formatter, 
        WebApplicationInformation appInfo)
    {
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Application domain: {0}&quot;</span>, 
            appInfo.ApplicationDomain));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Application Virtual Path: {0}&quot;</span>, 
            appInfo.ApplicationVirtualPath));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Application Physical Path: {0}&quot;</span>, 
            appInfo.ApplicationPath));
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitProcessInfo(
        CustomEventFormatter formatter, 
        WebProcessInformation webProcessInfo)
    {
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Process ID: {0}&quot;</span>, 
            webProcessInfo.ProcessID.ToString(
            CultureInfo.InvariantCulture)));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Process name: {0}&quot;</span>, 
            webProcessInfo.ProcessName));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Account name: {0}&quot;</span>, 
            webProcessInfo.AccountName));
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitRequestInfo(
        CustomEventFormatter formatter, 
        WebRequestInformation webRequestInfo)
    {
        <span class="kwrd">string</span> name = <span class="kwrd">null</span>;
        <span class="kwrd">if</span> (webRequestInfo.Principal != <span class="kwrd">null</span>)
            name = webRequestInfo.Principal.Identity.Name;

        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Request URL: {0}&quot;</span>, 
            webRequestInfo.RequestUrl));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Request path: {0}&quot;</span>, 
            webRequestInfo.RequestPath));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;User name: {0}&quot;</span>, 
            name ?? <span class="str">&quot;[ANONYMOUS]&quot;</span>));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;User host address: {0}&quot;</span>, 
            webRequestInfo.UserHostAddress));
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitExceptionAtAGlance(
        CustomEventFormatter formatter, 
        Exception exception)
    {
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Type: {0}&quot;</span>, 
            exception.GetType().Name));
        formatter.AppendLine(<span class="kwrd">string</span>.Format(
            <span class="str">&quot;Message: {0}&quot;</span>, 
            exception.Message));
        <span class="kwrd">if</span> (<span class="kwrd">null</span> != exception.InnerException)
        {
            formatter.Indent();
            formatter.AppendLine(<span class="str">&quot;--&gt;Inner Exception&quot;</span>);
            EmitExceptionAtAGlance(formatter, 
                exception.InnerException);
            formatter.RevertIndent();
        }
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> EmitExceptionStackTrace(
        CustomEventFormatter formatter, Exception exception)
    {
        formatter.AppendLine(exception.StackTrace);

        <span class="kwrd">if</span> (<span class="kwrd">null</span> != exception.InnerException)
        {
            <span class="rem">// no point indenting</span>
            <span class="rem">// since stack traces typically wrap like crazy</span>
            formatter.AppendLine();
            formatter.AppendLine(<span class="str">&quot;--&gt;Inner exception stack trace:&quot;</span>);
            EmitExceptionStackTrace(formatter, exception.InnerException);
        }
    }
}
</pre>
<p>And finally, here&#39;s a helper class that manages indentation levels for the output email message:</p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> CustomEventFormatter
{
    <span class="kwrd">const</span> <span class="kwrd">int</span> TabSpaces = 4;

    StringBuilder sb = <span class="kwrd">new</span> StringBuilder();
    <span class="kwrd">private</span> <span class="kwrd">int</span> indentLevel;
    <span class="kwrd">private</span> <span class="kwrd">bool</span> startingNewLine = <span class="kwrd">true</span>;

    <span class="kwrd">public</span> <span class="kwrd">void</span> Indent()
    {
        ++indentLevel;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> RevertIndent()
    {
        <span class="kwrd">if</span> (indentLevel &gt; 0)
            --indentLevel;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Append(<span class="kwrd">string</span> text)
    {
        <span class="kwrd">if</span> (startingNewLine)
            EmitIndent();
        sb.Append(text);
        startingNewLine = <span class="kwrd">false</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> AppendLine(<span class="kwrd">string</span> lineOfText)
    {
        <span class="kwrd">if</span> (startingNewLine)
            EmitIndent();
        EmitIndent();
        sb.AppendLine(lineOfText);
        startingNewLine = <span class="kwrd">true</span>;
    }

    <span class="kwrd">private</span> <span class="kwrd">void</span> EmitIndent()
    {
        sb.Append(<span class="str">&#39; &#39;</span>, TabSpaces * indentLevel);
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> AppendLine()
    {
        AppendLine(<span class="kwrd">string</span>.Empty);
    }

    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
    {
        <span class="kwrd">return</span> sb.ToString();
    }
}
</pre>
<p>Build this into a library application and reference it in your config file. Here&#39;s an example:</p><pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">healthMonitoring</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;mailWebEventProvider&quot;</span>
         <span class="attr">type</span><span class="kwrd">=&quot;MyMailWebEventProvider&quot;</span>
         <span class="attr">to</span><span class="kwrd">=&quot;web-fault@fabrikam.com&quot;</span>
         <span class="attr">from</span><span class="kwrd">=&quot;website@fabrikam.com&quot;</span>
         <span class="attr">buffer</span><span class="kwrd">=&quot;false&quot;</span>
         <span class="attr">subjectPrefix</span><span class="kwrd">=&quot;[WEB-ERROR]&quot;</span>
       <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">rules</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;All Errors Email&quot;</span>
         <span class="attr">eventName</span><span class="kwrd">=&quot;All Errors&quot;</span>
         <span class="attr">provider</span><span class="kwrd">=&quot;mailWebEventProvider&quot;</span>
         <span class="attr">profile</span><span class="kwrd">=&quot;Default&quot;</span>
         <span class="attr">minInstances</span><span class="kwrd">=&quot;1&quot;</span>
         <span class="attr">maxLimit</span><span class="kwrd">=&quot;Infinite&quot;</span>
         <span class="attr">minInterval</span><span class="kwrd">=&quot;00:01:00&quot;</span>
         <span class="attr">custom</span><span class="kwrd">=&quot;&quot;</span><span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">rules</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">healthMonitoring</span><span class="kwrd">&gt;</span>
</pre><div style="clear:both;"></div><img src="http://www.pluralsight.com/community/aggbug.aspx?PostID=52349" width="1" height="1">]]></content:encoded>
      <pubDate>Mon, 04 Aug 2008 10:11:14 +0000</pubDate>
      <category domain="http://securityratty.com/tag/return">return</category>
      <category domain="http://securityratty.com/tag/return subjectbuilder">return subjectbuilder</category>
      <category domain="http://securityratty.com/tag/return formatter">return formatter</category>
      <category domain="http://securityratty.com/tag/exception">exception</category>
      <category domain="http://securityratty.com/tag/formatter">formatter</category>
      <category domain="http://securityratty.com/tag/crazy formatter">crazy formatter</category>
      <category domain="http://securityratty.com/tag/static void">static void</category>
      <category domain="http://securityratty.com/tag/static void emitprocessinfo">static void emitprocessinfo</category>
      <category domain="http://securityratty.com/tag/return null">return null</category>
      <source url="http://www.pluralsight.com/community/blogs/keith/archive/2008/08/04/better-exception-reporting-in-asp-net-part-2.aspx">Better exception reporting in ASP.NET part 2</source>
    </item>
    <item>
      <title><![CDATA[Cloudsecurity.org Interviews Guido van Rossum: Google App Engine, Python and Security]]></title>
      <link>http://securityratty.com/article/a2cf6f2181968ed75532873c1bdb09fe</link>
      <guid>http://securityratty.com/article/a2cf6f2181968ed75532873c1bdb09fe</guid>
      <description><![CDATA[In this interview, cloudsecurity.org talks to Guido van Rossum about Python , Google App Engine and security
Guido is the creator of the Python programming language and more recently, Google App...]]></description>
      <content:encoded><![CDATA[<p><a title="Guido van Rossum in Google Uniform" href="http://www.python.org/~guido/" target="_blank"><img src="http://www.python.org/~guido/images/IMG_2192.jpg" border="0" alt="Guido Homepage" /></a></p>
<p>In this interview, cloudsecurity.org talks to <a title="Homepage of Guido van Rossum" href="http://www.python.org/~guido/">Guido van Rossum</a> about <a title="Python website" href="http://python.org">Python</a>, <a title="Description of Google AppEngine" href="http://code.google.com/appengine/docs/whatisgoogleappengine.html">Google App Engine</a> and security.</p>
<p>Guido is the creator of the Python programming language and more recently, Google App Engine team member.  His involvement with the App Engine project was pretty late - the code &#8220;was almost ready for release&#8221; when he get involved.  The security architect of App Engine was primarily project lead, <a title="Kevin Gibbs Campfire Transcript" href="http://code.google.com/appengine/articles/cf1-text.html">Kevin Gibbs</a>, supported by the rest of the App Engine crew and the Google Security Team.</p>
<h4>The Interview</h4>
<p><em>cloudsecurity.org: What security principles did you follow for App Engine?<br />
</em></p>
<p>GvR: While I can&#8217;t share any specifics on what we&#8217;re doing to secure App Engine, I can say that the main principle we&#8217;ve followed could be called &#8220;defense in depth&#8221;. We&#8217;re not relying exclusively on a secure interpreter, or any other single security layer, to protect our users.</p>
<p><em>cloudsecurity.org: Please provide some examples of how those principles played out in terms of the current implementation?<br />
</em> <em> </em></p>
<p>GvR: Sorry, we don&#8217;t divulge such information.</p>
<p><em>cloudsecurity.org: What criteria did you apply to Python module selection?</em></p>
<p>GvR: We first looked for modules that were useful and straightforward to audit. If a module was large or complex, we&#8217;d only audit it (fixing things we found) if it was deemed essential or at least useful for a large number of users; otherwise we&#8217;d exclude it.</p>
<p><em>cloudsecurity.org: What do you see as the security risks inherent in exposing an interpreter runtime in a shared environment?<br />
</em></p>
<p>GvR: <span>I presume you&#8217;re asking about risks to users, like providing accidental access to data belonging to another app. We&#8217;ve taken extensive measures to isolate different apps from each other. For example, each app runs in a separate process, and the datastore prevents an app from accessing data belonging to other apps.</span></p>
<p><em>cloudsecurity.org: I recently attended a fascinating talk by <a title="Justin Ferguson" href="http://eusecwest.com/justin-ferguson-interpreter-vm-attacks.html" target="_blank">Justin Ferguson</a> (a Seattle based security consultant) at <a title="eusecwest" href="http://www.eusecwest.com/" target="_blank">eusecwest</a> in London.  He gave a great talk exploring security vulnerabilities in language interpreters and specifically highlighted some security weaknesses in Python App Engine.  What are your thoughts on his research and specifically the Python issues he highlighted?  When do you anticipate they will get fixed?<br />
</em></p>
<p>GvR: We&#8217;ve anticipated all of the possibilities raised in Justin&#8217;s talk, and took measures to protect our users. Justin highlighted weaknesses in Python, but not in App Engine. Furthermore, our security model does not rely solely upon protections within the Python interpreter; there are additional protections that these external analyses have missed.<em><br />
</em><br />
<em>cloudsecurity.org: How do you contain an attacker that exploits bugs in App Engine from exploiting the underlying OS and potentially interfering with other users processes or attacking backend systems?<br />
</em></p>
<p>GvR: You are correct that there are strong measures in place, but I&#8217;m not at liberty to discuss details.</p>
<p><em>cloudsecurity.org: Python was the first language to get the App Engine treatment, what language is next and what are some of the language specific security challenges the team has had to deal with?<br />
</em></p>
<p>GvR: Although I can&#8217;t comment on what language is next, we are working on this, and have gotten a lot of great feedback from our developers. As far as language-specific security challenges, they stemmed mostly from the complexity of the Python interpreter. We spent a lot of time auditing this, and did a great deal more than just identifying buffer overflows.  I can also add that Google is actively researching the security of interpreted languages.  Google engineers routinely contribute security fixes to open source projects, including but not limited to Python.<em><br />
</em><br />
<em>cloudsecurity.org: How does the team decide when &#8216;enough is enough&#8217; in terms of hardening the interpreter?<br />
</em> <em> </em></p>
<p>GvR: That&#8217;s not really how we approach it. We realize that security is an ongoing effort, and try to stay ahead of threats through continuous monitoring and testing.</p>
<p><em>cloudsecurity.org: Some <a style="color: #551a8b;" title="commentators" href="http://blog.ianbicking.org/2008/04/13/app-engine-and-pylons/" target="_blank">commentators</a> have suggested that perhaps the difficulty of auditing the implementation led to some modules being more heavily restricted than perhaps necessary.  What are your thoughts on that and what plans, if any, are there to bring back code objects/functions that were eliminated in the initial release?  (with the benefit of hindsight).<br />
</em> <em> </em></p>
<p>GvR: The only thing we are likely to put back is the _ast module, which was not audited based upon an underestimation of its usefulness (see my answer to question #3 above).  We will also put back some dummy functions and other objects whose absence currently prevents some popular frameworks from being loaded without modifications. For example, some harmless functionality in the imp module will come back. We&#8217;re also looking into making urllib2 work (to some extent), though that&#8217;s not really a security issue but merely a matter of API adjustment.</p>
<p><em>cloudsecurity.org: It is reported that Google encourages small groups to go off and create.  How involved were the Google security team with App Engine in terms of design and implementation review/testing?  Given the dynamics, is it possible to have a meaningful security process that shadows the development process?<br />
</em> <em> </em></p>
<p>GvR: The Google Security team is involved in everything we do. They have been extremely helpful.</p>
<p><em>cloudsecurity.org: How can people report security weaknesses they discover in App Engine?  What commitment does Google give in terms of dealing vulnerability reports?<br />
</em> <em> </em></p>
<p>GvR: There is a standard process for submitting security issues. See <a title="http://www.google.com/corporate/security.html" href="http://www.google.com/corporate/security.html" target="_blank">http://www.google.com/corporate/security.html</a>. Google moves very fast to protect its users when a verifiable security vulnerability is reported.<span><em><br />
</em></span><br />
<em>cloudsecurity.org: One concern is the potential misuse of App Engine to exploit security vulnerabilities in visitors browsers.  This is not a new problem per se, shared hosting providers know all about this.  But with Google and other Cloud providers, the scalability potential is much higher.  What are your thoughts on this and what pro-active steps is Google taking to detect and terminate evil apps?<br />
</em> <em> </em></p>
<p>GvR: This is high on our list of concerns. We deal with this through a combination of restrictions on what you can do (e.g. certain HTTP headers and ports are off-limits) and, again, monitoring.</p>
<p><em>cloudsecurity.org: Beyond App Engine, what role do you think Python will play in the Cloud both now and in the future?<br />
</em> <em> </em></p>
<p>GvR: Sorry, I&#8217;m not prone to philosophizing about the future.</p>
<p><em>cloudsecurity.org: Trust is often cited as a barrier to enterprise adoption of Cloud Computing.  What role do you personally think Google can play in building that trust?<br />
</em> <em> </em></p>
<p>GvR: I think trust is built up over a long period of experience. Our actions in terms of being open to our users will be the most important factor in establishing trust. Of course, Google&#8217;s reputation also helps: everybody understands that Google doesn&#8217;t want its name associated with a bad product.</p>
<p><em>cloudsecurity.org: Looking at the Cloud Computing landscape beyond Google, what are your thoughts on the current state of Cloud Computing and Security?<br />
</em></p>
<p>GvR: It&#8217;s obvious that Cloud Computing is only just taking off. The next few years will be very exciting.</p>
<p><em>cloudsecurity.org: Lastly, what are some of your favourite App Engine apps?<br />
</em></p>
<p>GvR: There are too many to enumerate. If you insist on a highlight, well, I like Rietveld (<a title="http://codereview.appspot.com" href="http://codereview.appspot.com/" target="_blank">http://codereview.appspot.com</a>), a tool for collaborative code review which I (largely) wrote myself. It is open source and includes some essential components from Mondrian, a similar internal tool which I created before I joined the App Engine team.</p>
<h4><strong>Thanks</strong></h4>
<p>My thanks to Guido for his time and sharing his views.</p>
<img src="http://feeds.feedburner.com/~r/CloudSecurity/~4/324271347" height="1" width="1"/>]]></content:encoded>
      <pubDate>Tue, 01 Jul 2008 15:03:10 +0000</pubDate>
      <category domain="http://securityratty.com/tag/app engine">app engine</category>
      <category domain="http://securityratty.com/tag/google app engine">google app engine</category>
      <category domain="http://securityratty.com/tag/app">app</category>
      <category domain="http://securityratty.com/tag/app engine treatment">app engine treatment</category>
      <category domain="http://securityratty.com/tag/security">security</category>
      <category domain="http://securityratty.com/tag/app engine project">app engine project</category>
      <category domain="http://securityratty.com/tag/app engine crew">app engine crew</category>
      <category domain="http://securityratty.com/tag/secure app engine">secure app engine</category>
      <category domain="http://securityratty.com/tag/security vulnerabilities">security vulnerabilities</category>
      <source url="http://feeds.feedburner.com/~r/CloudSecurity/~3/324271347/">Cloudsecurity.org Interviews Guido van Rossum: Google App Engine, Python and Security</source>
    </item>
    <item>
      <title><![CDATA[Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption]]></title>
      <link>http://securityratty.com/article/a5ef3fac42280b513c7c8d31f1a499be</link>
      <guid>http://securityratty.com/article/a5ef3fac42280b513c7c8d31f1a499be</guid>
      <description><![CDATA[New Video: Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption
Ive recently become interested in measures that modern CPUs can...]]></description>
      <content:encoded><![CDATA[<b>New Video:</b><a href="http://irongeek.com/i.php?page=videos/using-data-execution-prevention-dep-in-windows-xp-and-vista">Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption</a><br>
&nbsp;I’ve recently become interested in measures that modern CPUs can take to prevent various types of memory corruption attacks. One such feature is the NX bit (as AMD calls it, XD is Intel’s term), which allows for memory pages to me 
marked as not executable. Microsoft Windows started using this ability with XP 
SP2 as part of their Data Execution Prevention (DEP) feature. Unfortunately, to 
get most out of DEP you have to configure it. This video will show how to 
configure DEP protection in Windows XP and Vista.
<p><a href="http://feeds.feedburner.com/~a/IrongeeksSecuritySite?a=c8SqYS"><img src="http://feeds.feedburner.com/~a/IrongeeksSecuritySite?i=c8SqYS" border="0"></img></a></p><img src="http://feeds.feedburner.com/~r/IrongeeksSecuritySite/~4/307708597" height="1" width="1"/>]]></content:encoded>
      <pubDate>Sun, 08 Jun 2008 20:36:29 +0000</pubDate>
      <category domain="http://securityratty.com/tag/dep">dep</category>
      <category domain="http://securityratty.com/tag/data execution prevention">data execution prevention</category>
      <category domain="http://securityratty.com/tag/memory corruption">memory corruption</category>
      <category domain="http://securityratty.com/tag/windows">windows</category>
      <category domain="http://securityratty.com/tag/configure dep protection">configure dep protection</category>
      <category domain="http://securityratty.com/tag/configure">configure</category>
      <category domain="http://securityratty.com/tag/memory corruption attacks">memory corruption attacks</category>
      <category domain="http://securityratty.com/tag/vista">vista</category>
      <category domain="http://securityratty.com/tag/buffer overflows">buffer overflows</category>
      <source url="http://feeds.feedburner.com/~r/IrongeeksSecuritySite/~3/307708597/i.php">Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption</source>
    </item>
    <item>
      <title><![CDATA[Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption]]></title>
      <link>http://securityratty.com/article/a9a090d025173f22251ad2d7caf4ad62</link>
      <guid>http://securityratty.com/article/a9a090d025173f22251ad2d7caf4ad62</guid>
      <description><![CDATA[New Video: Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption
Iâve recently become interested in measures that modern CPUs can...]]></description>
      <content:encoded><![CDATA[<b>New Video:</b><a href="http://irongeek.com/i.php?page=videos/using-data-execution-prevention-dep-in-windows-xp-and-vista">Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption</a><br>
&nbsp;Iâve recently become interested in measures that modern CPUs can take to prevent various types of memory corruption attacks. One such feature is the NX bit (as AMD calls it, XD is Intelâs term), which allows for memory pages to me 
marked as not executable. Microsoft Windows started using this ability with XP 
SP2 as part of their Data Execution Prevention (DEP) feature. Unfortunately, to 
get most out of DEP you have to configure it. This video will show how to 
configure DEP protection in Windows XP and Vista.<img src="http://feedproxy.google.com/~r/IrongeeksSecuritySite/~4/SQcMieqywPc" height="1" width="1"/>]]></content:encoded>
      <pubDate>Sun, 08 Jun 2008 20:36:29 +0000</pubDate>
      <category domain="http://securityratty.com/tag/dep">dep</category>
      <category domain="http://securityratty.com/tag/data execution prevention">data execution prevention</category>
      <category domain="http://securityratty.com/tag/memory corruption">memory corruption</category>
      <category domain="http://securityratty.com/tag/windows">windows</category>
      <category domain="http://securityratty.com/tag/configure dep protection">configure dep protection</category>
      <category domain="http://securityratty.com/tag/configure">configure</category>
      <category domain="http://securityratty.com/tag/memory corruption attacks">memory corruption attacks</category>
      <category domain="http://securityratty.com/tag/vista">vista</category>
      <category domain="http://securityratty.com/tag/buffer overflows">buffer overflows</category>
      <source url="http://feedproxy.google.com/~r/IrongeeksSecuritySite/~3/SQcMieqywPc/i.php">Using Data Execution Prevention (DEP) in Windows XP and Vista: Fighting back against buffer overflows and memory corruption</source>
    </item>
    <item>
      <title><![CDATA[Corrupted Heap Termination Redux]]></title>
      <link>http://securityratty.com/article/a724b98a0e84d0038871d63b124215da</link>
      <guid>http://securityratty.com/article/a724b98a0e84d0038871d63b124215da</guid>
      <description><![CDATA[Hi, Michael here
In a previous post I explained how to use HeapSetInformation correctly. In short there's an option when calling this function that will terminate your application if the heap manager...]]></description>
      <content:encoded><![CDATA[<P>Hi, Michael here.</P>
<P>In a <A href="http://blogs.msdn.com/michael_howard/archive/2008/02/18/faq-about-heapsetinformation-in-windows-vista-and-heap-based-buffer-overruns.aspx">previous post</A> I explained how to use HeapSetInformation correctly. In short there's an option when calling this function that will terminate your application if the heap manager detects some form of heap corruption, or the potential to cause heap corruption.</P>
<P>I would recommend you read the previous post before continuing.</P>
<P>You guessed it, the number one email I got after this post was, "So, what sort of corruption will terminate my app?"</P>
<P>So for all those who emailed me, here's a list:</P>
<UL>
<LI>Corruption of an uncommitted range (region inside heap segments which are reserved but not committed)</LI>
<LI>Heap header corruption, for example the heap header checksum is invalid. This can be a single header, or multiple headers.</LI>
<LI>Walk of the large virtual blocks shows corruption (all blocks above about 512Kb on x86 and 1Mb on 64 bit are not allocated from segments; they are direct virtual allocations, the heap just holds a list of them along with some metadata to assure consistency with the rest of the heap. They are chained in a double linked list so corruption can be detected by walking the list.)</LI>
<LI>Buffer overrun: the next block header size does not match the expected current block size.</LI>
<LI>Buffer underrun: same as above, but the previous block header size does not match the expected current block size.</LI>
<LI>Attempting to free a free'd block (double-free bug)</LI>
<LI>Attempting to free a non 8-byte aligned block.</LI>
<LI>Passing a bogus heap handle, it could simply be an invalid heap or a handle to a different heap.</LI>
<LI>Corruption of free block list. A bit of a catch-all, including: writing after free, overrunning a previous and managing to step over the list entry. </LI></UL>
<P>But there is one huge and critically important caveat to using the defense: it only works if you use the Windows heap manager. You might be surprised to learn that many applications actually implement their own heap functionality for various reasons, often legacy reasons based on historically poor performance of operating system heap managers. A great deal of performance work was performed on the Windows Vista and Windows Server 2008 heap managers, but the work performed is way beyond the scope of this document. Another common scenario is to allocate a huge block of memory from the operating system and then perform custom allocation within that heap block. Again, if you do this, you will not get benefit from using the heap corruption termination capability and you will still be subject to repeatable heap based attacks.</P>
<P>Another down side of not using the native Windows heap manager (or if you use your own sub-allocation mechanism) is you cannot take advantage of Windows leak-detection tools because you are not using the Windows heap in the way it's meant to be used, or you're not using the Windows heap at all.</P>
<P>With all this said, I realize that moving off a custom heap to another heap is never an easy task, but if you want to take advantage of this defense, you should add "Move off our custom heap" to the list of development tasks.</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8579450" width="1" height="1">]]></content:encoded>
      <pubDate>Sat, 07 Jun 2008 00:00:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/heap">heap</category>
      <category domain="http://securityratty.com/tag/free block list">free block list</category>
      <category domain="http://securityratty.com/tag/block">block</category>
      <category domain="http://securityratty.com/tag/handle">handle</category>
      <category domain="http://securityratty.com/tag/bogus heap handle">bogus heap handle</category>
      <category domain="http://securityratty.com/tag/invalid">invalid</category>
      <category domain="http://securityratty.com/tag/invalid heap">invalid heap</category>
      <category domain="http://securityratty.com/tag/custom heap">custom heap</category>
      <category domain="http://securityratty.com/tag/block header">block header</category>
      <source url="http://blogs.msdn.com/sdl/archive/2008/06/06/corrupted-heap-termination-redux.aspx">Corrupted Heap Termination Redux</source>
    </item>
    <item>
      <title><![CDATA[Giving SQL Injection the Respect it Deserves]]></title>
      <link>http://securityratty.com/article/57d875bb80f61dde372def8fc9b27b27</link>
      <guid>http://securityratty.com/article/57d875bb80f61dde372def8fc9b27b27</guid>
      <description><![CDATA[Hello, Michael here
You may have read recently about a large number of Web servers that were compromised through a SQL injection attack. The malicious SQL payload is very well designed, somewhat...]]></description>
      <content:encoded><![CDATA[&nbsp; 
<P>Hello, Michael here...</P>
<P>You may have <A href="http://blogs.iis.net/bills/archive/2008/04/25/sql-injection-attacks-on-iis-web-servers.aspx">read</A> recently about a <A href="http://blog.washingtonpost.com/securityfix/2008/04/hundreds_of_thousands_of_micro_1.html">large number of Web servers</A> that were compromised through a SQL injection attack. The malicious SQL payload is very well designed, somewhat database schema agnostic and generic &nbsp;so it could compromise as many database servers as possible. While the attack was a SQL injection attack that attacked and compromised back-end databases courtesy of vulnerable Web pages, from a user's perspective the real attack was compromised Web pages that serve up malware to attack user's through their browsers. In essence, there were two sets of victims: the Web site operators and the users who visited the affected Web sites. In this post, I want to focus on what the first set of users, the Web site operators, can do to protect themselves.</P>
<P>The fact that the malicious payload was so generic shows that the science of SQL injection has not taken a back seat to research in other vulnerability types, such as buffer overflows or cross-site scripting issues. </P>
<P>I think the first lesson from this attack is this:</P>
<P>If you have a Web server (doesn't matter what type), and it's hooked up to a database (doesn't matter what type) you need to go in and review your code that performs the database work.</P>
<P>So now that you've determined the database access code, now what? The SDL is very specific about what do here, there are three requirements - they are requirements not recommendations, which means you must do the following coding requirements and defenses</P>
<UL>
<LI>Use SQL Parameterized Queries</LI>
<LI>Use Stored Procedures</LI>
<LI>Use SQL Execute-only Permission</LI></UL>
<H2>Use SQL Parameterized Queries</H2>
<P>From the SDL documentation: </P>
<P>"Applications accessing a database must do so only using parameterized queries.</P>
<P>Creating dynamic queries using string concatenation potentially allows an attacker to execute an arbitrary query through the application. This vulnerability allows for unauthorized, interactive, logon to a SQL server which may result in the execution of malicious commands leading to the possible modification (or deletion) of Operating System or user data. </P>
<P>Combining the use of parameterized queries and stored procedures helps to mitigate the risk of successful exploitation of user input which is not correctly verified."</P>
<P>This defense has been known about forever; heck, <A href="http://blogs.msdn.com/david_leblanc/">David</A> and I discussed this in detail in the first edition of Writing Secure Code in 2002:</P>
<P>From page 320, "Another way to perform this kind of processing is to use <I>placeholders</I> which are often referred to as <I>parameterized commands</I>."</P>
<P>Just about every database access technology supports parameterized queries; work out what they are for your DB technology and use them: the defense for a PHP/MySQL combo will not be the same as a C#/SQL Server combo.</P>
<P>The most likely cause of these recent compromises is using string concatenation to build SQL statements. Just don't do it, even if you think you're safe, just don't use string concatenation to build SQL statements! There are some very specialized cases where string concatenation is valid, but they are rare, especially for Web apps. In my opinion, any use of string concatenation in a Web application is a high-priority bug. </P>
<H2>Use Stored Procedures</H2>
<P>From the SDL documentation: </P>
<P>"Applications accessing databases should do so only using stored procedures. "</P>
<P>-and-</P>
<P>"Do not use "exec @sql" construct in your stored procedures.</P>
<P>Using stored procedures helps to mitigate the SQL injection threat to a great extent since type checking is available for parameters. If the attacker supplies input that does not match the type constraints the stored procedures will throw an exception. In the vast majority of the cases, this should be properly handled within the application. </P>
<P>However, if the stored procedures perform string manipulation in their code and then execute that query using the "exec @sql" construct incorrect handling of user input can produce the same SQL injection vulnerability as would be seen at the application layer."</P>
<P>Note the words "help mitigate," by themselves stored procedures do not remove SQL injection vulnerabilities; they just raise the bar on the attacker by hiding much of the underlying database schema from the attacker.</P>
<H2>Use SQL Execute-only Permission</H2>
<P>This next defense is interesting in that it is a defense in depth method; in this case it assumes the attacker has successfully found a SQL injection bug in your code. Now what? Thankfully, this defense will stop most every attack dead in its tracks.</P>
<P>From the SDL documentation:</P>
<P>&nbsp;"Only grant ‘execute' permission on all stored procedures, and grant that permission only for the application domain group. </P>
<P>Ensure that this group is granted execute permissions only on your stored procedures. Do not grant any other permission on your database to any other user or group."</P>
<P>This is a great defense, because if the attacker attempts to access any other database object other than through a stored procedure (you can use views also), the underlying database permissions model prevents the attack by denying access to the attacker.</P>
<P>It's interesting that the SDL offers three SQL injection requirements; only one actually remedies the problem (secure by design) and the other two offer mores defenses assuming failure (secure by default.)</P>
<P>Of course, a simple set of rules is not a substitute for careful design, implementation, and test. The SDL is a holistic process that covers the software lifecycle end-to-end, so don't mistake these simple rules as a guarantee that you will avoid SQL injection problems. You need to understand the situations in which the rules apply. You may find, for example, that string concatenation is the best - or perhaps only - solution to a particular problem and these rules may not guard against SQL injection in those situations. Follow secure development practice throughout the lifecycle of your project - including things we left out of this blog, like testing and security response, for best results.</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8508828" width="1" height="1">]]></content:encoded>
      <pubDate>Thu, 15 May 2008 14:45:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/sql">sql</category>
      <category domain="http://securityratty.com/tag/sql injection bug">sql injection bug</category>
      <category domain="http://securityratty.com/tag/sql injection requirements">sql injection requirements</category>
      <category domain="http://securityratty.com/tag/sql injection attack">sql injection attack</category>
      <category domain="http://securityratty.com/tag/sql server">sql server</category>
      <category domain="http://securityratty.com/tag/sql execute-only permission">sql execute-only permission</category>
      <category domain="http://securityratty.com/tag/malicious sql payload">malicious sql payload</category>
      <category domain="http://securityratty.com/tag/sql injection">sql injection</category>
      <category domain="http://securityratty.com/tag/sql injection vulnerability">sql injection vulnerability</category>
      <source url="http://blogs.msdn.com/sdl/archive/2008/05/15/giving-sql-injection-the-respect-it-deserves.aspx">Giving SQL Injection the Respect it Deserves</source>
    </item>
  </channel>
</rss>
