Giter VIP home page Giter VIP logo

owin.hsts's Introduction

Owin.Hsts

According to OWASP, HTTP Strict Transport Security (HSTS) protects users from a number of threats, in particular man-in-the-middle attacks by not only forcing encrypted sessions, but also stopping attackers who use invalid digital certificates.

HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS. It also prevents HTTPS click through prompts on browsers.

The specification has been released and published end of 2012 as RFC 6797 (HTTP Strict Transport Security (HSTS)) by the IETF

*source

This package aims to provide developers the middleware required to effectively support this specification in a standardised way.

To install the package, search NuGet for Owin.Hsts or run the following command from the package console:

Install-Package Owin.HSTS

Then open Startup.cs and add the following:

using Owin.Hsts; // Add this at the top

app.UseHttpStrictTransportSecurity();

Which will result in a similar configuration to the following:

using Microsoft.Owin;
using Owin;
using Owin.Hsts;

[assembly: OwinStartupAttribute(typeof(MyWebApp.Startup))]
namespace MyWebApp
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseHttpStrictTransportSecurity();

            ConfigureAuth(app);
        }
    }
}

The following options are set by default:

  • All sub-domains are included (HSTS specification dictates an all or none approach)
  • The policy expires after 28 days
  • The middleware will not overwrite any header that is already set by the application

In order to override any of the above settings use the additional overload as demonstrated below:

using System;
using Microsoft.Owin;
using Owin;
using Owin.Hsts;

[assembly: OwinStartupAttribute(typeof(MyWebApp.Startup))]
namespace MyWebApp
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseHttpStrictTransportSecurity(new HstsSettings
                                               {
                                                   Duration = TimeSpan.FromDays(365d),
                                                   IncludeSubDomains = false,
                                                   OverwriteExisting = true
                                               });

            ConfigureAuth(app);
        }
    }
}

For browser compatibility with HSTS, check caniuse.com

owin.hsts's People

Contributors

estei avatar mthamil avatar

Watchers

 avatar

Forkers

jfancis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.