Interesting Links – Stuff Andy read while waiting for downloads

My interesting links email is something I send out to my colleagues, well, when I’ve found stuff of interest. This one is quite old (December 2015).

Idle thought for the day – should we include in our sites/pages details of ‘how to contact us if you find a vulnerability’?


Interesting Links – Stuff Andy read while waiting for downloads

Secure your Sitecore Cookies

So a Sitecore site I’ve been working on recently underwent a penetration test, which turned up an interesting item. The ASP.NET_SessionId and SC_ANALYTICS_GLOBAL_COOKIE cookies aren’t set with the ‘Secure’ flag.  Further, my own checking showed that the .ASPXAUTH token was also set without the ‘Secure’ flag.

As the entire site is only served over HTTPS, this seems to be a bit remiss.

Fortunately, there are a couple of easy fixes to this that can be set in the Web.config

Under <System.Web> and <httpCookies> set requireSSL:

<httpCookies requireSSL="true" />

And in <forms> set requireSSL too.

<forms name=".ASPXAUTH" cookieless="UseCookies" requireSSL="true" />

This latter one is needed for the .ASPXAUTH cookie, but that seems to do it.

Don’t forget to set the HTTPOnly flag as appropriate for your cookies too!

Secure your Sitecore Cookies

IIS Redirect HTTP to HTTPS

Just a quick note – if you want to use an IIS rule to redirect users from HTTP to HTTPS, the following rule seems to work pretty well. You’ll need the IIS URL Rewrite module installed.

<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<add input="{HTTPS}" pattern="^OFF$" />
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />


IIS Redirect HTTP to HTTPS

Is reading the web config faster than Sitecore’s Cache?

Okay, I’ll admit, I felt I knew the answer to this – but after my work with the CustomCache object, I felt that this was an interesting experiment.

If I just need to read string, is it faster to read from the configuration file with Sitecore.Configuration.Settings.GetSetting() or using the cache?

Well, the short answer is that the file is roughly twice as fast. Good, no cache needed! Continue reading “Is reading the web config faster than Sitecore’s Cache?”

Is reading the web config faster than Sitecore’s Cache?

Adding a button to the User Manager

A quick shout out to this page – Adding Options to Sitecore Applications by Alistair Deneys . It’s a nice guide about how to do exactly that – add options to the menus in Sitecore. It was pretty straight forward to do for the User Manager:

  • Add an entry in the Core database to represent the button
  • Add a patch file that defines your command and what class it should call
  • Add a class file that defines the command in a child of Sitecore.Shell.Framework.Commands.Command . Override and implement Execute

The parameters to the Execute method contains which usernames have been selected. This is as a pipe separated list:

public override void Execute(CommandContext context)
string usernamesParameter = context.Parameters["username"];
string[] usernames = null;
if (!string.IsNullOrEmpty(usernamesParameter))
char[] splitter = {'|' };
usernames = usernamesParameter.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

That might help.

Adding a button to the User Manager

Awkward Page Request Validation in Sitecore

I was configuring a new Sitecore 8.1 instance. It’s a vanilla, straight-off-the-installer instance, and yet I noticed that the node’s request validation was off:

<pages validateRequest="false">

This did, at least, come with a comment above it:

If requestValidationMode attribute of httRuntime node is set to 2.0, Sitecore requires this setting to be set to “false” for Sitecore client to work and it shouldn’t be changed. You can however set ValidateRequest attribute in the @Page directive to “true” for your layout .aspx files.

This is bonkers. The default configuration for this site is to remove request validation on my brand new Sitecore instance on the off-chance I should want to configure it to use an older, non-default requestValidationMode. Instead, I should stumble across this comment in the web.config file and add the appropriate attribute to all the layouts of my solution. And someone thought that this was a good idea?

Even if I were upgrading and I did rely on the httpRuntime requestValidationMode being 2.0, I would prefer that this was set to true, with instructions for how I should handle it in the case of an upgrade.

Crazy. One to be aware of.

Awkward Page Request Validation in Sitecore