summaryrefslogtreecommitdiffstats
path: root/debian/patches/CVE-2021-3427_2.patch
blob: ec1edbefae294b66ee531bae6028c602a99e608d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
commit 8ece036770484e170d5a728cdb25062088068f71
Author: Calum Lind <calumlind+deluge@gmail.com>
Date:   Mon Feb 14 10:23:19 2022 +0000

    [WebUI] Move HTML entity encoding to client
    
    We should not be mangling the torrent data in the JSON API since this
    can have unintended consquences with names and filepaths that can be
    edited. If we escape those symbols in the JSON API then the data no
    longer matches that stored by core. Therefore shift the encoding to the
    client and consider dealing separetely with these entities when the user
    first adds a torrent.
    
    * Created a modified htmlEncode in Deluge Formatter based on extjs
    method that also encodes single quotes.
    * Removed renderers in ListViews since only templates specified via tpl
    are used and any render attribute specified was a no-op.
    * Removed old buggy escapeHtml
    
    Resolves: https://dev.deluge-torrent.org/ticket/3459
    Ref: https://docs.sencha.com/extjs/6.5.3/modern/src/String.js.html#Ext.String-method-htmlEncode
    Ref: https://docs.sencha.com/extjs/3.4.0/source/Format.html#Ext-util-Format-method-htmlEncode

diff --git a/deluge/ui/web/js/deluge-all/Deluge.js b/deluge/ui/web/js/deluge-all/Deluge.js
index 86cae6d89..260ad978f 100644
--- a/deluge/ui/web/js/deluge-all/Deluge.js
+++ b/deluge/ui/web/js/deluge-all/Deluge.js
@@ -25,11 +25,6 @@ Ext.state.Manager.setProvider(
 // Add some additional functions to ext and setup some of the
 // configurable parameters
 Ext.apply(Ext, {
-    escapeHTML: function (text) {
-        text = String(text).replace('<', '&lt;').replace('>', '&gt;');
-        return text.replace('&', '&amp;');
-    },
-
     isObjectEmpty: function (obj) {
         for (var i in obj) {
             return false;
diff --git a/deluge/ui/web/js/deluge-all/Formatters.js b/deluge/ui/web/js/deluge-all/Formatters.js
index 443bfdf56..6b09abee5 100644
--- a/deluge/ui/web/js/deluge-all/Formatters.js
+++ b/deluge/ui/web/js/deluge-all/Formatters.js
@@ -15,7 +15,23 @@
  * @version 1.3
  * @singleton
  */
-Deluge.Formatters = {
+Deluge.Formatters = (function () {
+    var charToEntity = {
+        '&': '&amp;',
+        '>': '&gt;',
+        '<': '&lt;',
+        '"': '&quot;',
+        "'": '&#39;',
+    };
+
+    var charToEntityRegex = new RegExp(
+        '(' + Object.keys(charToEntity).join('|') + ')',
+        'g'
+    );
+    var htmlEncodeReplaceFn = function (match, capture) {
+        return charToEntity[capture];
+    };
+
     /**
      * Formats a date string in the date representation of the current locale,
      * based on the systems timezone.
@@ -24,154 +40,162 @@ Deluge.Formatters = {
      * @return {String} a string in the date representation of the current locale
      * or "" if seconds < 0.
      */
-    date: function (timestamp) {
-        function zeroPad(num, count) {
-            var numZeropad = num + '';
-            while (numZeropad.length < count) {
-                numZeropad = '0' + numZeropad;
+    return (Formatters = {
+        date: function (timestamp) {
+            function zeroPad(num, count) {
+                var numZeropad = num + '';
+                while (numZeropad.length < count) {
+                    numZeropad = '0' + numZeropad;
+                }
+                return numZeropad;
+            }
+            timestamp = timestamp * 1000;
+            var date = new Date(timestamp);
+            return String.format(
+                '{0}/{1}/{2} {3}:{4}:{5}',
+                zeroPad(date.getDate(), 2),
+                zeroPad(date.getMonth() + 1, 2),
+                date.getFullYear(),
+                zeroPad(date.getHours(), 2),
+                zeroPad(date.getMinutes(), 2),
+                zeroPad(date.getSeconds(), 2)
+            );
+        },
+
+        /**
+         * Formats the bytes value into a string with KiB, MiB or GiB units.
+         *
+         * @param {Number} bytes the filesize in bytes
+         * @param {Boolean} showZero pass in true to displays 0 values
+         * @return {String} formatted string with KiB, MiB or GiB units.
+         */
+        size: function (bytes, showZero) {
+            if (!bytes && !showZero) return '';
+            bytes = bytes / 1024.0;
+
+            if (bytes < 1024) {
+                return bytes.toFixed(1) + ' KiB';
+            } else {
+                bytes = bytes / 1024;
             }
-            return numZeropad;
-        }
-        timestamp = timestamp * 1000;
-        var date = new Date(timestamp);
-        return String.format(
-            '{0}/{1}/{2} {3}:{4}:{5}',
-            zeroPad(date.getDate(), 2),
-            zeroPad(date.getMonth() + 1, 2),
-            date.getFullYear(),
-            zeroPad(date.getHours(), 2),
-            zeroPad(date.getMinutes(), 2),
-            zeroPad(date.getSeconds(), 2)
-        );
-    },
-
-    /**
-     * Formats the bytes value into a string with KiB, MiB or GiB units.
-     *
-     * @param {Number} bytes the filesize in bytes
-     * @param {Boolean} showZero pass in true to displays 0 values
-     * @return {String} formatted string with KiB, MiB or GiB units.
-     */
-    size: function (bytes, showZero) {
-        if (!bytes && !showZero) return '';
-        bytes = bytes / 1024.0;
-
-        if (bytes < 1024) {
-            return bytes.toFixed(1) + ' KiB';
-        } else {
-            bytes = bytes / 1024;
-        }
-
-        if (bytes < 1024) {
-            return bytes.toFixed(1) + ' MiB';
-        } else {
-            bytes = bytes / 1024;
-        }
-
-        return bytes.toFixed(1) + ' GiB';
-    },
-
-    /**
-     * Formats the bytes value into a string with K, M or G units.
-     *
-     * @param {Number} bytes the filesize in bytes
-     * @param {Boolean} showZero pass in true to displays 0 values
-     * @return {String} formatted string with K, M or G units.
-     */
-    sizeShort: function (bytes, showZero) {
-        if (!bytes && !showZero) return '';
-        bytes = bytes / 1024.0;
 
-        if (bytes < 1024) {
-            return bytes.toFixed(1) + ' K';
-        } else {
-            bytes = bytes / 1024;
-        }
+            if (bytes < 1024) {
+                return bytes.toFixed(1) + ' MiB';
+            } else {
+                bytes = bytes / 1024;
+            }
 
-        if (bytes < 1024) {
-            return bytes.toFixed(1) + ' M';
-        } else {
-            bytes = bytes / 1024;
-        }
+            return bytes.toFixed(1) + ' GiB';
+        },
+
+        /**
+         * Formats the bytes value into a string with K, M or G units.
+         *
+         * @param {Number} bytes the filesize in bytes
+         * @param {Boolean} showZero pass in true to displays 0 values
+         * @return {String} formatted string with K, M or G units.
+         */
+        sizeShort: function (bytes, showZero) {
+            if (!bytes && !showZero) return '';
+            bytes = bytes / 1024.0;
+
+            if (bytes < 1024) {
+                return bytes.toFixed(1) + ' K';
+            } else {
+                bytes = bytes / 1024;
+            }
 
-        return bytes.toFixed(1) + ' G';
-    },
+            if (bytes < 1024) {
+                return bytes.toFixed(1) + ' M';
+            } else {
+                bytes = bytes / 1024;
+            }
 
-    /**
-     * Formats a string to display a transfer speed utilizing {@link #size}
-     *
-     * @param {Number} bytes the number of bytes per second
-     * @param {Boolean} showZero pass in true to displays 0 values
-     * @return {String} formatted string with KiB, MiB or GiB units.
-     */
-    speed: function (bytes, showZero) {
-        return !bytes && !showZero ? '' : fsize(bytes, showZero) + '/s';
-    },
+            return bytes.toFixed(1) + ' G';
+        },
+
+        /**
+         * Formats a string to display a transfer speed utilizing {@link #size}
+         *
+         * @param {Number} bytes the number of bytes per second
+         * @param {Boolean} showZero pass in true to displays 0 values
+         * @return {String} formatted string with KiB, MiB or GiB units.
+         */
+        speed: function (bytes, showZero) {
+            return !bytes && !showZero ? '' : fsize(bytes, showZero) + '/s';
+        },
+
+        /**
+         * Formats a string to show time in a human readable form.
+         *
+         * @param {Number} time the number of seconds
+         * @return {String} a formatted time string. will return '' if seconds == 0
+         */
+        timeRemaining: function (time) {
+            if (time <= 0) {
+                return '&infin;';
+            }
+            time = time.toFixed(0);
+            if (time < 60) {
+                return time + 's';
+            } else {
+                time = time / 60;
+            }
 
-    /**
-     * Formats a string to show time in a human readable form.
-     *
-     * @param {Number} time the number of seconds
-     * @return {String} a formatted time string. will return '' if seconds == 0
-     */
-    timeRemaining: function (time) {
-        if (time <= 0) {
-            return '&infin;';
-        }
-        time = time.toFixed(0);
-        if (time < 60) {
-            return time + 's';
-        } else {
-            time = time / 60;
-        }
-
-        if (time < 60) {
-            var minutes = Math.floor(time);
-            var seconds = Math.round(60 * (time - minutes));
-            if (seconds > 0) {
-                return minutes + 'm ' + seconds + 's';
+            if (time < 60) {
+                var minutes = Math.floor(time);
+                var seconds = Math.round(60 * (time - minutes));
+                if (seconds > 0) {
+                    return minutes + 'm ' + seconds + 's';
+                } else {
+                    return minutes + 'm';
+                }
             } else {
-                return minutes + 'm';
+                time = time / 60;
             }
-        } else {
-            time = time / 60;
-        }
-
-        if (time < 24) {
-            var hours = Math.floor(time);
-            var minutes = Math.round(60 * (time - hours));
-            if (minutes > 0) {
-                return hours + 'h ' + minutes + 'm';
+
+            if (time < 24) {
+                var hours = Math.floor(time);
+                var minutes = Math.round(60 * (time - hours));
+                if (minutes > 0) {
+                    return hours + 'h ' + minutes + 'm';
+                } else {
+                    return hours + 'h';
+                }
             } else {
-                return hours + 'h';
+                time = time / 24;
             }
-        } else {
-            time = time / 24;
-        }
-
-        var days = Math.floor(time);
-        var hours = Math.round(24 * (time - days));
-        if (hours > 0) {
-            return days + 'd ' + hours + 'h';
-        } else {
-            return days + 'd';
-        }
-    },
 
-    /**
-     * Simply returns the value untouched, for when no formatting is required.
-     *
-     * @param {Mixed} value the value to be displayed
-     * @return the untouched value.
-     */
-    plain: function (value) {
-        return value;
-    },
-
-    cssClassEscape: function (value) {
-        return value.toLowerCase().replace('.', '_');
-    },
-};
+            var days = Math.floor(time);
+            var hours = Math.round(24 * (time - days));
+            if (hours > 0) {
+                return days + 'd ' + hours + 'h';
+            } else {
+                return days + 'd';
+            }
+        },
+
+        /**
+         * Simply returns the value untouched, for when no formatting is required.
+         *
+         * @param {Mixed} value the value to be displayed
+         * @return the untouched value.
+         */
+        plain: function (value) {
+            return value;
+        },
+
+        cssClassEscape: function (value) {
+            return value.toLowerCase().replace('.', '_');
+        },
+
+        htmlEncode: function (value) {
+            return !value
+                ? value
+                : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
+        },
+    });
+})();
 var fsize = Deluge.Formatters.size;
 var fsize_short = Deluge.Formatters.sizeShort;
 var fspeed = Deluge.Formatters.speed;
@@ -179,3 +203,4 @@ var ftime = Deluge.Formatters.timeRemaining;
 var fdate = Deluge.Formatters.date;
 var fplain = Deluge.Formatters.plain;
 Ext.util.Format.cssClassEscape = Deluge.Formatters.cssClassEscape;
+Ext.util.Format.htmlEncode = Deluge.Formatters.htmlEncode;
diff --git a/deluge/ui/web/js/deluge-all/add/AddWindow.js b/deluge/ui/web/js/deluge-all/add/AddWindow.js
index 771543de3..f5f2fdf07 100644
--- a/deluge/ui/web/js/deluge-all/add/AddWindow.js
+++ b/deluge/ui/web/js/deluge-all/add/AddWindow.js
@@ -64,20 +64,6 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, {
         this.addButton(_('Cancel'), this.onCancelClick, this);
         this.addButton(_('Add'), this.onAddClick, this);
 
-        function torrentRenderer(value, p, r) {
-            if (r.data['info_hash']) {
-                return String.format(
-                    '<div class="x-deluge-add-torrent-name">{0}</div>',
-                    value
-                );
-            } else {
-                return String.format(
-                    '<div class="x-deluge-add-torrent-name-loading">{0}</div>',
-                    value
-                );
-            }
-        }
-
         this.list = new Ext.list.ListView({
             store: new Ext.data.SimpleStore({
                 fields: [
@@ -91,7 +77,6 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, {
                     id: 'torrent',
                     width: 150,
                     sortable: true,
-                    renderer: torrentRenderer,
                     dataIndex: 'text',
                     tpl: new Ext.XTemplate(
                         '<div class="x-deluge-add-torrent-name">{text:htmlEncode}</div>'
diff --git a/deluge/ui/web/js/deluge-all/preferences/PreferencesWindow.js b/deluge/ui/web/js/deluge-all/preferences/PreferencesWindow.js
index ed2abdcdc..4cfed016b 100644
--- a/deluge/ui/web/js/deluge-all/preferences/PreferencesWindow.js
+++ b/deluge/ui/web/js/deluge-all/preferences/PreferencesWindow.js
@@ -46,7 +46,6 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, {
             columns: [
                 {
                     id: 'name',
-                    renderer: fplain,
                     dataIndex: 'name',
                 },
             ],
diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py
index e16c440ed..c487ddf3c 100644
--- a/deluge/ui/web/json_api.py
+++ b/deluge/ui/web/json_api.py
@@ -13,7 +13,6 @@
 import tempfile
 from base64 import b64encode
 from types import FunctionType
-from xml.sax.saxutils import escape as xml_escape
 
 from twisted.internet import defer, reactor
 from twisted.internet.defer import Deferred, DeferredList
@@ -375,8 +374,6 @@ class WebApi(JSONComponent):
     methods available from the core RPC.
     """
 
-    XSS_VULN_KEYS = ['name', 'message', 'comment', 'tracker_status', 'peers']
-
     def __init__(self):
         super().__init__('Web', depend=['SessionProxy'])
         self.hostlist = HostList()
@@ -581,7 +578,7 @@ def _on_got_files(self, torrent, d):
         paths = []
         info = {}
         for index, torrent_file in enumerate(files):
-            path = xml_escape(torrent_file['path'])
+            path = torrent_file['path']
             paths.append(path)
             torrent_file['progress'] = file_progress[index]
             torrent_file['priority'] = file_priorities[index]
@@ -618,25 +615,10 @@ def walk(path, item):
         file_tree.walk(walk)
         d.callback(file_tree.get_tree())
 
-    def _on_torrent_status(self, torrent, d):
-        for key in self.XSS_VULN_KEYS:
-            try:
-                if key == 'peers':
-                    for peer in torrent[key]:
-                        peer['client'] = xml_escape(peer['client'])
-                else:
-                    torrent[key] = xml_escape(torrent[key])
-            except KeyError:
-                pass
-        d.callback(torrent)
-
     @export
     def get_torrent_status(self, torrent_id, keys):
         """Get the status for a torrent, filtered by status keys."""
-        main_deferred = Deferred()
-        d = component.get('SessionProxy').get_torrent_status(torrent_id, keys)
-        d.addCallback(self._on_torrent_status, main_deferred)
-        return main_deferred
+        return component.get('SessionProxy').get_torrent_status(torrent_id, keys)
 
     @export
     def get_torrent_files(self, torrent_id):