Browse Source

deps: replace jsrsasign

We were only using a couple of utility functionss to parse tokens, not to
validate them in any way.
master
Saúl Ibarra Corretgé 4 years ago
parent
commit
70d8fe91c3
3 changed files with 50 additions and 12 deletions
  1. 3
    8
      package-lock.json
  2. 1
    1
      package.json
  3. 46
    3
      react/features/calendar-sync/web/microsoftCalendar.js

+ 3
- 8
package-lock.json View File

@@ -5313,9 +5313,9 @@
5313 5313
       "integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs="
5314 5314
     },
5315 5315
     "base64-js": {
5316
-      "version": "1.2.3",
5317
-      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.3.tgz",
5318
-      "integrity": "sha512-MsAhsUW1GxCdgYSO6tAfZrNapmUKk7mWx/k5mFY/A1gBtkaCaNapTg+FExCw1r9yeaZhqx/xPg43xgTFH6KL5w=="
5316
+      "version": "1.3.1",
5317
+      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
5318
+      "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
5319 5319
     },
5320 5320
     "basic-auth": {
5321 5321
       "version": "2.0.1",
@@ -10714,11 +10714,6 @@
10714 10714
         "verror": "1.10.0"
10715 10715
       }
10716 10716
     },
10717
-    "jsrsasign": {
10718
-      "version": "8.0.12",
10719
-      "resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-8.0.12.tgz",
10720
-      "integrity": "sha1-Iqu5ZW00owuVMENnIINeicLlwxY="
10721
-    },
10722 10717
     "jssha": {
10723 10718
       "version": "2.3.1",
10724 10719
       "resolved": "https://registry.npmjs.org/jssha/-/jssha-2.3.1.tgz",

+ 1
- 1
package.json View File

@@ -41,6 +41,7 @@
41 41
     "@tensorflow/tfjs": "1.5.1",
42 42
     "@webcomponents/url": "0.7.1",
43 43
     "amplitude-js": "4.5.2",
44
+    "base64-js": "1.3.1",
44 45
     "bc-css-flags": "3.0.0",
45 46
     "dropbox": "4.0.9",
46 47
     "i18n-iso-countries": "3.7.8",
@@ -54,7 +55,6 @@
54 55
     "jquery-i18next": "1.2.1",
55 56
     "js-md5": "0.6.1",
56 57
     "js-utils": "github:jitsi/js-utils#cf11996bd866fdb47326c59a5d3bc24be17282d4",
57
-    "jsrsasign": "8.0.12",
58 58
     "jwt-decode": "2.2.0",
59 59
     "lib-jitsi-meet": "github:jitsi/lib-jitsi-meet#3c8d411c96fdfa18c57111630f29880f3f72949e",
60 60
     "libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",

+ 46
- 3
react/features/calendar-sync/web/microsoftCalendar.js View File

@@ -1,7 +1,8 @@
1 1
 // @flow
2 2
 
3 3
 import { Client } from '@microsoft/microsoft-graph-client';
4
-import rs from 'jsrsasign';
4
+import base64js from 'base64-js';
5
+
5 6
 import type { Dispatch } from 'redux';
6 7
 
7 8
 import { createDeferred } from '../../../../modules/util/helpers';
@@ -452,8 +453,13 @@ function getValidatedTokenParts(tokenInfo, guids, appId) {
452 453
         return null;
453 454
     }
454 455
 
455
-    const payload
456
-         = rs.KJUR.jws.JWS.readSafeJSONString(rs.b64utoutf8(tokenParts[1]));
456
+    let payload;
457
+
458
+    try {
459
+        payload = JSON.parse(b64utoutf8(tokenParts[1]));
460
+    } catch (e) {
461
+        return null;
462
+    }
457 463
 
458 464
     if (payload.nonce !== guids.authNonce
459 465
         || payload.aud !== appId
@@ -596,3 +602,40 @@ function s4(num) {
596 602
 
597 603
     return ret;
598 604
 }
605
+
606
+/**
607
+ * Convert a Base64URL encoded string to a UTF-8 encoded string including CJK or Latin.
608
+ *
609
+ * @param {string} str - The string that needs conversion.
610
+ * @private
611
+ * @returns {string} - The converted string.
612
+ */
613
+function b64utoutf8(str) {
614
+    let s = str;
615
+
616
+    // Convert from Base64URL to Base64.
617
+
618
+    if (s.length % 4 === 2) {
619
+        s += '==';
620
+    } else if (s.length % 4 === 3) {
621
+        s += '=';
622
+    }
623
+
624
+    s = s.replace(/-/g, '+').replace(/_/g, '/');
625
+
626
+    // Convert Base64 to a byte array.
627
+
628
+    const bytes = base64js.toByteArray(s);
629
+
630
+    // Convert bytes to hex.
631
+
632
+    s = bytes.reduce((str_, byte) => str_ + byte.toString(16).padStart(2, '0'), '');
633
+
634
+    // Convert a hexadecimal string to a URLComponent string
635
+
636
+    s = s.replace(/(..)/g, '%$1');
637
+
638
+    // Decodee the URI component
639
+
640
+    return decodeURIComponent(s);
641
+}

Loading…
Cancel
Save