Insecure cryptography Critical

Misuse of cryptography-related APIs can create security vulnerabilities. This includes algorithms with known weaknesses, certain padding modes, the lack of integrity checks, insufficiently large key sizes, and insecure combinations of the previous items.

Detector ID
typescript/insecure-cryptography@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1import https from 'https'
2function insecureCryptographyNoncompliant() {
3  var ciphers = [
4    `TLS_DH_anon_WITH_AES_256_GCM_SHA384`,
5    `TLS_AES_128_GCM_SHA256`,
6    `ECDHE-ECDSA-AES128-GCM-SHA256`,
7  ].join(":");
8  var options = {
9    hostname: "www.example.com",
10    port: 443,
11    path: "/",
12    method: "GET",
13    secureProtocol: "TLSv1_2_method",
14    // Noncompliant: insecure TLS cipher suite is used.
15    ciphers: ciphers,
16  };
17
18  var req = https.request(
19    options,
20    (res: { on: (arg0: string, arg1: (d: any) => void) => void }) => {
21      res.on("data", (d: any) => {
22        process.stdout.write(d);
23      });
24    },
25  );
26}

Compliant example

1import https from 'https'
2function insecureCryptographyCompliant() {
3  var ciphers = [
4    `TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256`,
5    `TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384`,
6    `TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256`,
7    `TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384`,
8    `TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256`,
9    `TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256`,
10    `TLS_AES_128_GCM_SHA256`,
11    `TLS_AES_256_GCM_SHA384`,
12    "!aNULL",
13    "!eNULL",
14    "!NULL",
15    "!DES",
16    "!RC4",
17    "!MD5",
18  ].join(":");
19  var options = {
20    hostname: "www.example.com",
21    port: 443,
22    path: "/",
23    method: "GET",
24    secureProtocol: "TLSv1_2_method",
25    // Compliant: secure TLS cipher suite is used.
26    ciphers: ciphers,
27  };
28
29  var req = https.request(
30    options,
31    (res: { on: (arg0: string, arg1: (d: any) => void) => void }) => {
32      res.on("data", (d: any) => {
33        process.stdout.write(d);
34      });
35    },
36  );
37}