Quellcode durchsuchen

Escapes html special chars and makes invitation field non-editable.

j8
yanas vor 11 Jahren
Ursprung
Commit
8ebe2d9468
3 geänderte Dateien mit 63 neuen und 31 gelöschten Zeilen
  1. 39
    27
      app.js
  2. 6
    4
      chat.js
  3. 18
    0
      util.js

+ 39
- 27
app.js Datei anzeigen

@@ -83,7 +83,8 @@ function doJoin() {
83 83
             roomnode = path.substr(1).toLowerCase();
84 84
         } else {
85 85
             roomnode = Math.random().toString(36).substr(2, 20);
86
-            window.history.pushState('VideoChat', 'Room: ' + roomnode, window.location.pathname + roomnode);
86
+            window.history.pushState('VideoChat',
87
+                    'Room: ' + roomnode, window.location.pathname + roomnode);
87 88
         }
88 89
     }
89 90
 
@@ -165,12 +166,14 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
165 166
     var remotes = document.getElementById('remoteVideos');
166 167
 
167 168
     if (data.peerjid) {
168
-        container  = document.getElementById('participant_' + Strophe.getResourceFromJid(data.peerjid));
169
+        container  = document.getElementById(
170
+                'participant_' + Strophe.getResourceFromJid(data.peerjid));
169 171
         if (!container) {
170 172
             console.warn('no container for', data.peerjid);
171 173
             // create for now...
172 174
             // FIXME: should be removed
173
-            container = addRemoteVideoContainer('participant_' + Strophe.getResourceFromJid(data.peerjid));
175
+            container = addRemoteVideoContainer(
176
+                    'participant_' + Strophe.getResourceFromJid(data.peerjid));
174 177
         } else {
175 178
             //console.log('found container for', data.peerjid);
176 179
         }
@@ -588,7 +591,7 @@ $(document).bind('presentationadded.muc', function (event, jid, presUrl, current
588 591
                 });
589 592
 
590 593
     $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
591
-                 
594
+
592 595
     preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
593 596
         console.log("prezi status", event.value);
594 597
         if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
@@ -897,10 +900,10 @@ function openLockDialog() {
897 900
                      if(v)
898 901
                      {
899 902
                         var lockKey = document.getElementById('lockKey');
900
-                     
903
+
901 904
                         if (lockKey.value)
902 905
                         {
903
-                            setSharedKey(lockKey.value);
906
+                            setSharedKey(Util.escapeHtml(lockKey.value));
904 907
                             lockRoom(true);
905 908
                         }
906 909
                      }
@@ -913,7 +916,8 @@ function openLockDialog() {
913 916
  * Opens the invite link dialog.
914 917
  */
915 918
 function openLinkDialog() {
916
-    $.prompt('<input id="inviteLinkRef" type="text" value="' + roomUrl + '" onclick="this.select();">',
919
+    $.prompt('<input id="inviteLinkRef" type="text" value="'
920
+            + encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
917 921
              {
918 922
              title: "Share this link with everyone you want to invite",
919 923
              persistent: false,
@@ -949,7 +953,7 @@ function openSettingsDialog() {
949 953
 
950 954
                         if ($('#requireNicknames').is(":checked"))
951 955
                         {
952
-                            // it is checked                        
956
+                            // it is checked
953 957
                         }
954 958
              /*
955 959
                         var lockKey = document.getElementById('lockKey');
@@ -986,7 +990,8 @@ function openPreziDialog() {
986 990
         });
987 991
     }
988 992
     else if (preziPlayer != null) {
989
-        $.prompt("Another participant is already sharing a Prezi. This conference allows only one Prezi at a time.",
993
+        $.prompt("Another participant is already sharing a Prezi." +
994
+                "This conference allows only one Prezi at a time.",
990 995
                  {
991 996
                  title: "Share a Prezi",
992 997
                  buttons: { "Ok": true},
@@ -1012,20 +1017,24 @@ function openPreziDialog() {
1012 1017
 
1013 1018
                     if (preziUrl.value)
1014 1019
                     {
1015
-                        if (preziUrl.value.indexOf('http://prezi.com/') != 0
1016
-                            && preziUrl.value.indexOf('https://prezi.com/') != 0)
1020
+                        var urlValue
1021
+                            = encodeURI(Util.escapeHtml(preziUrl.value));
1022
+
1023
+                        if (urlValue.indexOf('http://prezi.com/') != 0
1024
+                            && urlValue.indexOf('https://prezi.com/') != 0)
1017 1025
                         {
1018 1026
                             $.prompt.goToState('state1');
1019 1027
                             return false;
1020 1028
                         }
1021 1029
                         else {
1022
-                            var presIdTmp = preziUrl.value.substring(preziUrl.value.indexOf("prezi.com/") + 10);
1023
-                            if (presIdTmp.indexOf('/') < 2) {
1030
+                            var presIdTmp = urlValue.substring(urlValue.indexOf("prezi.com/") + 10);
1031
+                            if (!Util.isAlphanumeric(presIdTmp)
1032
+                                    || presIdTmp.indexOf('/') < 2) {
1024 1033
                                 $.prompt.goToState('state1');
1025 1034
                                 return false;
1026 1035
                             }
1027 1036
                             else {
1028
-                                connection.emuc.addPreziToPresence(preziUrl.value, 0);
1037
+                                connection.emuc.addPreziToPresence(urlValue, 0);
1029 1038
                                 connection.emuc.sendPresence();
1030 1039
                                 $.prompt.close();
1031 1040
                             }
@@ -1053,7 +1062,7 @@ function openPreziDialog() {
1053 1062
         };
1054 1063
 
1055 1064
         var myPrompt = jQuery.prompt(openPreziState);
1056
-        
1065
+
1057 1066
         myPrompt.on('impromptu:loaded', function(e) {
1058 1067
                     document.getElementById('preziUrl').focus();
1059 1068
                     });
@@ -1071,7 +1080,7 @@ function lockRoom(lock) {
1071 1080
         connection.emuc.lockRoom(sharedKey);
1072 1081
     else
1073 1082
         connection.emuc.lockRoom('');
1074
-    
1083
+
1075 1084
     updateLockButton();
1076 1085
 }
1077 1086
 
@@ -1202,6 +1211,8 @@ function toggleFullScreen() {
1202 1211
  * Shows the display name for the given video.
1203 1212
  */
1204 1213
 function showDisplayName(videoSpanId, displayName) {
1214
+    var escDisplayName = Util.escapeHtml(displayName);
1215
+
1205 1216
     var nameSpan = $('#' + videoSpanId + '>span.displayname');
1206 1217
 
1207 1218
     // If we already have a display name for this video.
@@ -1209,21 +1220,21 @@ function showDisplayName(videoSpanId, displayName) {
1209 1220
         var nameSpanElement = nameSpan.get(0);
1210 1221
 
1211 1222
         if (nameSpanElement.id == 'localDisplayName'
1212
-            && $('#localDisplayName').html() != displayName)
1213
-            $('#localDisplayName').html(displayName);
1223
+            && $('#localDisplayName').html() != escDisplayName)
1224
+            $('#localDisplayName').html(escDisplayName);
1214 1225
         else
1215
-            $('#' + videoSpanId + '_name').html(displayName);
1226
+            $('#' + videoSpanId + '_name').html(escDisplayName);
1216 1227
     }
1217 1228
     else {
1218 1229
         var editButton = null;
1230
+
1219 1231
         if (videoSpanId == 'localVideoContainer') {
1220 1232
             editButton = createEditDisplayNameButton();
1221 1233
         }
1222
-
1223
-        if (displayName.length) {
1234
+        if (escDisplayName.length) {
1224 1235
             nameSpan = document.createElement('span');
1225 1236
             nameSpan.className = 'displayname';
1226
-            nameSpan.innerHTML = displayName;
1237
+            nameSpan.innerHTML = escDisplayName;
1227 1238
             $('#' + videoSpanId)[0].appendChild(nameSpan);
1228 1239
         }
1229 1240
 
@@ -1233,13 +1244,14 @@ function showDisplayName(videoSpanId, displayName) {
1233 1244
         else {
1234 1245
             nameSpan.id = 'localDisplayName';
1235 1246
             $('#' + videoSpanId)[0].appendChild(editButton);
1236
-            
1247
+
1237 1248
             var editableText = document.createElement('input');
1238 1249
             editableText.className = 'displayname';
1239 1250
             editableText.id = 'editDisplayName';
1240 1251
 
1241
-            if (displayName.length)
1242
-                editableText.value = displayName.substring(0, displayName.indexOf(' (me)'));
1252
+            if (escDisplayName.length)
1253
+                editableText.value
1254
+                    = escDisplayName.substring(0, escDisplayName.indexOf(' (me)'));
1243 1255
 
1244 1256
             editableText.setAttribute('style', 'display:none;');
1245 1257
             editableText.setAttribute('placeholder', 'ex. Jane Pink');
@@ -1254,7 +1266,7 @@ function showDisplayName(videoSpanId, displayName) {
1254 1266
 
1255 1267
                 var inputDisplayNameHandler = function(name) {
1256 1268
                     if (nickname != name) {
1257
-                        nickname = name;
1269
+                        nickname = Util.escapeHtml(name);
1258 1270
                         window.localStorage.displayname = nickname;
1259 1271
                         connection.emuc.addDisplayNameToPresence(nickname);
1260 1272
                         connection.emuc.sendPresence();
@@ -1263,7 +1275,7 @@ function showDisplayName(videoSpanId, displayName) {
1263 1275
                     }
1264 1276
 
1265 1277
                     if (!$('#localDisplayName').is(":visible")) {
1266
-                        $('#localDisplayName').html(name + " (me)");
1278
+                        $('#localDisplayName').html(nickname + " (me)");
1267 1279
                         $('#localDisplayName').show();
1268 1280
                         $('#editDisplayName').hide();
1269 1281
                     }

+ 6
- 4
chat.js Datei anzeigen

@@ -19,7 +19,7 @@ var Chat = (function (my) {
19 19
         $('#nickinput').keydown(function(event) {
20 20
             if (event.keyCode == 13) {
21 21
                 event.preventDefault();
22
-                var val = this.value;
22
+                var val = Util.escapeHtml(this.value);
23 23
                 this.value = '';
24 24
                 if (!nickname) {
25 25
                     nickname = val;
@@ -38,7 +38,7 @@ var Chat = (function (my) {
38 38
         $('#usermsg').keydown(function(event) {
39 39
             if (event.keyCode == 13) {
40 40
                 event.preventDefault();
41
-                var message = this.value;
41
+                var message = Util.escapeHtml(this.value);
42 42
                 $('#usermsg').val('').trigger('autosize.resize');
43 43
                 this.focus();
44 44
                 connection.emuc.sendMessage(message, nickname);
@@ -78,10 +78,12 @@ var Chat = (function (my) {
78 78
         }
79 79
 
80 80
         //replace links and smileys
81
-        message = processReplacements(message);
81
+        var escMessage = Util.escapeHtml(message);
82
+        var escDisplayName = Util.escapeHtml(displayName);
83
+        message = processReplacements(escMessage);
82 84
 
83 85
         $('#chatconversation').append('<div class="' + divClassName + '"><b>'
84
-                                        + displayName + ': </b>'
86
+                                        + escDisplayName + ': </b>'
85 87
                                         + message + '</div>');
86 88
         $('#chatconversation').animate(
87 89
                 { scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);

+ 18
- 0
util.js Datei anzeigen

@@ -39,5 +39,23 @@ var Util = (function (my) {
39 39
         document.getElementById(id).play();
40 40
     };
41 41
 
42
+    /**
43
+     * Escapes the given text.
44
+     */
45
+    my.escapeHtml = function(unsafeText) {
46
+        return $('<div/>').text(unsafeText).html();
47
+    };
48
+
49
+    /**
50
+     * Indicates if the given string is an alphanumeric string.
51
+     * Note that some special characters are also allowed (-, _ , /) for the
52
+     * purpose of checking URIs. (FIXME: This should maybe moved to another not
53
+     * so generic method in the future.)
54
+     */
55
+    my.isAlphanumeric = function(unsafeText) {
56
+        var regex = /^[a-z0-9-_\/]+$/i;
57
+        return regex.test(unsafeText);
58
+    };
59
+
42 60
     return my;
43 61
 }(Util || {}));

Laden…
Abbrechen
Speichern