iamsecure 0.1.0 → 0.1.2
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/README.md +49 -2
- package/package.json +1 -1
- package/src/code/engine.js +13 -2
- package/src/report/terminal.js +4 -1
- package/src/scan.js +18 -20
- package/src/ui/index.html +2 -2
package/README.md
CHANGED
|
@@ -1,14 +1,61 @@
|
|
|
1
1
|
# iamsecure
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/iamsecure)
|
|
4
|
+
[](https://github.com/Ravindrabisht12/iamsecure/blob/main/LICENSE)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
**Find vulnerable dependencies and insecure code, ranked by how dangerous they are in *your* app, not just by CVSS.**
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx iamsecure # scan the current folder
|
|
12
|
+
npx iamsecure --ui # open the dashboard
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="docs/images/terminal.png" alt="iamsecure terminal report" width="680">
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
Every finding is ranked in two ways:
|
|
4
20
|
|
|
5
21
|
- **Real risk (worst first)** is the default. It shows how dangerous each issue is for *this* codebase.
|
|
6
22
|
- **Severity (high → low)** is the raw CVSS / rule severity, the same thing `npm audit` shows.
|
|
7
23
|
|
|
8
|
-
The two rankings differ a lot in practice.
|
|
24
|
+
The two rankings differ a lot in practice. A 9.8 CVE in a dev-only CLI tool drops to *low*. An 8.1 lodash advisory rises to *critical* because your API route calls the exact `_.template` function the advisory names.
|
|
9
25
|
|
|
10
26
|
It has **zero runtime dependencies** and needs only Node ≥ 18. A security scanner shouldn't add 300 packages to your supply chain.
|
|
11
27
|
|
|
28
|
+
### Example: OWASP Juice Shop
|
|
29
|
+
|
|
30
|
+
A scan of [OWASP Juice Shop](https://github.com/juice-shop/juice-shop), a deliberately vulnerable Node.js app:
|
|
31
|
+
|
|
32
|
+
| | critical | high | medium | low |
|
|
33
|
+
|---|---|---|---|---|
|
|
34
|
+
| By raw severity | 16 | 51 | 44 | 2 |
|
|
35
|
+
| **By real risk** | **16** | **40** | **44** | **13** |
|
|
36
|
+
|
|
37
|
+
It covered 1,181 packages and 377 source files in about 5 seconds, and found the app's planted SQL injection in `routes/login.ts`, its `eval`, its path traversal routes and 11 hard-coded secrets.
|
|
38
|
+
|
|
39
|
+
Twelve "high" findings dropped to medium or low:
|
|
40
|
+
- Nine are in `tar`, which is installed but never imported anywhere.
|
|
41
|
+
- The rest are in a dev-only build tool and a test file.
|
|
42
|
+
|
|
43
|
+
One "high" `jsonwebtoken` advisory rose to *critical*, because the server's auth code imports that package.
|
|
44
|
+
|
|
45
|
+
## Dashboard
|
|
46
|
+
|
|
47
|
+
`npx iamsecure --ui` opens a local dashboard. Its **Fix list** groups every issue into one action, explains it in plain language (what's wrong, what could happen, where it runs, how to fix) and gives the exact install command.
|
|
48
|
+
|
|
49
|
+
<p align="center">
|
|
50
|
+
<img src="docs/images/dashboard.png" alt="iamsecure dashboard: fix list" width="820">
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
The **Dependency tree** shows which of your direct dependencies brings in each vulnerable package. Its search answers "why is this installed?".
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<img src="docs/images/dependency-tree.png" alt="iamsecure dependency tree" width="820">
|
|
57
|
+
</p>
|
|
58
|
+
|
|
12
59
|
## Quick start
|
|
13
60
|
|
|
14
61
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iamsecure",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Scan a codebase for vulnerable dependencies and insecure code, ranked by real-world risk \u2014 with an optional AI second opinion.",
|
|
5
5
|
"author": "Ravindra Bisht",
|
|
6
6
|
"repository": {
|
package/src/code/engine.js
CHANGED
|
@@ -43,9 +43,20 @@ export function taintedNames(code, lang) {
|
|
|
43
43
|
return names;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The sink and its arguments: up to the `)` that closes the call (works without semicolons),
|
|
48
|
+
* or to the end of the line for sinks that aren't calls (`el.innerHTML = …`, `echo …`).
|
|
49
|
+
*/
|
|
46
50
|
function argsAfter(window, idx) {
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
const open = window.indexOf('(', idx);
|
|
52
|
+
const lineEnd = window.indexOf('\n', idx);
|
|
53
|
+
if (open === -1 || (lineEnd !== -1 && open > lineEnd)) return window.slice(idx, lineEnd === -1 ? undefined : lineEnd);
|
|
54
|
+
let depth = 0;
|
|
55
|
+
for (let i = open; i < window.length; i++) {
|
|
56
|
+
if (window[i] === '(') depth++;
|
|
57
|
+
else if (window[i] === ')' && --depth === 0) return window.slice(idx, i + 1);
|
|
58
|
+
}
|
|
59
|
+
return window.slice(idx);
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
const DYNAMIC = /\$\{|['"`]\s*\+|\+\s*['"`\w$]|\(\s*[\w$.[\]]+\s*[,)]|\(\s*\w+\s*\(|=\s*[\w$.[\]()]+\s*;?\s*$|\$\w+|\bf['"]|%\s*\(|\.format\(/;
|
package/src/report/terminal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import { sortFindings } from '../scan.js';
|
|
2
3
|
|
|
3
4
|
const useColor = (process.stdout.isTTY || !!process.env.FORCE_COLOR) && !process.env.NO_COLOR;
|
|
@@ -209,7 +210,9 @@ export function printReport(report, { sort = 'risk', limit = 30, min } = {}) {
|
|
|
209
210
|
out.push(c.gray('━'.repeat(width)));
|
|
210
211
|
const fw = report.project.framework;
|
|
211
212
|
const brand = ` ${c.bold('iamsecure')} ${c.gray('v' + report.tool.version)}`;
|
|
212
|
-
const
|
|
213
|
+
const home = os.homedir();
|
|
214
|
+
const shown = report.project.root.startsWith(home) ? '~' + report.project.root.slice(home.length) : report.project.root;
|
|
215
|
+
const where = c.gray(ellipsisStart(shown, Math.max(10, width - 30)));
|
|
213
216
|
out.push(brand + ' '.repeat(Math.max(2, width - vlen(brand) - vlen(where) - 2)) + where);
|
|
214
217
|
out.push(c.gray('━'.repeat(width)));
|
|
215
218
|
out.push('');
|
package/src/scan.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { loadProject } from
|
|
2
|
-
import { loadGraphs, scanDependencies, treeStats } from
|
|
3
|
-
import { LEVELS } from
|
|
4
|
-
import { analyzeSource } from
|
|
5
|
-
import { scanCode } from
|
|
6
|
-
import { scanSecrets } from
|
|
7
|
-
import { loadExploitData } from
|
|
8
|
-
import { scoreFindings } from
|
|
1
|
+
import { loadProject } from "./project.js";
|
|
2
|
+
import { loadGraphs, scanDependencies, treeStats } from "./deps/index.js";
|
|
3
|
+
import { LEVELS } from "./deps/cvss.js";
|
|
4
|
+
import { analyzeSource } from "./code/index.js";
|
|
5
|
+
import { scanCode } from "./code/engine.js";
|
|
6
|
+
import { scanSecrets } from "./code/secrets.js";
|
|
7
|
+
import { loadExploitData } from "./risk/exploit.js";
|
|
8
|
+
import { scoreFindings } from "./risk/score.js";
|
|
9
9
|
|
|
10
|
-
export const VERSION =
|
|
10
|
+
export const VERSION = "0.1.2";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Run a full scan and return a JSON-serialisable report.
|
|
@@ -37,14 +37,14 @@ export async function scan(root, opts = {}) {
|
|
|
37
37
|
|
|
38
38
|
let src = null;
|
|
39
39
|
if (code) {
|
|
40
|
-
log(
|
|
40
|
+
log("Analysing source code…");
|
|
41
41
|
src = analyzeSource(project);
|
|
42
42
|
stats.files = src.contexts.size;
|
|
43
43
|
findings.push(...scanCode(src), ...scanSecrets(src, project.root));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let exploitData;
|
|
47
|
-
const cves = [...new Set(findings.flatMap((f) => (f.advisory ? [f.advisory.id, ...f.advisory.aliases] : [])).filter((id) => id.startsWith(
|
|
47
|
+
const cves = [...new Set(findings.flatMap((f) => (f.advisory ? [f.advisory.id, ...f.advisory.aliases] : [])).filter((id) => id.startsWith("CVE-")))];
|
|
48
48
|
if (exploit && cves.length) {
|
|
49
49
|
log(`Checking ${cves.length} CVEs against CISA KEV + EPSS…`);
|
|
50
50
|
exploitData = await loadExploitData(cves);
|
|
@@ -54,7 +54,7 @@ export async function scan(root, opts = {}) {
|
|
|
54
54
|
scoreFindings(findings, { src, framework: project.framework, exploit: exploitData });
|
|
55
55
|
|
|
56
56
|
return {
|
|
57
|
-
tool: { name:
|
|
57
|
+
tool: { name: "iamsecure", version: VERSION },
|
|
58
58
|
scannedAt: new Date().toISOString(),
|
|
59
59
|
durationMs: Date.now() - started,
|
|
60
60
|
project: { name: project.name, root: project.root, framework: project.framework },
|
|
@@ -62,20 +62,20 @@ export async function scan(root, opts = {}) {
|
|
|
62
62
|
stats,
|
|
63
63
|
warnings,
|
|
64
64
|
summary: summarize(findings),
|
|
65
|
-
findings: sortFindings(findings,
|
|
65
|
+
findings: sortFindings(findings, "risk"),
|
|
66
66
|
tree: graphs.map(serializeGraph),
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export function sortFindings(findings, by =
|
|
71
|
-
const primary = by ===
|
|
72
|
-
const secondary = by ===
|
|
70
|
+
export function sortFindings(findings, by = "risk") {
|
|
71
|
+
const primary = by === "severity" ? "severityScore" : "riskScore";
|
|
72
|
+
const secondary = by === "severity" ? "riskScore" : "severityScore";
|
|
73
73
|
return [...findings].sort((a, b) => b[primary] - a[primary] || b[secondary] - a[secondary] || a.title.localeCompare(b.title));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export function summarize(findings) {
|
|
77
77
|
const count = (field) => Object.fromEntries(LEVELS.slice(0, 4).map((l) => [l, findings.filter((f) => f[field] === l).length]));
|
|
78
|
-
return { total: findings.length, bySeverity: count(
|
|
78
|
+
return { total: findings.length, bySeverity: count("severity"), byRisk: count("risk") };
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/** Compact tree for the dashboard: direct deps and the vulnerable packages beneath them. */
|
|
@@ -84,8 +84,6 @@ function serializeGraph(g) {
|
|
|
84
84
|
ecosystem: g.ecosystem,
|
|
85
85
|
lockfile: g.lockfile,
|
|
86
86
|
roots: g.roots.map((r) => ({ name: r.name, key: r.key, dev: r.dev, workspace: r.workspace })),
|
|
87
|
-
nodes: Object.fromEntries(
|
|
88
|
-
[...g.nodes.values()].filter((n) => !n.local).map((n) => [n.key, { deps: [...n.deps], prod: !!n.prod }]),
|
|
89
|
-
),
|
|
87
|
+
nodes: Object.fromEntries([...g.nodes.values()].filter((n) => !n.local).map((n) => [n.key, { deps: [...n.deps], prod: !!n.prod }])),
|
|
90
88
|
};
|
|
91
89
|
}
|
package/src/ui/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>iamsecure report</title>
|
|
7
|
-
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%
|
|
7
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23142b3b' d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z'/%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' d='m8.5 12 2.5 2.5 4.5-5'/%3E%3C/svg%3E">
|
|
8
8
|
<style>
|
|
9
9
|
:root {
|
|
10
10
|
--bg: #ffffff; --strip: #0f2b3d; --text: #142b3b; --muted: #5b6b78; --faint: #8795a1;
|
|
@@ -821,7 +821,7 @@ function nodeHtml(g, key, path, { root = null } = {}) {
|
|
|
821
821
|
const belowOnly = under.size - (v ? 1 : 0);
|
|
822
822
|
const kids = kidsOf(g, key, path);
|
|
823
823
|
const node = g.nodes[key];
|
|
824
|
-
const worst =
|
|
824
|
+
const worst = worstOf(under); // the card edge shows the worst issue anywhere in this branch
|
|
825
825
|
const bits = [
|
|
826
826
|
kids.length ? `<button class="tv-tog" type="button" aria-expanded="false" aria-label="Show what ${esc(name)} depends on">›</button>` : '<span class="tv-leaf"></span>',
|
|
827
827
|
dot(v ? v.worst : under.size ? 'muted' : 'ok'),
|