Skip to content

Commit a5b3914

Browse files
authored
Enforcing HTTPS enhancements (dotnet#9044)
1 parent 967d89a commit a5b3914

File tree

5 files changed

+136
-103
lines changed

5 files changed

+136
-103
lines changed

aspnetcore/host-and-deploy/linux-apache.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to set up Apache as a reverse proxy server on CentOS to r
44
author: spboyer
55
ms.author: spboyer
66
ms.custom: mvc
7-
ms.date: 10/09/2018
7+
ms.date: 10/23/2018
88
uid: host-and-deploy/linux-apache
99
---
1010
# Host ASP.NET Core on Linux with Apache
@@ -51,13 +51,6 @@ Any component that depends on the scheme, such as authentication, link generatio
5151

5252
::: moniker range=">= aspnetcore-2.0"
5353

54-
> [!NOTE]
55-
> Either configuration—with or without a reverse proxy server—is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps. For more information, see [When to use Kestrel with a reverse proxy](xref:fundamentals/servers/kestrel#when-to-use-kestrel-with-a-reverse-proxy).
56-
57-
::: moniker-end
58-
59-
# [ASP.NET Core 2.x](#tab/aspnetcore2x)
60-
6154
Invoke the [UseForwardedHeaders](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersextensions.useforwardedheaders) method in `Startup.Configure` before calling [UseAuthentication](/dotnet/api/microsoft.aspnetcore.builder.authappbuilderextensions.useauthentication) or similar authentication scheme middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers:
6255

6356
```csharp
@@ -69,7 +62,9 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
6962
app.UseAuthentication();
7063
```
7164

72-
# [ASP.NET Core 1.x](#tab/aspnetcore1x)
65+
::: moniker-end
66+
67+
::: moniker range="< aspnetcore-2.0"
7368

7469
Invoke the [UseForwardedHeaders](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersextensions.useforwardedheaders) method in `Startup.Configure` before calling [UseIdentity](/dotnet/api/microsoft.aspnetcore.builder.builderextensions.useidentity) and [UseFacebookAuthentication](/dotnet/api/microsoft.aspnetcore.builder.facebookappbuilderextensions.usefacebookauthentication) or similar authentication scheme middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers:
7570

@@ -87,7 +82,7 @@ app.UseFacebookAuthentication(new FacebookOptions()
8782
});
8883
```
8984

90-
---
85+
::: moniker-end
9186

9287
If no [ForwardedHeadersOptions](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersoptions) are specified to the middleware, the default headers to forward are `None`.
9388

@@ -393,13 +388,17 @@ sudo yum install mod_headers
393388

394389
[Clickjacking](https://blog.qualys.com/securitylabs/2015/10/20/clickjacking-a-common-implementation-mistake-that-can-put-your-websites-in-danger), also known as a *UI redress attack*, is a malicious attack where a website visitor is tricked into clicking a link or button on a different page than they're currently visiting. Use `X-FRAME-OPTIONS` to secure the site.
395390

396-
Edit the *httpd.conf* file:
391+
To mitigate clickjacking attacks:
397392

398-
```bash
399-
sudo nano /etc/httpd/conf/httpd.conf
400-
```
393+
1. Edit the *httpd.conf* file:
394+
395+
```bash
396+
sudo nano /etc/httpd/conf/httpd.conf
397+
```
401398

402-
Add the line `Header append X-FRAME-OPTIONS "SAMEORIGIN"`. Save the file. Restart Apache.
399+
Add the line `Header append X-FRAME-OPTIONS "SAMEORIGIN"`.
400+
1. Save the file.
401+
1. Restart Apache.
403402

404403
#### MIME-type sniffing
405404

@@ -479,4 +478,5 @@ The example file limits bandwidth as 600 KB/sec under the root location:
479478

480479
## Additional resources
481480

481+
* [Prerequisites for .NET Core on Linux](/dotnet/core/linux-prerequisites)
482482
* [Configure ASP.NET Core to work with proxy servers and load balancers](xref:host-and-deploy/proxy-load-balancer)

aspnetcore/host-and-deploy/linux-nginx.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: rick-anderson
44
description: Learn how to setup Nginx as a reverse proxy on Ubuntu 16.04 to forward HTTP traffic to an ASP.NET Core web app running on Kestrel.
55
ms.author: riande
66
ms.custom: mvc
7-
ms.date: 10/09/2018
7+
ms.date: 10/23/2018
88
uid: host-and-deploy/linux-nginx
99
---
1010
# Host ASP.NET Core on Linux with Nginx
@@ -60,13 +60,6 @@ Test the app:
6060

6161
A reverse proxy is a common setup for serving dynamic web apps. A reverse proxy terminates the HTTP request and forwards it to the ASP.NET Core app.
6262

63-
::: moniker range=">= aspnetcore-2.0"
64-
65-
> [!NOTE]
66-
> Either configuration&mdash;with or without a reverse proxy server&mdash;is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps. For more information, see [When to use Kestrel with a reverse proxy](xref:fundamentals/servers/kestrel#when-to-use-kestrel-with-a-reverse-proxy).
67-
68-
::: moniker-end
69-
7063
### Use a reverse proxy server
7164

7265
Kestrel is great for serving dynamic content from ASP.NET Core. However, the web serving capabilities aren't as feature rich as servers such as IIS, Apache, or Nginx. A reverse proxy server can offload work such as serving static content, caching requests, compressing requests, and SSL termination from the HTTP server. A reverse proxy server may reside on a dedicated machine or may be deployed alongside an HTTP server.
@@ -77,7 +70,7 @@ Because requests are forwarded by reverse proxy, use the [Forwarded Headers Midd
7770

7871
Any component that depends on the scheme, such as authentication, link generation, redirects, and geolocation, must be placed after invoking the Forwarded Headers Middleware. As a general rule, Forwarded Headers Middleware should run before other middleware except diagnostics and error handling middleware. This ordering ensures that the middleware relying on forwarded headers information can consume the header values for processing.
7972

80-
# [ASP.NET Core 2.x](#tab/aspnetcore2x)
73+
::: moniker range=">= aspnetcore-2.0"
8174

8275
Invoke the [UseForwardedHeaders](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersextensions.useforwardedheaders) method in `Startup.Configure` before calling [UseAuthentication](/dotnet/api/microsoft.aspnetcore.builder.authappbuilderextensions.useauthentication) or similar authentication scheme middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers:
8376

@@ -90,7 +83,9 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
9083
app.UseAuthentication();
9184
```
9285

93-
# [ASP.NET Core 1.x](#tab/aspnetcore1x)
86+
::: moniker-end
87+
88+
::: moniker range="< aspnetcore-2.0"
9489

9590
Invoke the [UseForwardedHeaders](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersextensions.useforwardedheaders) method in `Startup.Configure` before calling [UseIdentity](/dotnet/api/microsoft.aspnetcore.builder.builderextensions.useidentity) and [UseFacebookAuthentication](/dotnet/api/microsoft.aspnetcore.builder.facebookappbuilderextensions.usefacebookauthentication) or similar authentication scheme middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers:
9691

@@ -108,7 +103,7 @@ app.UseFacebookAuthentication(new FacebookOptions()
108103
});
109104
```
110105

111-
---
106+
::: moniker-end
112107

113108
If no [ForwardedHeadersOptions](/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersoptions) are specified to the middleware, the default headers to forward are `None`.
114109

@@ -327,7 +322,7 @@ sudo ufw enable
327322

328323
Edit *src/http/ngx_http_header_filter_module.c*:
329324

330-
```c
325+
```
331326
static char ngx_http_server_string[] = "Server: Web Server" CRLF;
332327
static char ngx_http_server_full_string[] = "Server: Web Server" CRLF;
333328
```
@@ -342,9 +337,9 @@ Configure the server with additional required modules. Consider using a web app
342337

343338
* Harden the security by employing some of the practices depicted in the following */etc/nginx/nginx.conf* file. Examples include choosing a stronger cipher and redirecting all traffic over HTTP to HTTPS.
344339

345-
* Adding an `HTTP Strict-Transport-Security` (HSTS) header ensures all subsequent requests made by the client are over HTTPS only.
340+
* Adding an `HTTP Strict-Transport-Security` (HSTS) header ensures all subsequent requests made by the client are over HTTPS.
346341

347-
* Don't add the Strict-Transport-Security header or chose an appropriate `max-age` if SSL will be disabled in the future.
342+
* Don't add the HSTS header or chose an appropriate `max-age` if SSL will be disabled in the future.
348343

349344
Add the */etc/nginx/proxy.conf* configuration file:
350345

@@ -355,15 +350,20 @@ Edit the */etc/nginx/nginx.conf* configuration file. The example contains both `
355350
[!code-nginx[](linux-nginx/nginx.conf?highlight=2)]
356351

357352
#### Secure Nginx from clickjacking
358-
Clickjacking is a malicious technique to collect an infected user's clicks. Clickjacking tricks the victim (visitor) into clicking on an infected site. Use X-FRAME-OPTIONS to secure the site.
359353

360-
Edit the *nginx.conf* file:
354+
[Clickjacking](https://blog.qualys.com/securitylabs/2015/10/20/clickjacking-a-common-implementation-mistake-that-can-put-your-websites-in-danger), also known as a *UI redress attack*, is a malicious attack where a website visitor is tricked into clicking a link or button on a different page than they're currently visiting. Use `X-FRAME-OPTIONS` to secure the site.
361355

362-
```bash
363-
sudo nano /etc/nginx/nginx.conf
364-
```
356+
To mitigate clickjacking attacks:
357+
358+
1. Edit the *nginx.conf* file:
359+
360+
```bash
361+
sudo nano /etc/nginx/nginx.conf
362+
```
365363

366-
Add the line `add_header X-Frame-Options "SAMEORIGIN";` and save the file, then restart Nginx.
364+
Add the line `add_header X-Frame-Options "SAMEORIGIN";`.
365+
1. Save the file.
366+
1. Restart Nginx.
367367

368368
#### MIME-type sniffing
369369

0 commit comments

Comments
 (0)