<?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/"><channel><title>Reflection for tag .net</title><link>http://blog.bigfinger.se</link><pubDate>2012-02-07T23:01:29</pubDate><generator>umbraco</generator><description>Thoughts on life: Umbraco, EPiServer, .NET and Fatherhood.</description><language>en</language><copyright>Copyright 2009-2012 Stephan Kvart</copyright><webMaster>stephan@bigfinger.se</webMaster><item><title>Available for hire from April 1st</title><link>http://blog.bigfinger.se/2010/2/12/available-for-hire-from-april-1st.aspx</link><pubDate>Fri, 12 Feb 2010 20:16:19 GMT</pubDate><guid>http://blog.bigfinger.se/2010/2/12/available-for-hire-from-april-1st.aspx</guid><description>
Today it became finalized that I will be available for hire from
April 1st and on, since Milagro chose not to extend my contract. It
has nothing to do with my skills, but is rather an economic
issue.

Sad as it may be, it leaves me available for hire, to do Umbraco
or EPiServer work, wherever I may be needed. I have several years
experience, and am certified, on both platforms. I work well in
teams, and solo, and you're really missing out if you don't hire
me. If needed, I'll travel for star...</description><content:encoded><![CDATA[ 
<p>Today it became finalized that I will be available for hire from
April 1st and on, since Milagro chose not to extend my contract. It
has nothing to do with my skills, but is rather an economic
issue.</p>

<p>Sad as it may be, it leaves me available for hire, to do Umbraco
or EPiServer work, wherever I may be needed. I have several years
experience, and am certified, on both platforms. I work well in
teams, and solo, and you're really missing out if you don't hire
me. If needed, I'll travel for start up meetings etc. So don't
hesitate just because I'm Swedish. I'm that good.</p>

<p>There's an online resume-ish site <a href="http://bigfinger.se"
target="_blank"
title="Big Finger - Web Development made right.">here</a>. And I'll
even send you a PDF with more info, if you still have doubts.</p>

<p>I know, cheap trick, but I have a family to support. :)</p>
]]></content:encoded></item><item><title>Notes from the EPiServer Meetup in Stockholm.</title><link>http://blog.bigfinger.se/2010/1/26/notes-from-the-episerver-meetup-in-stockholm.aspx</link><pubDate>Tue, 26 Jan 2010 09:37:28 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/26/notes-from-the-episerver-meetup-in-stockholm.aspx</guid><description>
Yesterday I was at the EPiServer Meetup, which was kindly hosted
by KnowIT. It started off with a VERY interesting talk on XSS/CSRF.
After a short break with thai food, there was a presentation on
developing EPiServer templates that validate and are SEO
friendly.

I'm not going to cover the validation/SEO friendlyness here, not
because I believe that what they said was bullcrap, but rather
because I believe that their approach doesn't give the client the
freedom of choice I think goes hand-i...</description><content:encoded><![CDATA[ 
<p>Yesterday I was at the EPiServer Meetup, which was kindly hosted
by KnowIT. It started off with a VERY interesting talk on XSS/CSRF.
After a short break with thai food, there was a presentation on
developing EPiServer templates that validate and are SEO
friendly.</p>

<p>I'm not going to cover the validation/SEO friendlyness here, not
because I believe that what they said was bullcrap, but rather
because I believe that their approach doesn't give the client the
freedom of choice I think goes hand-in-hand with using a large
scale CMS like EPiServer. When a client uses EPiServer, and tires
of their development partner, they should be able to switch
over-night. Furthermore, development time is, and this is only my
personal oppinion, increased, since developers have to build their
own post-back mechanisms. But enough on that, what they said mostly
made sense :).</p>

<p>XSS, or Cross-Site-Scripting, is when someone injects HTML or a
script, into a site. There are two different kinds,
Non-persistent/Reflected or Persisted/Stored.</p>

<p>The Reflected approach is when someone exploits a XSS
vulnerability, for example, modifies a querystring parameter so
that html and/or javascript is rendered directly onto the page.
They then spread a link to their modified URL, and anyone logging
on there might be subjected to some form of fraud or some other
malignant attempt at their data.</p>

<p>The Stored approach is when someone submits, for instance to a
forum or blog comment, html and/or javascript that is then stored
on the page for other visitors to be subjected to. Like as if a
blog comment here would contain html and javascript that would
render a login form on every page, but when fileld out, would send
that data to a third party. In short, it would suck. Big time.</p>

<p>Now, how to protect yourself?</p>

<p>In short: Don't allow HTML being posted to your forms. Oh, and
check for scripts too.</p>

<p>OK. But that won't always do. I know, so here's a few more
lengthy pointers.</p>

<ol>
<li>Enable validateRequest in web.config in system.web/pages - if
this isn't an option for you, i.e. EPiServer's editor won't work,
consider using it in combination with your &lt;location&gt;
segments, only disabling it where absolutely needed.</li>

<li>Clean your output. HTML-Encode any input sent from the user, or
use RegEx to clean those tags/attributes that can cause harm. For
me anyway, RegEx is awesome, but I can NEVER seem to learn
them.</li>

<li>Implement <a
href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;displaylang=en"
 target="_blank"
title="Microsoft Anti-Cross Site Scripting Library V3.1">The
Microsoft Anti-Cross Site Scripting Library</a></li>

<li>Evaluate your content, and look for vulnerabilites.
Repeatedly.</li>
</ol>

<p>Here are some useful links for those that want to know more.</p>

<ul>
<li><a
href="http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet"
 target="_blank"
title="XSS (Cross Site Scripting) Prevention Cheat Sheet">XSS
Prevention Cheat Sheet</a></li>

<li><a href="http://labs.securitycompass.com/index.php/exploit-me/"
target="_blank"
title="Explot-Me, XSS-Me, SQL-Inject-Me, Access-Me">Security
Compass Exploit-Me Firefox Add-On</a></li>

<li><a href="http://en.wikipedia.org/wiki/Cross-site_scripting"
target="_blank" title="Cross-site scripting">XSS on
Wikipedia</a></li>

<li><a
href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;displaylang=en"
 target="_blank"
title="Microsoft Anti-Cross Site Scripting Library V3.1">The
Microsoft Anti-Cross Site Scripting Library</a></li>
</ul>

<p>&nbsp;</p>

<p>So, what then is that other abbreviation, CSRF? CSRF, or
Cross-Site Request Forgery, is when a malignant website uses valid
data from your browser, like hi-jacking a validation cookie, and
sends a request with that valid data, in your name. This was a
wake-up call for me.</p>

<p>A possible scenario is, when you're out in your sunday best,
couch-surfing. You check your mail at Gmail in one tab, and doing
some "grown-up's surfing" in another tab. Your browser then has an
authorization cookie for Gmail, certifying that you're logged in,
and everything is A-OK. The grown-up-site you're watching has some
malicious code on it, that tries to send data to Gmail behind your
back, and since your browser is authorized, Gmail accepts that
incoming request, forged as it may be.</p>

<p>Working around this can be a hassle, but it isn't impossible,
here are a few tips.</p>

<ol>
<li><a href="http://anticsrf.codeplex.com/" target="_blank"
title="AntiCSRF - A Cross Site Request Forgery (CSRF) module for ASP.NET">
Implement an ANTI-CSRF HttpModule.</a></li>

<li>Check the referrer header, and make sure it's your site making
the request. It can be found in
HttpContext.Request.UrlReferrer.</li>

<li>Make sure that any crossdomain.xml doesn't allow everything.
This is a Flash thing, so if you don't have any Flash on your site,
you don't need to bother.</li>

<li>Limit the lifetime of authentication cookies.</li>

<li>If you're using <a href="http://www.asp.net/mvc/"
target="_blank" title="ASP.NET MVC">ASP.NET MVC</a>, use the
Html.AntiForgeryToken() helper in conjuction with the
[ValidateAntiForgeryToken] attribute on your post method.</li>
</ol>

<p>Here are some useful links for those that want to know more.</p>

<ul>
<li><a href="http://www.owasp.org/index.php/.Net_CSRF_Guard"
target="_blank" title=".NET CSRF Guard">.NET CSRF Guard</a></li>

<li><a href="http://en.wikipedia.org/wiki/CSRF" target="_blank"
title="Cross-site request forgery">CSRF on Wikipedia</a></li>
</ul>

<p>&nbsp;</p>

<p>I'll be testing Umbraco in general, and the Blog4Umbraco package
specifically, for XSS vulnerabilites in the next few days, I'll
keep you posted.</p>

<p>Finally, thanks to&nbsp;<a
href="http://concreteit.se/Blogg/Sakerhet/author/Sergio.aspx"
target="_blank"
title="Sergio Molero's posts at Concrete IT's Blog [SE]">Sergio
Molero</a> at&nbsp;<a href="http://concreteit.se/" target="_blank"
title="Concrete IT">Concrete IT</a> for an excellent
presentation.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 4 - To hell and back. Deserializing my baby.</title><link>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-4-to-hell-and-back-deserializing-my-baby.aspx</link><pubDate>Thu, 14 Jan 2010 15:06:17 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-4-to-hell-and-back-deserializing-my-baby.aspx</guid><description>
How to enforce that initialization is done properly once
the object has been de-serialized?

So far so good. But as with all serializable objects, they need
to have a default (parameterless) constructor. And I want my
objects to behave, remember?

Enter another useful attribute. OnDeserialized.

[Serializable]
 [DataContract(IsReference = true)]
 public abstract class Element {
 ...
 [OnDeserialized]
 private void OnDeserialized(StreamingContext context) {
 if (this.Children ...</description><content:encoded><![CDATA[ 
<p><strong>How to enforce that initialization is done properly once
the object has been de-serialized?</strong></p>

<p>So far so good. But as with all serializable objects, they need
to have a default (parameterless) constructor. And I want my
objects to behave, remember?</p>

<p>Enter another useful attribute. <a
href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx"
 target="_blank">OnDeserialized</a>.</p>

<p>[Serializable]<br />
 [DataContract(IsReference = true)]<br />
 public abstract class Element {<br />
 ...<br />
 [OnDeserialized]<br />
 private void OnDeserialized(StreamingContext context) {<br />
 if (this.Children == null) { this.Children = new
ElementList(this); }<br />
 //Make sure that any new child added gets a correct reference to
its parent.<br />
 if ( this.Children.Element == null) { this.Children.Element =
this; }<br />
 //Make sure that all children have correct parental
references.<br />
 foreach (Element e in this.Children) { e.Parent = this; }<br />
 }<br />
 ...<br />
 }</p>

<p>This will be executed every time my object has been
de-serialized, enforcing my constructor logic.</p>

<p>Now, as far as I'm concerned, that's behaving.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 3 - Serializing the hell out my object.</title><link>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-3-serializing-the-hell-out-my-object.aspx</link><pubDate>Thu, 14 Jan 2010 15:01:07 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-3-serializing-the-hell-out-my-object.aspx</guid><description>
How to make sure that my object can be serialized in an
orderly fashion?

Making sure that my object kan be serialized is simple, we just
add the [Serializable] attribute to it.

[Serializable]
 public abstract class Element {
 ...
 }

However, since my object has a reference to its Parent object,
serializing it will most likely result in a cyclic, never ending,
recursion. Fail.

Enter the DataContract.

[Serializable]
 [DataContract(IsReference = true)]
 public abstract ...</description><content:encoded><![CDATA[ 
<p><strong>How to make sure that my object can be serialized in an
orderly fashion?</strong></p>

<p>Making sure that my object kan be serialized is simple, we just
add the [Serializable] attribute to it.</p>

<p>[Serializable]<br />
 public abstract class Element {<br />
 ...<br />
 }</p>

<p>However, since my object has a reference to its Parent object,
serializing it will most likely result in a cyclic, never ending,
recursion. Fail.</p>

<p>Enter the <a
href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"
 target="_blank">DataContract</a>.</p>

<p>[Serializable]<br />
 [DataContract(IsReference = true)]<br />
 public abstract class Element {<br />
 ...<br />
 }</p>

<p>By applying it to my class, it enables serialization and
deserialization with, for instance, the DataContractSerializer. I
simply apply the [DataMember] attributes to all members I want to
serialize, and voilá, I get a nice and clean, reference enabled,
serialization.</p>

<p>But, you might ask, how does this work with the fancy List
implementation we did?</p>

<p>Simple, there's a [CollectionDataContract] attribute available
for that. That ensures that my List gets serialized to exactly
that, and not a stupid array.</p>

<p>Next up: What happens on deserialization.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 2 - Setting the parent reference.</title><link>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-2-setting-the-parent-reference.aspx</link><pubDate>Thu, 14 Jan 2010 08:16:01 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-2-setting-the-parent-reference.aspx</guid><description>
How to make sure that any objects added to the Children
property, gets a correct reference to the parent object
(this)?

Attempt 1: Adding Add and Insert methods to the
Element

public abstract class Element {
 public Element() {
 this.Children = new List&amp;lt;Element&amp;gt;();
 }
 public int ID { get; protected set; }
 public string Name { get; protected set; }
 public virtual Element Parent { get; internal set; }
 public virtual List&amp;lt;Element&amp;gt; Children { get; private set;
}...</description><content:encoded><![CDATA[ 
<p><strong>How to make sure that any objects added to the Children
property, gets a correct reference to the parent object
(this)?</strong></p>

<p><em>Attempt 1: Adding Add and Insert methods to the
Element</em></p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new List&lt;Element&gt;();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual List&lt;Element&gt; Children { get; private set;
}<br />
 public string Instructions { get; set; }<br />
<br />
 public void Add(Element item){<br />
 item.Parent = this;<br />
 this.Children.Add(item);<br />
 }<br />
 ...<br />
 }</p>

<p>This solution works all-right for many cases, however, it
doesn't solve the issue when the Add method is used on the
List&lt;Element&gt; directly. We'll want this.</p>

<p><em>Attempt 2: Changing the List type</em></p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new ElementList();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual ElementList Children { get; private set; }<br />
 public string Instructions { get; set; }<br />
 }</p>

<p>public class ElementList : List&lt;Element&gt; {<br />
 public Element Element { get; internal set; }<br />
 public ElementList(Element element) {<br />
 if (element != null){ this.Element = element; }<br />
 else { throw new ArgumentNullException("element"); }<br />
 }<br />
 new public void Add(Element item) {<br />
 if ( item.Parent == null) { item.Parent = Element; }<br />
 base.Add(item);<br />
 }<br />
 new public void Insert(int index, Element item) {<br />
 if (item.Parent == null) { item.Parent = Element; }<br />
 base.Insert(index, item);<br />
 }<br />
 new public void InsertRange(int index, IEnumerable&lt;Element&gt;
collection){<br />
 foreach (Element e in collection){<br />
 if (e.Parent == null) { e.Parent = Element; }<br />
 }<br />
 base.InsertRange(index, collection);<br />
 }<br />
 new public void AddRange(IEnumerable&lt;Element&gt; collection)
{<br />
 foreach (Element e in collection) {<br />
 if (e.Parent == null) { e.Parent = Element; }<br />
 }<br />
 base.AddRange(collection);<br />
 }<br />
 }</p>

<p>This solution ensures that all Elements added to an ElementList,
gets their Parent property re-set to reference the ElementLists
Element property. This way, one can always assume that an Element's
Children, always have their Parent references set.</p>

<p>Next up: Serialization.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 1 - The scenario.</title><link>http://blog.bigfinger.se/2010/1/13/making-objects-behave-across-a-client-server-relationship-part-1-the-scenario.aspx</link><pubDate>Wed, 13 Jan 2010 22:47:19 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/13/making-objects-behave-across-a-client-server-relationship-part-1-the-scenario.aspx</guid><description>
Ok, so here's the scenario. I have a set of objects, which all
inherit from Element (shown below). I need these objects to behave
properly when transferred across a web service, and more
importantly, when they return. One assumption I want to be able to
make, is that any Element contained in the Children property,
should have its Parent property set to the containing object, so
it's a node-like structure. Furthermore, I need my non-default
constructor logic to apply, to de-serialized...</description><content:encoded><![CDATA[ 
<p>Ok, so here's the scenario. I have a set of objects, which all
inherit from Element (shown below). I need these objects to behave
properly when transferred across a web service, and more
importantly, when they return. One assumption I want to be able to
make, is that any Element contained in the Children property,
should have its Parent property set to the containing object, so
it's a node-like structure. Furthermore, I need my non-default
constructor logic to apply, to de-serialized objects, as if they
were initialized with my parameterized constructor.</p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new List&lt;Element&gt;();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual List&lt;Element&gt; Children { get; private set;
}<br />
 public string Instructions { get; set; }<br />
 }</p>

<p><strong>The problems:</strong></p>

<p>How to make sure that any objects added to the Children
property, gets a correct reference to the parent object (this)?</p>

<p>How to make sure that my object can be serialized in an orderly
fashion?</p>

<p>How to enforce that initialization is done properly once the
object has been de-serialized?</p>

<p>&nbsp;</p>
]]></content:encoded></item></channel></rss>

