Updating a .netcore Website’s Security Headers
Tags: applicationsecurity, dotnetcore, owasp
Published: 2018-12-07 15:09:01

---
title: Updating a .netcore Website’s Security Headers
published: true
tags: application-security,dotnet-core,owasp
canonical_url: https://medium.com/@kritner/updating-a-netcore-websites-security-headers-140266520c0
---

### Updating a .netcore Website’s Security Headers

GaProgMan tweeted recently about his A+ rating on securityHeaders.com. Checking my site, I could see there was room for improvement!

The original tweet:

{% tweet 1067344351947309057 %}

I checked kritner.com and didn’t do so well. Let’s see about changing that!

Website security — We did the whole A+ on ssllabs thing:

[Going from an “A” to an “A+” on ssllabs.com](https://dev.to/kritner/going-from-an-a-to-an-a-on-ssllabscom-3pda)

But what about having a secure site from the headers point of view? Let’s get going!

#### What are security headers, and what problem do they solve?

Owasp is a great resource when it comes to helping keep your application secure:

[OWASP Secure Headers Project - OWASP](https://www.owasp.org/index.php/OWASP_Secure_Headers_Project)

The OWASP site goes into great detail about the top security vulnerabilities, how to prevent them, and how to secure your site through various different potential attack vectors. Right now, we’re concentrating on security headers.

The TLDR of utilizing security headers is to set up an agreement between client and server between what is, and what isn’t allowed when connected to each other. Ensuring we’re communicating over HTTPS, not allowing the site to be loaded within an iframe, and preventing cross site scripting, are some examples of the problems appropriate security headers can help solve.

#### Baseline of kritner.com

Just to get a baseline of what I’ll be dealing with on kritner.com — from [securityheaders.com](https://www.securityheaders.com):

![](https://cdn-images-1.medium.com/max/1024/1*oGfUiEhBFyOLlPCXxdAZ-w.png)

![](https://cdn-images-1.medium.com/max/1024/1*pmRv7BUE1VFMlTKs0j9dxA.png)

The above gives a nice breakdown of the rating, and information on the missing pieces of information.

#### What we can do to improve it

Luckily for us GaProgman (the author of the tweet that spawned this post) has put together an OWasp secure header NuGet package, which I think will get my site most of the way there.

[OwaspHeaders.Core 3.3.2](https://www.nuget.org/packages/OwaspHeaders.Core/)

Jamie advised me to read the documentation first, so I suppose I should :)

{% tweet 1067522245558525955 %}

Ok, I read it, did you?

Let’s install this bad boy!

```cmd
add package OwaspHeaders.Core
```

![](https://cdn-images-1.medium.com/max/1024/1*Vsi95AwFOMjA_-5wA2SPrQ.png)

and I’ll go with the default builder as specified from the [readme](https://github.com/GaProgMan/OwaspHeaders.Core/blob/master/README.md), just to see where that gets me.

Within `Startup.Configure()`

```cs
app.UseSecureHeadersMiddleware(SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration());
```

Now all that’s left to do is build this thing and test it out! Note, I am using docker, kestrel, and nginx for building and serving my website, so I wasn’t quite sure if this would work without tweaks; thankfully, it did!

I just needed to:

- Rebuild my docker image (Note to self — this dockerfile is too big… I need to refactor it)
- Push image to docker hub
- SSH into server, pull image, restart services
- Hope for the best

After doing all that, and testing my site again, I am presented with:

![](https://cdn-images-1.medium.com/max/1024/1*nnqnoL9ViTuktP4f1LleiA.png)

Well, I don’t know what else to say. It’s super simple, and almost out of the box, to get your website into a more secure state. Now we’ve ensured kritner.com is secure through its SSL/TLS, and its security headers!

#### Related

- [Security Headers](https://www.securityheaders.com) — test your website’s security headers!
- [OWasp Headers Core](https://www.nuget.org/packages/OwaspHeaders.Core/) — NuGet package by [GaProgman](https://dotnetcore.gaprogman.com/)
- [OWasp Headers Core ](https://github.com/GaProgMan/OwaspHeaders.Core)— GitHub repo
- [Going from an A to an A+ on SSLLabs.com](https://medium.com/@kritner/going-from-an-a-to-an-a-on-ssllabs-com-570d2e245100?source=friends_link&sk=54451e8847a0162f28349b43595e4efc)