diff --git a/changelog.md b/changelog.md index e6f1dbf..e335b84 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,10 @@ This changelog represents all of the major (i.e. breaking) changes made to the O | 2 | Uses `secureHeaderSettings.json` and default config loader to create instances of `SecureHeadersMiddlewareConfiguration` class
also uses .NET Core 2.0 | | 1 | Uses `secureHeaderSettings.json` and default config loader to create instances of `SecureHeadersMiddlewareConfiguration` class
also uses .NET Standard 1.4 | +### Version 7 + +This version adds the Cross-Origin-Resource-Policy header with the OWASP recommended value "same-origin" to the list of default headers in the `BuildDefaultConfiguration()` extension method. This was requested via [issue #76](https://github.com/GaProgMan/OwaspHeaders.Core/issues/76). + ### Version 6 This version removes Expect-CT Header from the list of default headers in the `BuildDefaultConfiguration()` extension method. This is related to [issue #72](https://github.com/GaProgMan/OwaspHeaders.Core/issues/72). diff --git a/src/Constants.cs b/src/Constants.cs index 61aa50c..d8d5314 100644 --- a/src/Constants.cs +++ b/src/Constants.cs @@ -27,5 +27,7 @@ public static class Constants public static readonly string PoweredByHeaderName = "X-Powered-By"; public static readonly string ServerHeaderName = "Server"; + + public static readonly string CrossOriginResourcePolicyHeaderName = "Cross-Origin-Resource-Policy"; } } diff --git a/src/Extensions/SecureHeadersMiddlewareBuilder.cs b/src/Extensions/SecureHeadersMiddlewareBuilder.cs index dbb5722..fffbc6a 100644 --- a/src/Extensions/SecureHeadersMiddlewareBuilder.cs +++ b/src/Extensions/SecureHeadersMiddlewareBuilder.cs @@ -12,6 +12,7 @@ using OwaspHeaders.Core.Enums; using OwaspHeaders.Core.Helpers; using OwaspHeaders.Core.Models; +using static OwaspHeaders.Core.Models.CrossOriginResourcePolicy; namespace OwaspHeaders.Core.Extensions { @@ -319,7 +320,23 @@ public static SecureHeadersMiddlewareConfiguration RemovePoweredByHeader (this SecureHeadersMiddlewareConfiguration config) { config.RemoveXPoweredByHeader = true; + return config; + } + /// + /// The HTTP Cross-Origin-Resource-Policy response header conveys a desire that the browser + /// blocks no-cors cross-origin/cross-site requests to the given resource. + /// + /// + /// The HTTP Cross-Origin-Resource-Policy response header value. + /// + /// + /// Defaults to "same-origin" () which means that "Only requests from the same Origin (i.e. scheme + host + port) can read the resource." + /// + public static SecureHeadersMiddlewareConfiguration UseCrossOriginResourcePolicy(this SecureHeadersMiddlewareConfiguration config, CrossOriginResourceOptions value = CrossOriginResourceOptions.SameOrigin) + { + config.UseCrossOriginResourcePolicy = true; + config.CrossOriginResourcePolicy = new CrossOriginResourcePolicy(value); return config; } diff --git a/src/Extensions/SecureHeadersMiddlewareExtensions.cs b/src/Extensions/SecureHeadersMiddlewareExtensions.cs index e686d5e..bdb2be3 100644 --- a/src/Extensions/SecureHeadersMiddlewareExtensions.cs +++ b/src/Extensions/SecureHeadersMiddlewareExtensions.cs @@ -33,6 +33,7 @@ public static SecureHeadersMiddlewareConfiguration BuildDefaultConfiguration() .UseCacheControl() .RemovePoweredByHeader() .UseXssProtection() + .UseCrossOriginResourcePolicy() .Build(); } diff --git a/src/Models/CrossOriginResourcePolicy.cs b/src/Models/CrossOriginResourcePolicy.cs new file mode 100644 index 0000000..1c1e4ca --- /dev/null +++ b/src/Models/CrossOriginResourcePolicy.cs @@ -0,0 +1,67 @@ +namespace OwaspHeaders.Core.Models +{ + /// + /// Cross-Origin-Resource-Policy + /// This response header(also named CORP) allows to define a policy that lets web sites and applications opt in to protection + /// against certain requests from other origins(such as those issued with elements like