tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug601429.js (1888B)


      1 // Tests whether characters above 0x7F decode to ASCII characters liable to
      2 // expose XSS vulnerabilities
      3 
      4 function run_test() {
      5  var failures = false;
      6  var decodingConverter = CreateScriptableConverter();
      7 
      8  var decoders = [
      9    "Big5",
     10    "Big5-HKSCS",
     11    "EUC-JP",
     12    "EUC-KR",
     13    "gb18030",
     14    "IBM866",
     15    "ISO-2022-JP",
     16    "ISO-8859-1",
     17    "ISO-8859-2",
     18    "ISO-8859-3",
     19    "ISO-8859-4",
     20    "ISO-8859-5",
     21    "ISO-8859-6",
     22    "ISO-8859-7",
     23    "ISO-8859-8",
     24    "ISO-8859-8-I",
     25    "ISO-8859-10",
     26    "ISO-8859-13",
     27    "ISO-8859-14",
     28    "ISO-8859-15",
     29    "ISO-8859-16",
     30    "KOI8-R",
     31    "KOI8-U",
     32    "Shift_JIS",
     33    "windows-1250",
     34    "windows-1251",
     35    "windows-1252",
     36    "windows-1253",
     37    "windows-1254",
     38    "windows-1255",
     39    "windows-1256",
     40    "windows-1257",
     41    "windows-1258",
     42    "windows-874",
     43    "macintosh",
     44    "x-mac-cyrillic",
     45    "x-user-defined",
     46    "UTF-8",
     47  ];
     48 
     49  var counter = 0;
     50  while (counter < decoders.length) {
     51    var charset = decoders[counter++];
     52    dump("testing " + counter + " " + charset + "\n");
     53 
     54    decodingConverter.charset = charset;
     55    for (var i = 0x80; i < 0x100; ++i) {
     56      var inString = String.fromCharCode(i);
     57      var outString;
     58      try {
     59        outString =
     60          decodingConverter.ConvertToUnicode(inString) +
     61          decodingConverter.Finish();
     62      } catch (e) {
     63        outString = String.fromCharCode(0xfffd);
     64      }
     65      for (var n = 0; n < outString.length; ++n) {
     66        var outChar = outString.charAt(n);
     67        if (outChar == "<" || outChar == ">" || outChar == "/") {
     68          dump(
     69            charset +
     70              " has a problem: " +
     71              escape(inString) +
     72              " decodes to '" +
     73              outString +
     74              "'\n"
     75          );
     76          failures = true;
     77        }
     78      }
     79    }
     80  }
     81  if (failures) {
     82    do_throw("test failed\n");
     83  }
     84 }