/// <summary> /// Initializes a new instance of the <see cref="SecurityHeadersMiddleware"/> class. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policies">A <see cref="HeaderPolicyCollection"/> containing the policies to be applied.</param> /// <param name="nonceGenerator">Used to generate nonce (number used once) values for headers</param> internal SecurityHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, HeaderPolicyCollection policies, INonceGenerator nonceGenerator) { _next = next ?? throw new ArgumentNullException(nameof(next)); _service = service ?? throw new ArgumentNullException(nameof(service)); _policy = policies ?? throw new ArgumentNullException(nameof(policies)); _nonceGenerator = nonceGenerator ?? throw new ArgumentException(nameof(nonceGenerator)); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityHeadersMiddleware"/> class. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policies">A <see cref="HeaderPolicyCollection"/> containing the policies to be applied.</param> public SecurityHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, HeaderPolicyCollection policies) : this(next, service, policies, new RNGNonceGenerator()) { // TODO: Yuk. Don't want to be generating a noce every request if we don't have to though... // Could look at generalising this if we need it for other CSP headers _mustGenerateNonce = _policy.Values .Where(header => header is ContentSecurityPolicyHeader) .Cast <ContentSecurityPolicyHeader>() .Any(header => header.HasPerRequestValues); }
/// <summary> /// Instantiates a new <see cref="CustomHeadersMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policy">A <see cref="HeaderPolicyCollection"/> containing the policies to be applied.</param> public CustomHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, HeaderPolicyCollection policy) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } _next = next; _service = service; _policy = policy; }
/// <summary> /// Instantiates a new <see cref="CustomHeadersMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policyProvider">A policy provider which can get a <see cref="HeaderPolicyCollection"/>.</param> /// <param name="policyName">An optional name of the policy to be fetched..</param> public CustomHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, ICustomHeaderPolicyProvider policyProvider, string policyName) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } if (policyProvider == null) { throw new ArgumentNullException(nameof(policyProvider)); } _next = next; _service = service; _policyProvider = policyProvider; _policyName = policyName; }
/// <summary> /// Instantiates a new <see cref="SecurityHeadersMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policy">A <see cref="HeaderPolicyCollection"/> containing the policies to be applied.</param> public SecurityHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, HeaderPolicyCollection policy) { _next = next ?? throw new ArgumentNullException(nameof(next)); _service = service ?? throw new ArgumentNullException(nameof(service)); _policy = policy ?? throw new ArgumentNullException(nameof(policy)); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityHeadersMiddleware"/> class. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="service">An instance of <see cref="ICustomHeaderService"/>.</param> /// <param name="policies">A <see cref="HeaderPolicyCollection"/> containing the policies to be applied.</param> public SecurityHeadersMiddleware(RequestDelegate next, ICustomHeaderService service, HeaderPolicyCollection policies) : this(next, service, policies, new NullNonceGenerator()) { _mustGenerateNonce = false; }
public CustomHeaderController(IErrorService errorService, ICustomHeaderService customImageService) : base(errorService) { this._customImageService = customImageService; }