]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add a trivial checksum to prevent strange issues from typing errors in uio URL option.
authorChris Porter <redacted>
Sat, 24 Apr 2010 03:06:36 +0000 (04:06 +0100)
committerChris Porter <redacted>
Sat, 24 Apr 2010 03:06:36 +0000 (04:06 +0100)
js/jslib.js
js/ui/panes/options.js

index b61038dc6d7e290b056f24a283779f0a40c24fe5..bbf2c13642f497bcb4c75ce4bff5687b63c6f349 100644 (file)
@@ -293,6 +293,11 @@ qwebirc.util.b64Decode = function(data) {
 
   var output = [];
   var table = qwebirc.util.b64Table;
+  
+  /* grossly inefficient... so sue me */
+  while(data.length % 4 != 0)
+    data = data + "=";
+    
   for(var i=0;i<data.length;) {
     var enc1 = table.indexOf(data.charAt(i++));
     var enc2 = table.indexOf(data.charAt(i++));
index 2422f75e221d6b4960852e1ab97a9216bc1b33fc..402213ab0763ed1f02f2b3d025f3d28360cb7c09 100644 (file)
@@ -430,9 +430,11 @@ qwebirc.ui.SuppliedArgOptions = new Class({
   initialize: function(ui, arg) {
     var p = {};
     
-    if($defined(arg) && arg != "") {
-      var decoded = qwebirc.util.b64Decode(arg);
-      if(decoded)
+    if($defined(arg) && arg != "" && arg.length > 2) {
+      var checksum = arg.substr(arg.length - 2, 2);
+      var decoded = qwebirc.util.b64Decode(arg.substr(0, arg.length - 2));
+      
+      if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum))
         p = qwebirc.util.parseURI("?" + decoded);
     }
     
@@ -456,7 +458,9 @@ qwebirc.ui.SuppliedArgOptions = new Class({
         result.push(x.optionId + "=" + x.value);
     }.bind(this));
     
-    return qwebirc.util.b64Encode(result.join("&")).replaceAll("=", "");
+    var raw = result.join("&");
+    var checksum = new qwebirc.util.crypto.MD5().digest(raw).slice(0, 2);
+    return (qwebirc.util.b64Encode(raw)).replaceAll("=", "") + checksum;
   }
 });