Example #1
0
        public void SetCspHeaders(IHttpContextWrapper context, bool reportOnly)
        {
            var cspConfig = _cspConfigurationOverrideHelper.GetCspConfigWithOverrides(context, reportOnly);

            if (cspConfig == null)
            {
                return;
            }

            var oldConfig = _contextConfigurationHelper.GetCspConfiguration(context, reportOnly);
            var header    = _headerGenerator.CreateCspResult(cspConfig, reportOnly, _reportHelper.GetBuiltInCspReportHandlerRelativeUri(), oldConfig);

            _headerResultHandler.HandleHeaderResult(context, header);
        }
        public ICspConfiguration GetCspConfigWithOverrides([NotNull] HttpContextBase context, bool reportOnly)
        {
            var overrides = _contextConfigurationHelper.GetCspConfigurationOverride(context, reportOnly, true);

            //No overrides
            if (overrides == null)
            {
                return(null);
            }

            var newConfig      = new CspConfiguration(false);
            var originalConfig = _contextConfigurationHelper.GetCspConfiguration(context, reportOnly);

            //We might be "attributes only", so no other config around.
            if (originalConfig != null)
            {
                _configMapper.MergeConfiguration(originalConfig, newConfig);
            }

            //Deal with header override
            _configMapper.MergeOverrides(overrides, newConfig);

            return(newConfig);
        }
Example #3
0
        internal void SetCspHeaders(HttpContext context, bool reportOnly)
        {
            var cspConfig = _cspConfigurationOverrideHelper.GetCspConfigWithOverrides(context, reportOnly);

            if (cspConfig == null)
            {
                return;
            }

            var oldConfig = _contextConfigurationHelper.GetCspConfiguration(context, reportOnly);
            var header    = _headerGenerator.CreateCspResult(cspConfig, reportOnly, null, oldConfig);

            //TODO CSP reporting fun
            //var header = _headerGenerator.CreateCspResult(cspConfig, reportOnly, _reportHelper.GetBuiltInCspReportHandlerRelativeUri(), oldConfig);

            _headerResultHandler.HandleHeaderResult(context.Response, header);
        }
Example #4
0
        internal void SetCspHeaders(HttpContextBase context, bool reportOnly)
        {
            var cspConfig = _cspConfigurationOverrideHelper.GetCspConfigWithOverrides(context, reportOnly);

            if (cspConfig == null)
            {
                return;
            }

            var userAgent = context.Request.UserAgent;

            if (!String.IsNullOrEmpty(userAgent) && userAgent.Contains(" Version/5") && userAgent.Contains(" Safari/"))
            {
                return;
            }

            var oldConfig = _contextConfigurationHelper.GetCspConfiguration(context, reportOnly);
            var header    = _headerGenerator.CreateCspResult(cspConfig, reportOnly, _reportHelper.GetBuiltInCspReportHandlerRelativeUri(), oldConfig);

            _headerResultHandler.HandleHeaderResult(context.Response, header);
        }