<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Just Another Web Application : security</title><link>http://blogs.technet.com/jasbro/archive/tags/security/default.aspx</link><description>Tags: security</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Blogging catchup and mailbox spring clean</title><link>http://blogs.technet.com/jasbro/archive/2008/03/07/blogging-catchup-and-mailbox-spring-clean.aspx</link><pubDate>Fri, 07 Mar 2008 03:50:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2971386</guid><dc:creator>jasbro</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/jasbro/comments/2971386.aspx</comments><wfw:commentRss>http://blogs.technet.com/jasbro/commentrss.aspx?PostID=2971386</wfw:commentRss><description>&lt;P&gt;Having recently spent some time in India attending training on &lt;A class="" title="Search Server 2008" href="http://www.microsoft.com/enterprisesearch/serverproducts/searchserver/default.aspx" mce_href="http://www.microsoft.com/enterprisesearch/serverproducts/searchserver/default.aspx"&gt;Microsoft Search Server 2008&lt;/A&gt;, and having been quite sick as a result, I've got a bit of a backlog of SharePoint blogging to catch up with. First of all, to comment on Search Server: This is a &lt;EM&gt;great&lt;/EM&gt; product. It significantly builds on the&amp;nbsp;search already offered by WSS and MOSS, streamlines the admin and search&amp;nbsp;interface, adds Ajax functionality and Federation, and comes in a free Express&amp;nbsp;flavour to boot. This is a new, standalone&amp;nbsp;product, but you could potentially&amp;nbsp;also&amp;nbsp;look on it as an expansion/update for your current WSS 3.0&amp;nbsp;installation. An update for MOSS adding this functionality will be available on a provisional timeframe of mid-2008 (calendar).&lt;/P&gt;
&lt;P&gt;MOSS administrators, you may be aware that SQL Database maintenance can be the &lt;A class="" title="You experience issues with portal alerts in SharePoint Portal Server 2003 or with search performance in SharePoint Server 2007 after you create SQL Server 2005 maintenance plans" href="http://support.microsoft.com/kb/930887" mce_href="http://support.microsoft.com/kb/930887"&gt;bane of your existence&lt;/A&gt;, as well as being something of a dark art with documentation having been thin on the ground. The good news is that there is now a whitepaper covering all aspects of DB maintenance for SharePoint. &lt;A class="" title="Database Maintenance for Sharepoint whitepaper" href="http://go.microsoft.com/fwlink/?LinkId=111531&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkId=111531&amp;amp;clcid=0x409"&gt;Download it here&lt;/A&gt; and get cracking on supported database maintenance scenarios.&lt;/P&gt;
&lt;P&gt;Securing MOSS is a large topic deserving of more than just a throwaway line on a blog, so I intend to develop some content on the subject in the coming weeks, as workload allows. For now, here's the &lt;A class="" title="MOSS Security" href="http://technet.microsoft.com/en-us/library/cc263518.aspx" mce_href="http://technet.microsoft.com/en-us/library/cc263518.aspx"&gt;Roadmap to Security Content for Office Sharepoint Server 2003&lt;/A&gt;, which should be on any admin's bookmark list.&lt;/P&gt;
&lt;P&gt;Unfortunately, I'm short on time to post much more than this for now, but expect more in the near future...&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2971386" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/jasbro/archive/tags/sharepoint/default.aspx">sharepoint</category><category domain="http://blogs.technet.com/jasbro/archive/tags/security/default.aspx">security</category><category domain="http://blogs.technet.com/jasbro/archive/tags/search/default.aspx">search</category></item><item><title>SPSecurity.RunWithElevatedPrivileges()</title><link>http://blogs.technet.com/jasbro/archive/2007/12/12/spsecurity-runwithelevatedprivileges.aspx</link><pubDate>Wed, 12 Dec 2007 03:09:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2636833</guid><dc:creator>jasbro</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/jasbro/comments/2636833.aspx</comments><wfw:commentRss>http://blogs.technet.com/jasbro/commentrss.aspx?PostID=2636833</wfw:commentRss><description>&lt;P&gt;The subject of today's post: running code in sharepoint with elevated rights, an operation sometimes required, sometimes abused and often misunderstood.&lt;/P&gt;
&lt;P&gt;The WSS Object Model provides a huge number of classes, some of which can carry-out potentially dodgy actions, so require elevation to run. Ordinarily you'd just deal with this by logging in as a user with rights to carry out the operation, but occasionally this isn't practical or possible, and that's where today's subject comes in.&lt;/P&gt;
&lt;P&gt;Let's say, just as an example, you're creating an anonymously-accessible site. In a Control on on of the pages you want to enumerate subsites of your site, and grab some properties thereof, maybe for display, maybe for some other operation in your code - however, this isn't something an anonymous identity can do.&lt;/P&gt;
&lt;P&gt;In steps our hero - RunWithElevatedPrivileges()&lt;/P&gt;
&lt;P&gt;Used correctly, this method allows a specified block of code to run in the context of the SharePoint System Account, a powerful method with much potential. Here's the summary &lt;A class="" title="SDK Reference to SPSecurity.RunWithElevatedPrivileges()" href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx"&gt;from the SDK&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;CODE&gt;
&lt;DIV class=CodeDisplayLanguage&gt;[SharePointPermissionAttribute(SecurityAction.Demand, Impersonate=&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)] &lt;BR&gt;[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel=&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)] &lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; RunWithElevatedPrivileges (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeToRunElevated secureCode&lt;BR&gt;)&lt;/DIV&gt;&lt;/CODE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;Now the CodeToRunElevated parameter can be a reference to a void, parameterless method or an anonymous method via&amp;nbsp;delegate() - please, follow the SDK link if that's unclear.&lt;/P&gt;
&lt;P&gt;Pretty simple, huh? Yep, well as always there's a catch or two.&lt;/P&gt;
&lt;P&gt;1. If you're manipulating any Object Model elements within your elevated method, you need to get a fresh&amp;nbsp;SPSite reference inside this call. For example&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;CODE&gt;SPSecurity.RunWithElevatedPrivileges(delegate(){&lt;BR&gt;&amp;nbsp;&amp;nbsp; SPSite mySite = new SPSite(&lt;A href="http://sharepoint/"&gt;http://sharepoint/&lt;/A&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp; SPWeb myWeb = SPSite.OpenWeb();&lt;BR&gt;&amp;nbsp;&amp;nbsp; // further implementation omitted&lt;BR&gt;});&lt;/CODE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;2. You can't just use &lt;CODE&gt;SPContext.Current.Site&lt;/CODE&gt; to get your SPSite reference - or you'll ber handed the object with the security context of the anonymous (or non-elevated)&amp;nbsp;user and &lt;EM&gt;your elevation will not work as expected&lt;/EM&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;3. If you need to Update() anything inside this block, you'll need to call SPSite.AllowUnsafeUpdates() on your new site reference (or web reference) &lt;A class="" title="AllowUnsafeUpdates in the SDK" href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsite.allowunsafeupdates.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsite.allowunsafeupdates.aspx"&gt;as per this SDK entry&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;So those are the gotchas. Following those we have the obvious security warnings - be careful what you do within this call, as the system identity has full control over SharePoint and could do Very Bad Things if incorrectly used. Sanitise any user input very carefully if you're going to let it anywhere near this method - you certainly&amp;nbsp;don't want a user finding some injectable exploit into this code. Exercise caution over what you do, for this power must be used wisely. But you knew that, right?&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2636833" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/jasbro/archive/tags/sharepoint/default.aspx">sharepoint</category><category domain="http://blogs.technet.com/jasbro/archive/tags/sdk/default.aspx">sdk</category><category domain="http://blogs.technet.com/jasbro/archive/tags/security/default.aspx">security</category><category domain="http://blogs.technet.com/jasbro/archive/tags/elevated/default.aspx">elevated</category></item></channel></rss>