| | | 1 | | namespace ProjectTemplate.Web.Options; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Options to control which security-related HTTP headers are applied by the application. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class ApplicationSecurityHeadersOptions |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Gets the configuration section name used to bind security header settings. |
| | | 10 | | /// </summary> |
| | 154 | 11 | | public static string SectionName { get; internal set; } = "ProjectTemplate:SecurityHeaders"; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets or sets a value indicating whether security headers are enabled. |
| | | 15 | | /// </summary> |
| | 636 | 16 | | public bool Enabled { get; set; } = true; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets or sets a value indicating whether the Content-Security-Policy header is applied. |
| | | 20 | | /// </summary> |
| | 874 | 21 | | public bool EnableContentSecurityPolicy { get; set; } = true; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets or sets a value indicating whether the Permissions-Policy header is applied. |
| | | 25 | | /// </summary> |
| | 876 | 26 | | public bool EnablePermissionsPolicy { get; set; } = true; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets or sets a value indicating whether cross-origin related headers are applied. |
| | | 30 | | /// </summary> |
| | 618 | 31 | | public bool EnableCrossOriginHeaders { get; set; } = true; |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets or sets the Content-Security-Policy header value applied to responses. |
| | | 35 | | /// </summary> |
| | 706 | 36 | | public string ContentSecurityPolicy { get; set; } = |
| | 258 | 37 | | "default-src 'self'; " + |
| | 258 | 38 | | "base-uri 'self'; " + |
| | 258 | 39 | | "object-src 'none'; " + |
| | 258 | 40 | | "frame-ancestors 'none'; " + |
| | 258 | 41 | | "form-action 'self'; " + |
| | 258 | 42 | | "img-src 'self' data:; " + |
| | 258 | 43 | | "script-src 'self'; " + |
| | 258 | 44 | | "style-src 'self' 'unsafe-inline';"; |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Gets or sets the Permissions-Policy header value applied to responses. |
| | | 48 | | /// Set EnablePermissionsPolicy to false to omit the header. |
| | | 49 | | /// </summary> |
| | 708 | 50 | | public string PermissionsPolicy { get; set; } = |
| | 258 | 51 | | "camera=(), microphone=(), geolocation=(), payment=(), usb=(), fullscreen=(self)"; |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Gets or sets path prefixes that are excluded from applying the security headers. |
| | | 55 | | /// </summary> |
| | 892 | 56 | | public List<string> ExcludedPathPrefixes { get; set; } = |
| | 258 | 57 | | [ |
| | 258 | 58 | | "/health", |
| | 258 | 59 | | "/metrics" |
| | 258 | 60 | | ]; |
| | | 61 | | } |