Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between UseHttpsRedirection and UseHsts

I don't quite get the difference between UseHsts and UseHttpsRedirection in the configure section of the startup file in .net core. Could anyone explain?

like image 916
Roger Lebrun Avatar asked Sep 28 '18 13:09

Roger Lebrun


2 Answers

According to the documentation you should use both together:

We recommend all production ASP.NET Core web apps call:

  • The HTTPS Redirection Middleware (UseHttpsRedirection) to redirect all HTTP requests to HTTPS.
  • UseHsts, HTTP Strict Transport Security Protocol (HSTS).

ASP.NET Core Enforce HTTPS

The .UseHttpsRedirection() will issue HTTP response codes redirecting from http to https. The .UseHsts() will add the HSTS response header which the client is supposed to obey.

like image 123
Nate Avatar answered Nov 15 '22 05:11

Nate


UseHsts adds the Strict-Transport-Security header to the response, which informs the browser that the application must only be accessed with HTTPS. After this declaration, compliant browsers should automatically convert any http request of the application into an HTTPS request.

UseHttpsRedirection causes an automatic redirection to HTTPS URL when an HTTP URL is received, in a way that forces a secure connection.

Once the first HTTPS secure connection is established, the strict-security header prevents future redirections that might be used to perform man-in-the-middle attacks.

like image 45
eslam helmy Avatar answered Nov 15 '22 05:11

eslam helmy