<commit_before>﻿using System;
using System.Web.Mvc;
using RequireHttpsAttributeBase = System.Web.Mvc.RequireHttpsAttribute;

namespace CertiPay.Common.Web
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class RequireHttpsOverrideAttribute : RequireHttpsAttributeBase
    {
        // This class is borrowed from the AppHarbor FAQ's.
        // Right now, we mainly use it for the Request.IsLocal check to avoid requiring SSL locally
        // but we'll likely need it in the future for the load balancer header check

        private const String PROTOCOL_HEADER_FIELD = "X-Forwarded-Proto";

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (filterContext.HttpContext.Request.IsSecureConnection)
            {
                return;
            }

            if (filterContext.HttpContext.Request.IsLocal)
            {
                return;
            }

            if (string.Equals(filterContext.HttpContext.Request.Headers[PROTOCOL_HEADER_FIELD], Uri.UriSchemeHttps, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            HandleNonHttpsRequest(filterContext);
        }
    }
}<commit_msg>Added Forwarded to checked Headers<commit_after>﻿using System;
using System.Linq;
using System.Web.Mvc;
using RequireHttpsAttributeBase = System.Web.Mvc.RequireHttpsAttribute;

namespace CertiPay.Common.Web
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class RequireHttpsOverrideAttribute : RequireHttpsAttributeBase
    {
        // This class is borrowed from the AppHarbor FAQ's.
        // Right now, we mainly use it for the Request.IsLocal check to avoid requiring SSL locally
        // but we'll likely need it in the future for the load balancer header check

        private const String PROTOCOL_HEADER_FIELD = "X-Forwarded-Proto";

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (filterContext.HttpContext.Request.IsSecureConnection)
            {
                return;
            }

            if (filterContext.HttpContext.Request.IsLocal)
            {
                return;
            }

            if (string.Equals(filterContext.HttpContext.Request.Headers[PROTOCOL_HEADER_FIELD], Uri.UriSchemeHttps, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            //Mimic behavoir from Nancy's SSLProxy to conform with RFC7239
            //http://tools.ietf.org/html/rfc7239#section-1
            if (filterContext.HttpContext.Request.Headers.Get("Forwarded") != null)
            {
                var forwardedHeader = filterContext.HttpContext.Request.Headers.Get("Forwarded").Split(',');
                var protoValue = forwardedHeader.FirstOrDefault(x => x.StartsWith("proto", StringComparison.OrdinalIgnoreCase));
                if (protoValue != null && protoValue.Equals("proto=https", StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
            }

            HandleNonHttpsRequest(filterContext);
        }
    }
}
{'fraction_non_alphanumeric': 0.07744297381019431, 'fraction_numerical': 0.0025344973246972683, 'mean_word_length': 2.21447963800905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3744130', 'n_tokens_mistral': 915, 'n_tokens_neox': 875, 'n_words': 201}