Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Firefox addon to fix broken webpage on the fly

At my job they use a "central login" facility on internal webpages. Whenever an internal webpage requires authentication, it forwards you to the central login, and after logging in, it sends you back to the page you were trying to view.

The very first line in the HTML for this central login page starts with this:

<!-- Encoding=ISO-8859-1;

But it never ends the comment, which means that all the HTML code in the whole document is actually commented out. This works fine in IE6 (which is the company standard - eek!), and it used to work in Firefox, but when I upgraded to Firefox 4, this no longer works (as it shouldn't - it is following standards).

I have saved the source and changed the first line to:

<!-- Encoding=ISO-8859-1; -->

And then the page will display, but since it is loaded from file:///, I can't submit my credentials to the main server...

I hate using IE6, but for all internal pages I am stuck with it because Firefox renders an empty page every time I get sent to the central login.

Is it possible to create a Firefox addon (or even a Greasemonkey script) to modify the HTML as it is coming into the browser before it gets rendered? I see tons of examples of modifying HTML once it is already loaded, but can't find anything to manipulate while loading it.

I guess I'm open to other solutions besides an addon, but that was the only thing I could think of. Also, we are not allowed to use Chrome or Safari, so that is out. And no, I cannot talk to the person in charge of the central login page and get them to change it. Proxying would probably be very difficult too because of the nature of the page.

Thanks in advance!

like image 453
BrianH Avatar asked May 11 '11 16:05

BrianH


2 Answers

Maybe a local Apache with mod_proxy and mod_subsitute could be used for this? Derived from an example from berkek.com:

<VirtualHost *>
  ServerAdmin [email protected]
  ServerName www.yourcompany.com
  <Proxy *>
    Order deny,allow
  </Proxy>
  ProxyRequests on
  ProxyPass / http://www.yourcompany.com/
  ProxyPassReverse / http://www.yourcompany.com/
  AddOutputFilterByType SUBSTITUTE text/html
  Substitute "s|<!-- Encoding=ISO-8859-1;|<!-- Encoding=ISO-8859-1; -->|n"
</VirtualHost>
like image 129
Tatu Lahtela Avatar answered Nov 06 '22 18:11

Tatu Lahtela


Here is a method I found:

The Fiddler Web Debugging Proxy. It is basically doing what @Tatu Lahtela suggested and what @alex suggested, only without apache.

Here are the steps I took:

  1. Download and install Fiddler
  2. Run Fiddler, which listens on port 8888 (by default)
  3. In the Fiddler options (HTTPS tab), check the "Decrypt HTTPS traffic" box
  4. In Fiddler, click the Rules Menu, then Customize Rules.
  5. In my text editor, I found the OnBeforeResponse function, and added this code:

    if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
      // Remove any compression or chunking    
      oSession.utilDecodeResponse();
    
      var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
    
      var oRegEx = /<!-- Encoding=ISO-8859-1; /gi;
      oBody = oBody.replace(oRegEx, "<!-- Encoding=ISO-8859-1;  -->");
    
      oSession.utilSetResponseBody(oBody);
    }
    
  6. In Fiddler, under Tools->Options->Connections tab, click "Copy browser Proxy Configuration URL" (This is the proxy PAC file that @Tatu Lahtela mentioned).

  7. In Firefox, Tools->Options->Advanced Tab->Network Tab->Settings, check "Automatic Proxy Configuration URL and paste in the URL from step #6.
  8. Surf the web!

I modified the PAC file to limit the sites that went to Fiddler like @Tatu Lahtela suggested.

This works for me, with minimal setup. A Firefox addon would be better for me since I wouldn't have to use an external program, but building one to do this seems pretty difficult.

Thanks to everyone who helped! I will mark @Tatu Lahtela 's answer as the accepted answer since that is how I was able to find what I needed.

like image 31
BrianH Avatar answered Nov 06 '22 19:11

BrianH