@reliabilityworks/analyzer-javascript 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/package.json +15 -0
- package/src/index.ts +69 -0
- package/test/smoke.test.js +16 -0
- package/tsconfig.json +8 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAElD,eAAO,MAAM,gBAAgB,EAAE,IAAI,EA8DlC,CAAA;AAED,wBAAgB,kBAAkB,IAAI,IAAI,EAAE,CAE3C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JAVASCRIPT_RULES = void 0;
|
|
4
|
+
exports.getJavaScriptRules = getJavaScriptRules;
|
|
5
|
+
exports.JAVASCRIPT_RULES = [
|
|
6
|
+
{
|
|
7
|
+
id: 'javascript/dangerous-eval',
|
|
8
|
+
severity: 'high',
|
|
9
|
+
title: 'Use of eval()',
|
|
10
|
+
description: 'eval() can execute arbitrary code and is often a sign of injection risk.',
|
|
11
|
+
matcher: {
|
|
12
|
+
type: 'regex',
|
|
13
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
14
|
+
pattern: '\\beval\\s*\\(',
|
|
15
|
+
message: 'eval() usage detected',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'javascript/dangerous-new-function',
|
|
20
|
+
severity: 'high',
|
|
21
|
+
title: 'Use of new Function()',
|
|
22
|
+
description: 'The Function constructor evaluates strings as code and can lead to injection.',
|
|
23
|
+
matcher: {
|
|
24
|
+
type: 'regex',
|
|
25
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
26
|
+
pattern: '\\bnew\\s+Function\\s*\\(',
|
|
27
|
+
message: 'new Function() usage detected',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'javascript/child-process-exec',
|
|
32
|
+
severity: 'high',
|
|
33
|
+
title: 'Use of child_process.exec/execSync',
|
|
34
|
+
description: 'Executing shell commands from application code can be risky, especially with user-controlled input.',
|
|
35
|
+
matcher: {
|
|
36
|
+
type: 'regex',
|
|
37
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
38
|
+
pattern: '\\bchild_process\\.(?:exec|execSync)\\s*\\(',
|
|
39
|
+
message: 'child_process.exec or child_process.execSync usage detected',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'javascript/tls-reject-unauthorized-disabled',
|
|
44
|
+
severity: 'critical',
|
|
45
|
+
title: 'TLS verification disabled',
|
|
46
|
+
description: 'Disabling TLS verification allows man-in-the-middle attacks.',
|
|
47
|
+
matcher: {
|
|
48
|
+
type: 'regex',
|
|
49
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
50
|
+
pattern: '\\bNODE_TLS_REJECT_UNAUTHORIZED\\s*=\\s*[\'"]?0[\'"]?',
|
|
51
|
+
message: 'NODE_TLS_REJECT_UNAUTHORIZED is set to 0',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'javascript/reject-unauthorized-false',
|
|
56
|
+
severity: 'high',
|
|
57
|
+
title: 'rejectUnauthorized set to false',
|
|
58
|
+
description: 'Setting rejectUnauthorized: false disables TLS certificate verification.',
|
|
59
|
+
matcher: {
|
|
60
|
+
type: 'regex',
|
|
61
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
62
|
+
pattern: '\\brejectUnauthorized\\s*:\\s*false\\b',
|
|
63
|
+
message: 'rejectUnauthorized appears to be set to false',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
function getJavaScriptRules() {
|
|
68
|
+
return exports.JAVASCRIPT_RULES;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAkEA,gDAEC;AAlEY,QAAA,gBAAgB,GAAW;IACtC;QACE,EAAE,EAAE,2BAA2B;QAC/B,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,eAAe;QACtB,WAAW,EAAE,0EAA0E;QACvF,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,sBAAsB,CAAC;YACnC,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,uBAAuB;SACjC;KACF;IACD;QACE,EAAE,EAAE,mCAAmC;QACvC,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EAAE,+EAA+E;QAC5F,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,sBAAsB,CAAC;YACnC,OAAO,EAAE,2BAA2B;YACpC,OAAO,EAAE,+BAA+B;SACzC;KACF;IACD;QACE,EAAE,EAAE,+BAA+B;QACnC,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,oCAAoC;QAC3C,WAAW,EACT,qGAAqG;QACvG,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,sBAAsB,CAAC;YACnC,OAAO,EAAE,6CAA6C;YACtD,OAAO,EAAE,6DAA6D;SACvE;KACF;IACD;QACE,EAAE,EAAE,6CAA6C;QACjD,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,2BAA2B;QAClC,WAAW,EAAE,8DAA8D;QAC3E,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,sBAAsB,CAAC;YACnC,OAAO,EAAE,uDAAuD;YAChE,OAAO,EAAE,0CAA0C;SACpD;KACF;IACD;QACE,EAAE,EAAE,sCAAsC;QAC1C,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,iCAAiC;QACxC,WAAW,EAAE,0EAA0E;QACvF,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,sBAAsB,CAAC;YACnC,OAAO,EAAE,wCAAwC;YACjD,OAAO,EAAE,+CAA+C;SACzD;KACF;CACF,CAAA;AAED,SAAgB,kBAAkB;IAChC,OAAO,wBAAgB,CAAA;AACzB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reliabilityworks/analyzer-javascript",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -p tsconfig.json",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"test": "pnpm build && node --test test",
|
|
10
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@reliabilityworks/core": "0.1.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Rule } from '@reliabilityworks/core'
|
|
2
|
+
|
|
3
|
+
export const JAVASCRIPT_RULES: Rule[] = [
|
|
4
|
+
{
|
|
5
|
+
id: 'javascript/dangerous-eval',
|
|
6
|
+
severity: 'high',
|
|
7
|
+
title: 'Use of eval()',
|
|
8
|
+
description: 'eval() can execute arbitrary code and is often a sign of injection risk.',
|
|
9
|
+
matcher: {
|
|
10
|
+
type: 'regex',
|
|
11
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
12
|
+
pattern: '\\beval\\s*\\(',
|
|
13
|
+
message: 'eval() usage detected',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'javascript/dangerous-new-function',
|
|
18
|
+
severity: 'high',
|
|
19
|
+
title: 'Use of new Function()',
|
|
20
|
+
description: 'The Function constructor evaluates strings as code and can lead to injection.',
|
|
21
|
+
matcher: {
|
|
22
|
+
type: 'regex',
|
|
23
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
24
|
+
pattern: '\\bnew\\s+Function\\s*\\(',
|
|
25
|
+
message: 'new Function() usage detected',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'javascript/child-process-exec',
|
|
30
|
+
severity: 'high',
|
|
31
|
+
title: 'Use of child_process.exec/execSync',
|
|
32
|
+
description:
|
|
33
|
+
'Executing shell commands from application code can be risky, especially with user-controlled input.',
|
|
34
|
+
matcher: {
|
|
35
|
+
type: 'regex',
|
|
36
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
37
|
+
pattern: '\\bchild_process\\.(?:exec|execSync)\\s*\\(',
|
|
38
|
+
message: 'child_process.exec or child_process.execSync usage detected',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'javascript/tls-reject-unauthorized-disabled',
|
|
43
|
+
severity: 'critical',
|
|
44
|
+
title: 'TLS verification disabled',
|
|
45
|
+
description: 'Disabling TLS verification allows man-in-the-middle attacks.',
|
|
46
|
+
matcher: {
|
|
47
|
+
type: 'regex',
|
|
48
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
49
|
+
pattern: '\\bNODE_TLS_REJECT_UNAUTHORIZED\\s*=\\s*[\'"]?0[\'"]?',
|
|
50
|
+
message: 'NODE_TLS_REJECT_UNAUTHORIZED is set to 0',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'javascript/reject-unauthorized-false',
|
|
55
|
+
severity: 'high',
|
|
56
|
+
title: 'rejectUnauthorized set to false',
|
|
57
|
+
description: 'Setting rejectUnauthorized: false disables TLS certificate verification.',
|
|
58
|
+
matcher: {
|
|
59
|
+
type: 'regex',
|
|
60
|
+
fileGlobs: ['**/*.{js,jsx,ts,tsx}'],
|
|
61
|
+
pattern: '\\brejectUnauthorized\\s*:\\s*false\\b',
|
|
62
|
+
message: 'rejectUnauthorized appears to be set to false',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
export function getJavaScriptRules(): Rule[] {
|
|
68
|
+
return JAVASCRIPT_RULES
|
|
69
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const assert = require('node:assert/strict')
|
|
2
|
+
const test = require('node:test')
|
|
3
|
+
|
|
4
|
+
test('analyzer exports javascript rules', async () => {
|
|
5
|
+
const mod = require('../dist/index.js')
|
|
6
|
+
assert.ok(mod)
|
|
7
|
+
|
|
8
|
+
assert.equal(typeof mod.getJavaScriptRules, 'function')
|
|
9
|
+
const rules = mod.getJavaScriptRules()
|
|
10
|
+
assert.ok(Array.isArray(rules))
|
|
11
|
+
assert.ok(rules.length > 0)
|
|
12
|
+
|
|
13
|
+
const ids = new Set(rules.map((r) => r.id))
|
|
14
|
+
assert.ok(ids.has('javascript/dangerous-eval'))
|
|
15
|
+
assert.ok(ids.has('javascript/tls-reject-unauthorized-disabled'))
|
|
16
|
+
})
|