public ReferrerPolicyMiddleware(AppFunc next, ReferrerPolicyOptions options)
            : base(next)
        {
            _config = options;
            var headerGenerator = new HeaderGenerator();

            _headerResult = headerGenerator.CreateReferrerPolicyResult(_config);
        }
Example #2
0
        /// <summary>
        /// Governs which referrer information, sent in the Referer header, should be included with requests made
        /// </summary>
        /// <remarks>
        /// If a <see cref="ReferrerPolicyOptions"/> value is not supplied, then the default value of "no-referrer"
        /// will be used.
        /// </remarks>
        public static SecureHeadersMiddlewareConfiguration UseReferrerPolicy
            (this SecureHeadersMiddlewareConfiguration config,
            ReferrerPolicyOptions referrerPolicyOption =
            ReferrerPolicyOptions.noReferrer)
        {
            config.UseReferrerPolicy = true;

            config.ReferrerPolicy = new ReferrerPolicy(referrerPolicyOption);
            return(config);
        }
        /// <summary>
        ///     Adds a middleware to the ASP.NET Core pipeline that sets the Referrer-Policy header.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder" /> to which the middleware is added.</param>
        /// <param name="configurer">An <see cref="Action" /> that configures the options for the middleware.</param>
        /// <returns>The <see cref="IApplicationBuilder" /> supplied in the app parameter.</returns>
        public static IApplicationBuilder UseReferrerPolicy(this IApplicationBuilder app, Action <IFluentReferrerPolicyOptions> configurer)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }

            var options = new ReferrerPolicyOptions();

            configurer(options);
            return(app.UseMiddleware <ReferrerPolicyMiddleware>(options));
        }
Example #4
0
        public ReferrerPolicyMiddleware(RequestDelegate next, ReferrerPolicyOptions option)
        {
            this.next = next;

            switch (option)
            {
            case ReferrerPolicyOptions.NoReferrerWhenDowngrade:
                headerValue = "no-referrer-when-downgrade";
                break;

            case ReferrerPolicyOptions.NoReferrer:
                headerValue = "no-referrer";
                break;

            case ReferrerPolicyOptions.Origin:
                headerValue = "origin";
                break;

            case ReferrerPolicyOptions.OriginWhenCrossOrigin:
                headerValue = "origin-when-cross-origin";
                break;

            case ReferrerPolicyOptions.SameOrigin:
                headerValue = "same-origin";
                break;

            case ReferrerPolicyOptions.StrictOrigin:
                headerValue = "strict-origin";
                break;

            case ReferrerPolicyOptions.StrictOriginWhenCrossOrigin:
                headerValue = "strict-origin-when-cross-origin";
                break;

            case ReferrerPolicyOptions.UnsafeUrl:
                headerValue = "unsafe-url";
                break;
            }
        }
 /// <summary>
 /// Adds middleware that adds the Referrer-Policy header.
 /// </summary>
 /// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
 /// <param name="option">A <see cref="ReferrerPolicyOptions"/> value representing an option to be set.</param>
 public static IApplicationBuilder UseReferrerPolicy(this IApplicationBuilder app, ReferrerPolicyOptions option)
 {
     return(app.UseMiddleware <ReferrerPolicyMiddleware>(option));
 }
Example #6
0
 public ReferrerPolicyOptionsTests()
 {
     _options = new ReferrerPolicyOptions();
 }
Example #7
0
 public ReferrerPolicy(ReferrerPolicyOptions referrerPolicyOption)
 {
     ReferrerPolicyOption = referrerPolicyOption;
 }
 public ReferrerPolicyMiddleware(ReferrerPolicyOptions options)
 {
     Policy       = options.Policy;
     _headerValue = HeaderValues[Policy];
 }
 public static IServiceCollection AddReferrerPolicy(this IServiceCollection services, ReferrerPolicyOptions options)
 {
     services.AddSingleton <ReferrerPolicyMiddleware>();
     services.AddSingleton(options);
     return(services);
 }