Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/docs basic entries #129

Merged
merged 31 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea81c23
Re-arranged basic docs, added configuration page
GaProgMan Nov 27, 2024
7cf5d6d
Altered ordering of pages
GaProgMan Nov 27, 2024
8b48c50
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Nov 27, 2024
2426011
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Nov 27, 2024
0fac4a4
Added changelog to docs
GaProgMan Nov 28, 2024
de7ec2f
Added about header to index
GaProgMan Nov 28, 2024
3c07ed7
Removed reference to code base
GaProgMan Nov 28, 2024
ad341fe
Added quote type to docs config
GaProgMan Nov 28, 2024
f3c6ac3
Made configuration docs into a directory
GaProgMan Nov 28, 2024
4c96d6f
Added HSTS and X-Frame-Options docs
GaProgMan Nov 28, 2024
43e1d5c
Added empty CSP docs file
GaProgMan Nov 28, 2024
448d81e
Added docs for the X-Content-Type-Options header
GaProgMan Nov 28, 2024
1ecad8e
Added docs for the X-XSS-Protection header
GaProgMan Nov 28, 2024
e27932b
Linked to the CSP header docs in the X-Frame-Options header
GaProgMan Nov 28, 2024
7356ac7
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Nov 28, 2024
f80a97c
Fixed layout types on header config docs
GaProgMan Nov 28, 2024
3d8c1b6
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Nov 28, 2024
eba1437
Fixed layout for CSP header config page
GaProgMan Nov 28, 2024
6495afa
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Nov 28, 2024
4ead07c
Set header options files as children of the Configuration leaf
GaProgMan Dec 2, 2024
1842164
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Dec 2, 2024
2b4284d
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Dec 2, 2024
4022b42
Add docs build badge to readme
GaProgMan Dec 2, 2024
f97ad50
Removed "layout" from front matter of all Configuration child pages
GaProgMan Dec 2, 2024
2edd361
Set parent on all Configuration child pages
GaProgMan Dec 2, 2024
07a74cb
Added explicit default layout for all Configuration pages
GaProgMan Dec 2, 2024
340924a
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Dec 2, 2024
d09616b
Added layout type to parent Configuration page
GaProgMan Dec 2, 2024
c8a41b0
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Dec 2, 2024
75e51f3
Increased text coverage in Configuration page
GaProgMan Dec 2, 2024
2f3826a
Merge branch 'main' into feature/docs-basic-entries
GaProgMan Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ callouts:
note:
title: Note
color: purple
suggestion:
title: Suggestion
color: green
warning:
title: Warning
color: red
Expand Down
68 changes: 60 additions & 8 deletions docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ nav_order: 2
layout: page
---

This Middleware uses the builder pattern to set up the header information, which is a compile time dependency. If you need to change the configuration, you will need to rebuild your application.
OwaspHeaders.Core uses the builder pattern to set up the header information, which is a compile time dependency. If you need
to change the configuration, you will need to rebuild your application. This is an intentional design choice, as a change
to any of the HTTP headers that the OwaspHeaders.Core middleware injects should require the application to restart.

## Basic Configuration

Adding the default configuration by adding the following to your `Program.cs` somewhere in the Middleware pipeline:
Add the default configuration by adding the following to your `Program.cs` the Middleware pipeline as early as is
possible for your application design:

```csharp
app.UseSecureHeadersMiddleware();
```

This will use the default configuration for the OwaspHeaders.Core middleware. The method looks like this:
The above will use the default configuration for the OwaspHeaders.Core middleware. The method that sets the defaults looks
like this:

```csharp
public static SecureHeadersMiddlewareConfiguration BuildDefaultConfiguration()
Expand All @@ -38,29 +42,64 @@ public static SecureHeadersMiddlewareConfiguration BuildDefaultConfiguration()
{: .warning }
The default configuration is INCREDIBLY restrictive.

The following is an example of the response headers from version 9.1.0 (taken on November 19th, 2024) when using the
default configuration:

```plaintext
Cache-Control: max-age=31536000;private
Strict-Transport-Security: max-age=31536000;includeSubDomains
X-Frame-Options: DENY
X-XSS-Protection: 0
X-Content-Type-Options: nosniff
Content-Security-Policy: script-src 'self';object-src 'self';block-all-mixed-content;upgrade-insecure-requests;
X-Permitted-Cross-Domain-Policies: none;
Referrer-Policy: no-referrer
Cross-Origin-Resource-Policy: same-origin
```

{: .note }
The above example contains only the headers added by the Middleware.

### Custom Configuration

In order to use a custom configuration, follow the same pattern (perhaps creating your own extension method to encapsulate it). In the following example, we've created a static method called `CustomConfiguration` within a helpers class (called `CustomSecureHeaderExtensions`) which returns a completely custom configuration:
In most cases (except for the [Content-Security Policy](./Content-Security-Policy.md)), the default configuration will
be suitable. This is because it adds the OWASP recommended headers and values. Content-Security Policy is a non-trivial
header, and is an allowlist for sources of content for the rendered page.

In some cases, you may need to provide a custom configuration for the OwaspHeaders.Core middleware. In order to use a
custom configuration, follow the same pattern.

{: .suggestion }
We recommend creating your own extension method to encapsulate your custom configuration.

In the following example, we've created a static method called `CustomConfiguration` within a static extensions class
(called `CustomSecureHeaderExtensions`). This custom method returns an instance of the `SecureHeadersMiddlewareConfiguration`
which contains all the configuration required for a fictional custom configuration:

``` csharp
public static CustomSecureHeaderExtensions
using OwaspHeaders.Core.Enums;
using OwaspHeaders.Core.Extensions;
using OwaspHeaders.Core.Models;

namespace OwaspHeaders.Core.Example.Helpers;

public static class CustomSecureHeaderExtensions
{
public static SecureHeadersMiddlewareConfiguration CustomConfiguration()
{
return SecureHeadersMiddlewareBuilder
.CreateBuilder()
.UseHsts(1200, false)
.UseContentDefaultSecurityPolicy()
.UsePermittedCrossDomainPolicy
(XPermittedCrossDomainOptionValue.masterOnly)
.UsePermittedCrossDomainPolicies(XPermittedCrossDomainOptionValue.masterOnly)
.UseReferrerPolicy(ReferrerPolicyOptions.sameOrigin)
.Build();
}
}
```

{: .note }
This is an example configuration
This is an example configuration. It is recommended that you do NOT use this configuration in a production environment.

Then consume it in the following manner, within your `Program.cs`'s Middleware pipeline:

Expand All @@ -69,3 +108,16 @@ app.UseSecureHeadersMiddleware(
CustomSecureHeaderExtensions.CustomConfiguration()
);
```

This configuration will add the following headers to all server-generated responses:

```plaintext
Strict-Transport-Security: max-age=1200
Content-Security-Policy: script-src 'self';object-src 'self';block-all-mixed-content;upgrade-insecure-requests;
X-Permitted-Cross-Domain-Policies: master-only;
Referrer-Policy: same-origin
```

{: .note }
The above example contains only the headers added by the Middleware for the configuration provided in the
`CustomConfiguration` extension method.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app.UseSecureHeadersMiddleware();

This will add a number of default HTTP headers to all responses from your server component.

The following is an example of the response headers from version 9.0.0 (taken on November 19th, 2024)
The following is an example of the response headers from version 9.1.0 (taken on November 19th, 2024)

```plaintext
Cache-Control: max-age=31536000;private
Expand All @@ -50,7 +50,7 @@ Cross-Origin-Resource-Policy: same-origin
{: .note }
The above example contains only the headers added by the Middleware.

For a more detailed explanation of how to use the middleware, including how to configure it, see [Using the Middleware]().
For a more detailed explanation of how to use the middleware, including how to configure it, see [Configuration](./configuration).

## Server Header: A Warning

Expand Down