Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

Greasemonkey Force Secure Connection Script
Welcome, Guest. Please login or register.
December 02, 2008, 03:57:56 AM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Bits and Bytes  |  Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom  |  Greasemonkey Force Secure Connection Script « previous next »
Pages: [1]
Author Topic: Greasemonkey Force Secure Connection Script  (Read 1654 times)
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« on: July 09, 2006, 03:29:25 PM »

Known Issue : Will loop on sites that forcefully redirect from HTTPS back to HTTP for example Google. Google has been added to the exclude list for the time being until a workaround is made. Any site that has this problem remove it from the include list or add to the exclude list.

Code
Language: javascript (GeSHi-highlighted)
// ==UserScript==
// @name          Force Secure Connection
// @description  Forces A Domain To Use The HTTPS Scheme
// @include       *.example.com/*
// @exclude       http://*.google.com/*
// ==/UserScript==
 
/************************************************************************/
/* Copyright (c) 2006 by CrYpTiC MauleR                                 */
/* cryptic_mauler {at} expertsrt {dot} net                              */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
 
/* Check If Is NOT https */
if (/^http:/.test(document.URL))
{
   /* Make Redirect URL */
   const redirect = 'https' + document.URL.substr(4);
 
   /* Lets Check If New URL Will Load */
   GM_xmlhttpRequest(
   {
       /* Use Faster HEAD Method */
       method:'HEAD',
 
       /* Set Redirect URL */
       url:redirect,
 
       onload:function(http_request)
       {
           /* Check HTTP Status & State */
           if ((4 == http_request.readyState) && ('OK' == http_request.statusText))
           {
               /* Redirect To https */
               window.location.replace(redirect);
           }
       }
   })
}
else
{
   /* Make Regex For Matching Current Domain */
   const regex = new RegExp('^http://' + document.domain);
 
   function convert(elems, attribute)
   {
       /* Get Tags */
       var lnks = document.getElementsByTagName(elems);
 
       /* Loops Through All Elements */
       for (var i = 0; i < lnks.length; i++)
       {
           /* Get URL */
           var lnk = lnks[i].getAttribute(attribute);
 
           /* Check If Absolute URL For Current Domain */
           if (regex.test(lnk))
           {
               /* Make Absolute URL Use HTTPS */
               lnks[i].setAttribute(attribute, 'https' + lnk.substr(4));
           }
       }
   }
 
   /* Loop Through FORM & A Tags To Convert URL */
   convert('a', 'href');
   convert('form', 'action');
}

Above uses the GreaseMonkey extension for Firefox. It will force a domain(s) of your choice to use the HTTPS scheme.

It will first check if the scheme will break the site, in such cases where the site will not load HTTPS scheme for that domain, if it does it will redirect to the HTTPS version of that URL.

Another nice feature is once you are on a HTTPS page it will convert any absolute URLS for <a> (href) and <form> (action) tags for the current domain that is not HTTPS to HTTPS, by doing so it will prevent needless redirects and page accesses to the server. Thus happy server admin and happy surfer =o). More documentation on GreaseMonkey script available at Dive Into GreaseMonkey

If you are security cautious or a system admin having problems with people not using secure logins then this is the script for you. Any comments, or suggestions appreciated =o), safe surfing!
« Last Edit: May 05, 2007, 03:39:38 PM by CrYpTiC_MauleR » Logged

[x] Fight | www.crypticmauler.com
"You must be
nicholassolutions
Administrator
*
Offline Offline

Posts: 133



WWW
« Reply #1 on: July 09, 2006, 03:38:46 PM »

Cool Nick  :thumbup:
Logged
Pages: [1]
« previous next »
    Jump to: