Пример #1
0
        public ReferrerPolicyMiddleware(AppFunc next, ReferrerPolicyOptions options)
            : base(next)
        {
            _config = options;
            var headerGenerator = new HeaderGenerator();

            _headerResult = headerGenerator.CreateReferrerPolicyResult(_config);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferrerPolicyAttribute"/> class
 /// </summary>
 public ReferrerPolicyAttribute(ReferrerPolicy policy)
 {
     _config = new ReferrerPolicyConfiguration {
         Policy = policy.MapToCoreType()
     };
     _configurationOverrideHelper = new HeaderConfigurationOverrideHelper();
     _headerOverrideHelper        = new HeaderOverrideHelper(new CspReportHelper());
 }
        internal void SetReferrerPolicyOverride(HttpContext context, IReferrerPolicyConfiguration referrerConfig)
        {
            var headerList = GetHeaderListFromContext(context);
            var headerKey  = HeaderConstants.ReferrerPolicyHeader;

            if (headerList.ContainsKey(headerKey))
            {
                headerList.Remove(headerKey);
            }

            headerList.Add(headerKey, referrerConfig);
        }
Пример #4
0
        public HeaderResult CreateReferrerPolicyResult(IReferrerPolicyConfiguration rpConfig,
                                                       IReferrerPolicyConfiguration oldRpConfig = null)
        {
            if (oldRpConfig != null && oldRpConfig.Policy != ReferrerPolicy.Disabled && rpConfig.Policy == ReferrerPolicy.Disabled)
            {
                return(new HeaderResult(HeaderResult.ResponseAction.Remove, HeaderConstants.ReferrerPolicyHeader));
            }

            if (rpConfig.Policy == ReferrerPolicy.Disabled)
            {
                return(null);
            }

            var policyValue = rpConfig.Policy.GetPolicyString();

            return(new HeaderResult(HeaderResult.ResponseAction.Set, HeaderConstants.ReferrerPolicyHeader, policyValue));
        }
Пример #5
0
 internal void SetReferrerPolicyOverride(IHttpContextWrapper context, IReferrerPolicyConfiguration referrerConfig)
 {
     context.GetNWebsecOverrideContext().ReferrerPolicy = referrerConfig;
 }