From 7370b34fdbe86e2586643a64292f9c1c3cf814bc Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 8 Sep 2014 19:23:47 +0000 Subject: [PATCH] Disabling SSL enforcers was a REALLY bad idea. Adding special case for CloudFlare instead - it's a common enough deployment. --- Site5/Master-v5.master.cs | 9 ++++++--- Site5/Security/Login.aspx.cs | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Site5/Master-v5.master.cs b/Site5/Master-v5.master.cs index 9f9271ad..f99f9b71 100644 --- a/Site5/Master-v5.master.cs +++ b/Site5/Master-v5.master.cs @@ -61,8 +61,11 @@ namespace Swarmops // Check for SSL and force it - /* DISABLED - WORKS REALLY POORLY WHEN IN COMPLEX DEPLOYMENTS. MUST IMPROVE DETECTION MECHANISM - if (Request.Url.ToString().StartsWith("http://")) // only check client-side as many server sites de-SSL the connection before reaching the web server + string cloudFlareVisitorScheme = Request.Headers["CF-Visitor"]; + + bool cloudFlareSsl = (cloudFlareVisitorScheme == "\"scheme\":\"https\""? true: false); + + if (Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl) // only check client-side as many server sites de-SSL the connection before reaching the web server { if (!Request.Url.ToString().StartsWith("http://dev.swarmops.com/") && !Request.Url.ToString().StartsWith("http://sandbox.swarmops.com") && !Request.Url.ToString().StartsWith("http://localhost:") && !Request.Url.ToString().StartsWith("http://swarmops-")) { @@ -71,7 +74,7 @@ namespace Swarmops // Only force this if set to force it in database // TODO: Make admin init task } - }*/ + } Localize(); diff --git a/Site5/Security/Login.aspx.cs b/Site5/Security/Login.aspx.cs index 9b51247a..5f2dfe5b 100644 --- a/Site5/Security/Login.aspx.cs +++ b/Site5/Security/Login.aspx.cs @@ -30,16 +30,19 @@ namespace Swarmops.Pages.Security this.LabelLoginFailed.Visible = false; this.TextLogin.Focus(); - // Check for SSL + // Check for SSL and force it - /* DISABLE temporarily - if ((!Request.IsSecureConnection) && (!Request.Url.ToString().StartsWith("https://"))) // Both are necessary, as some reverse proxies will https-ify an original nonsecure connection + string cloudFlareVisitorScheme = Request.Headers["CF-Visitor"]; + + bool cloudFlareSsl = (cloudFlareVisitorScheme == "\"scheme\":\"https\""? true: false); + + if (Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl) // only check client-side as many server sites de-SSL the connection before reaching the web server { if (!Request.Url.ToString().StartsWith("http://dev.swarmops.com/") && !Request.Url.ToString().StartsWith("http://localhost:") && !Request.Url.ToString().StartsWith("http://swarmops-")) { Response.Redirect(Request.Url.ToString().Replace("http:", "https:")); } - } */ + } } protected void ButtonLogin_Click(object sender, EventArgs e)