-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/cross origin opener policy (#160)
* Added model for Cross-Origin-Opener-Policy * Leveraged COOP models * Added tests for COOP header * Moved CORP model back to explicit constructor * Added missing test for COOP in one-shot test * Minor version bump * Ran dotnet-format on codebase * Checked off the COOP (Cross-Origin-Opener-Policy) header in list of supported headers * Linked to docs files for some of the supported headers * Moved detail about X-XSS-Protection header to a warning at the head of it's documentation * Added docs page for Cross-Origin-Resource-Policy (CORP) header * Altered order of Cache-Control header docs page * Added docs page for the Cross-Origin-Opener-Policy (COOP) header * Added links in index for CORP and COOP docs pages --------- Co-authored-by: Jamie Taylor <jamie.taylor@rjj-software.co.uk>
- Loading branch information
1 parent
b9a4671
commit a46c76b
Showing
15 changed files
with
338 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: Cache-Control | ||
nav_order: 7 | ||
nav_order: 8 | ||
parent: Configuration | ||
layout: page | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: Cross-Origin-Opener-Policy | ||
nav_order: 9 | ||
parent: Configuration | ||
layout: page | ||
--- | ||
|
||
The Mozilla Developer Network describes the Cross-Origin-Opener-Policy (COOP) header like this: | ||
|
||
{: .quote } | ||
> The HTTP Cross-Origin-Opener-Policy (COOP) response header allows a website to control whether a new top-level | ||
> document, opened using Window.open() or by navigating to a new page, is opened in the same browsing context group | ||
> (BCG) or in a new browsing context group. | ||
> | ||
> source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy | ||
A COOP header can be added in one of two ways, either using the default middleware options: | ||
|
||
```csharp | ||
app.UseSecureHeadersMiddleware(); | ||
``` | ||
|
||
The above adds the COOP header with a `same-origin` value. | ||
|
||
Or by creating an instance of the `SecureHeadersMiddlewareBuilder` class using the following code: | ||
|
||
```csharp | ||
var customConfig = SecureHeadersMiddlewareBuilder | ||
.CreateBuilder() | ||
.UseCrossOriginOpenerPolicy() | ||
.Build(); | ||
|
||
app.UseSecureHeadersMiddleware(customConfig); | ||
``` | ||
|
||
The above adds the COOP header with a `same-origin` value. | ||
|
||
## Full Options | ||
|
||
The COOP header object (known internally as `CrossOriginOpenerPolicy`) has the following options: | ||
|
||
- enum: `CrossOriginOpenerOptions` | ||
|
||
The values available for the `CrossOriginOpenerOptions` enum are: | ||
|
||
- `CrossOrigin` | ||
- `SameSite` | ||
- `SameOrigin` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Cross-Origin-Resource-Policy | ||
nav_order: 7 | ||
parent: Configuration | ||
layout: page | ||
--- | ||
|
||
The Mozilla Developer Network describes the Cross-Origin-Resource-Policy (CORP) header like this: | ||
|
||
{: .quote } | ||
> The HTTP Cross-Origin-Resource-Policy response header indicates that the browser should block no-cors cross-origin or cross-site requests to the given resource. | ||
> | ||
> source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy | ||
A CORP header can be added in one of two ways, either using the default middleware options: | ||
|
||
```csharp | ||
app.UseSecureHeadersMiddleware(); | ||
``` | ||
|
||
The above adds the CORP header with a `same-origin` value. | ||
|
||
Or by creating an instance of the `SecureHeadersMiddlewareBuilder` class using the following code: | ||
|
||
```csharp | ||
var customConfig = SecureHeadersMiddlewareBuilder | ||
.CreateBuilder() | ||
.UseCrossOriginResourcePolicy() | ||
.Build(); | ||
|
||
app.UseSecureHeadersMiddleware(customConfig); | ||
``` | ||
|
||
The above adds the CORP header with a `same-origin` value. | ||
|
||
## Full Options | ||
|
||
The CORP header object (known internally as `CrossOriginResourcePolicy`) has the following options: | ||
|
||
- enum: `CrossOriginResourceOptions` | ||
|
||
The values available for the `CrossOriginResourceOptions` enum are: | ||
|
||
- `CrossOrigin` | ||
- `SameSite` | ||
- `SameOrigin` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace OwaspHeaders.Core.Models; | ||
|
||
/// <summary> | ||
/// Cross-Origin-Opener-Policy. | ||
/// The following text was taken from the OWASP Secure Headers Project: | ||
/// This response header (also named COOP) allows you to ensure a top-level | ||
/// document does not share a browsing context group with cross-origin documents. | ||
/// COOP will process-isolate your document and potential attackers can’t access | ||
/// to your global object if they were opening it in a popup, preventing a | ||
/// set of cross-origin attacks dubbed XS-Leaks (https://xsleaks.dev/) | ||
/// (source Mozilla MDN (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy)). | ||
|
||
|
||
/// </summary> | ||
public class CrossOriginOpenerPolicy : IConfigurationBase | ||
{ | ||
/// <summary> | ||
/// Cross-Origin-Opener-Policy. | ||
/// The following text was taken from the OWASP Secure Headers Project: | ||
/// This response header (also named COOP) allows you to ensure a top-level | ||
/// document does not share a browsing context group with cross-origin documents. | ||
/// COOP will process-isolate your document and potential attackers can’t access | ||
/// to your global object if they were opening it in a popup, preventing a | ||
/// set of cross-origin attacks dubbed XS-Leaks (https://xsleaks.dev/) | ||
/// (source Mozilla MDN (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy)). | ||
/// </summary> | ||
public CrossOriginOpenerPolicy(CrossOriginOpenerOptions value = | ||
CrossOriginOpenerOptions.SameOrigin) | ||
{ | ||
OptionValue = value; | ||
} | ||
|
||
/// <summary> | ||
/// Allows the document to be added to its opener’s browsing context group | ||
/// unless the opener itself has a COOP of same-origin or same-origin-allow-popups (it is the default value). | ||
/// </summary> | ||
private const string UnsafeNoneValue = "unsafe-none"; | ||
|
||
/// <summary> | ||
/// Only requests from the same Site can read the resource. | ||
/// </summary> | ||
private const string SameOriginAllowPopupsValue = "same-origin-allow-popups"; | ||
|
||
/// <summary> | ||
/// Retains references to newly opened windows or tabs which either | ||
/// don’t set COOP or which opt out of isolation by setting a COOP | ||
/// of unsafe-none | ||
/// </summary> | ||
public const string SameOriginValue = "same-origin"; | ||
|
||
public enum CrossOriginOpenerOptions | ||
{ | ||
/// <summary> | ||
/// <see cref="UnsafeNoneValue"/> | ||
/// </summary> | ||
UnsafeNone, | ||
|
||
/// <summary> | ||
/// <see cref="SameOriginAllowPopupsValue"/> | ||
/// </summary> | ||
SameOriginAllowPopups, | ||
|
||
/// <summary> | ||
/// <see cref="SameOriginValue"/> | ||
/// </summary> | ||
SameOrigin | ||
}; | ||
|
||
private CrossOriginOpenerOptions OptionValue { get; } | ||
|
||
/// <summary> | ||
/// Builds the HTTP header value | ||
/// </summary> | ||
/// <returns>A string representing the HTTP header value</returns> | ||
public string BuildHeaderValue() | ||
{ | ||
switch (OptionValue) | ||
{ | ||
case CrossOriginOpenerOptions.SameOriginAllowPopups: | ||
return SameOriginAllowPopupsValue; | ||
case CrossOriginOpenerOptions.UnsafeNone: | ||
return UnsafeNoneValue; | ||
case CrossOriginOpenerOptions.SameOrigin: | ||
default: | ||
return SameOriginValue; | ||
} | ||
} | ||
} |
Oops, something went wrong.