sentrion 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +134 -2
- package/bin/sentrion.js +11 -0
- package/lib/cli.js +117 -0
- package/lib/cmd-allow.js +16 -0
- package/lib/cmd-doctor.js +40 -0
- package/lib/cmd-init.js +26 -0
- package/lib/cmd-mode.js +22 -0
- package/lib/cmd-rules.js +51 -0
- package/lib/cmd-scan.js +58 -0
- package/lib/cmd-shell-init.js +28 -0
- package/lib/cmd-test.js +26 -0
- package/lib/cmd-trust.js +53 -0
- package/lib/cmd-update.js +59 -0
- package/lib/data/malware.json +56 -0
- package/lib/data/typosquats.json +13 -0
- package/lib/guard.js +246 -0
- package/lib/hook.js +257 -0
- package/lib/policy.js +109 -0
- package/lib/proxy.js +61 -0
- package/lib/py/sitecustomize.py +167 -0
- package/lib/report.js +131 -0
- package/lib/rules.js +43 -0
- package/lib/scan.js +131 -0
- package/lib/sensors.js +112 -0
- package/lib/store.js +32 -0
- package/lib/ui.js +63 -0
- package/package.json +43 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 imeerai — imeer.ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sentrion
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sentrion is a runtime security guard for developers. Run commands through
|
|
4
|
+
Sentrion to block malicious package scripts, credential theft, backdoors,
|
|
5
|
+
network abuse, and other risky behavior.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g sentrion
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install it locally in a project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i sentrion
|
|
17
|
+
npx sentrion --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Node.js 18 or newer.
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
sentrion npm install express
|
|
26
|
+
sentrion pnpm add zod
|
|
27
|
+
sentrion pip install requests
|
|
28
|
+
sentrion python3 app.py
|
|
29
|
+
sentrion scan ./project
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`scan` checks a package or project without executing it.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Package managers
|
|
38
|
+
sentrion npm install express
|
|
39
|
+
sentrion pnpm add zod
|
|
40
|
+
sentrion yarn add zod
|
|
41
|
+
sentrion bun add zod
|
|
42
|
+
sentrion npx create-react-app my-app
|
|
43
|
+
|
|
44
|
+
# Python package managers
|
|
45
|
+
sentrion pip install requests
|
|
46
|
+
sentrion uv add requests
|
|
47
|
+
sentrion poetry add requests
|
|
48
|
+
|
|
49
|
+
# Run code
|
|
50
|
+
sentrion python3 app.py
|
|
51
|
+
sentrion node app.js
|
|
52
|
+
sentrion run -- node server.js
|
|
53
|
+
|
|
54
|
+
# Scan
|
|
55
|
+
sentrion scan express@4.21.2
|
|
56
|
+
sentrion scan ./project
|
|
57
|
+
|
|
58
|
+
# Reports
|
|
59
|
+
sentrion report --last
|
|
60
|
+
sentrion rules
|
|
61
|
+
sentrion doctor
|
|
62
|
+
sentrion --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Every command supports `--json` for machine-readable output and `--quiet` for
|
|
66
|
+
minimal output.
|
|
67
|
+
|
|
68
|
+
## Modes
|
|
69
|
+
|
|
70
|
+
| Mode | Behavior |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `prompt` | Pause and ask whether to kill, allow once, or trust |
|
|
73
|
+
| `enforce` | Block risky actions without prompting |
|
|
74
|
+
| `audit` | Record risky actions without blocking |
|
|
75
|
+
| `learn` | Observe behavior and suggest trust rules |
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
sentrion mode audit
|
|
79
|
+
sentrion mode enforce
|
|
80
|
+
sentrion --mode audit npm install express
|
|
81
|
+
sentrion --ci npm install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
In CI, use `--ci` for non-interactive behavior. If Sentrion blocks or needs a
|
|
85
|
+
decision, the command exits with status `87`.
|
|
86
|
+
|
|
87
|
+
## Policy
|
|
88
|
+
|
|
89
|
+
Sentrion reads policy from:
|
|
90
|
+
|
|
91
|
+
1. Built-in defaults
|
|
92
|
+
2. `~/.sentrion/policy.json`
|
|
93
|
+
3. `./.sentrion.json`
|
|
94
|
+
|
|
95
|
+
Project policy can be stricter, but cannot disable protection.
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"mode": "prompt",
|
|
100
|
+
"install": {
|
|
101
|
+
"allowHosts": ["registry.npmjs.org", "pypi.org"],
|
|
102
|
+
"minPackageAgeHours": 48
|
|
103
|
+
},
|
|
104
|
+
"rules": {
|
|
105
|
+
"SCAN-02": "warn"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Create a project policy file:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
sentrion init
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Common Commands
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
sentrion trust esbuild@^0.24
|
|
120
|
+
sentrion allow NET-02
|
|
121
|
+
sentrion update
|
|
122
|
+
sentrion policy show
|
|
123
|
+
sentrion shell-init
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- `trust` approves a package and behavior narrowly.
|
|
127
|
+
- `allow` changes the behavior of a specific rule.
|
|
128
|
+
- `update` refreshes package security data.
|
|
129
|
+
- `policy show` prints the active policy.
|
|
130
|
+
- `shell-init` prints shell aliases for commands such as `npm`, `pip`, and
|
|
131
|
+
`python`.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT License
|
package/bin/sentrion.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// Sentrion CLI entry. by imeerai — MIT.
|
|
4
|
+
const { main } = require('../lib/cli.js');
|
|
5
|
+
|
|
6
|
+
main(process.argv)
|
|
7
|
+
.then((code) => process.exit(typeof code === 'number' ? code : 0))
|
|
8
|
+
.catch((err) => {
|
|
9
|
+
console.error('sentrion: ' + (err && err.message ? err.message : err));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
});
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { c, tag } = require('./ui.js');
|
|
4
|
+
const pkg = require('../package.json');
|
|
5
|
+
|
|
6
|
+
const HELP = `
|
|
7
|
+
${tag()} v${pkg.version} a live guard for developer machines
|
|
8
|
+
|
|
9
|
+
${c.bold('USAGE')}
|
|
10
|
+
sentrion <command> [args...] run any command under the guard
|
|
11
|
+
sentrion <subcommand> [options]
|
|
12
|
+
|
|
13
|
+
${c.bold('GUARD ANY COMMAND')} ${c.dim('(scan, watch, decide, live)')}
|
|
14
|
+
sentrion npm install express guard a package install
|
|
15
|
+
sentrion pnpm add zod also yarn, bun, npx, pnpx, bunx
|
|
16
|
+
sentrion pip install requests also uv, poetry, pipx
|
|
17
|
+
sentrion python3 app.py the fake-interview case
|
|
18
|
+
sentrion node server.js
|
|
19
|
+
sentrion run -- <cmd...> explicit form (use after flags)
|
|
20
|
+
|
|
21
|
+
${c.bold('INSPECT BEFORE RUNNING')}
|
|
22
|
+
sentrion scan <package[@version]> static check of a package, nothing runs
|
|
23
|
+
sentrion scan . static check of this repo/clone
|
|
24
|
+
sentrion test -- <cmd...> run in a throwaway sandbox (enforce + temp home)
|
|
25
|
+
|
|
26
|
+
${c.bold('DECISIONS & EVIDENCE')}
|
|
27
|
+
sentrion report [--last|<id>|--all] what happened and why it was blocked
|
|
28
|
+
sentrion report <id> --format sarif export for CI code scanning (also --json)
|
|
29
|
+
sentrion rules [<id>] list the rule set, or show one rule
|
|
30
|
+
sentrion policy [show|path] the effective, merged policy
|
|
31
|
+
|
|
32
|
+
${c.bold('TRUST & SETUP')}
|
|
33
|
+
sentrion trust <pkg[@range]> allow one package's scripts (narrow, pinned)
|
|
34
|
+
sentrion untrust <pkg> remove a trust entry
|
|
35
|
+
sentrion allow <RULE-ID> set one rule to allow in your policy
|
|
36
|
+
sentrion mode <prompt|enforce|audit|learn> set your default mode
|
|
37
|
+
sentrion init scaffold ./.sentrion.json for a repo
|
|
38
|
+
sentrion update refresh the malware + typosquat lists
|
|
39
|
+
sentrion shell-init [bash|zsh|pwsh] print aliases (npm -> sentrion npm ...)
|
|
40
|
+
sentrion doctor what this OS lets Sentrion see and block
|
|
41
|
+
|
|
42
|
+
${c.bold('OPTIONS')}
|
|
43
|
+
--mode <prompt|enforce|audit|learn> override the policy mode for this run
|
|
44
|
+
--ci non-interactive; any ask/block = fail
|
|
45
|
+
--json machine-readable output (report, rules, scan)
|
|
46
|
+
--quiet, -q silence normal output; only blocks/prompts
|
|
47
|
+
--no-color plain output
|
|
48
|
+
-h, --help this help
|
|
49
|
+
-v, --version version and platform
|
|
50
|
+
|
|
51
|
+
${c.bold('MODES')}
|
|
52
|
+
prompt pause on a risky event and ask: K kill / A allow once / P trust (default)
|
|
53
|
+
enforce block per policy, never ask (servers, CI, --ci)
|
|
54
|
+
audit log only, block nothing (first week, tuning)
|
|
55
|
+
learn record what each package normally does and propose allow rules
|
|
56
|
+
|
|
57
|
+
docs: https://github.com/imeerai/sentrion license: MIT by imeerai
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
function parseFlags(args) {
|
|
61
|
+
const opts = {}; const rest = [];
|
|
62
|
+
for (let i = 0; i < args.length; i++) {
|
|
63
|
+
const a = args[i];
|
|
64
|
+
if (a === '--mode') opts.mode = args[++i];
|
|
65
|
+
else if (a === '--ci') opts.ci = true;
|
|
66
|
+
else if (a === '--json') opts.json = true;
|
|
67
|
+
else if (a === '--quiet' || a === '-q') opts.quiet = true;
|
|
68
|
+
else if (a === '--no-color') process.env.NO_COLOR = '1';
|
|
69
|
+
else if (a === '--format') opts.format = args[++i];
|
|
70
|
+
else if (a === '--last') rest.push('--last');
|
|
71
|
+
else if (a === '--all') rest.push('--all');
|
|
72
|
+
else rest.push(a);
|
|
73
|
+
}
|
|
74
|
+
return { opts, rest };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function main(argv) {
|
|
78
|
+
const raw = argv.slice(2);
|
|
79
|
+
if (!raw.length || raw[0] === '-h' || raw[0] === '--help') { console.log(HELP); return 0; }
|
|
80
|
+
if (raw[0] === '-v' || raw[0] === '--version') {
|
|
81
|
+
console.log(`sentrion ${pkg.version} · ${process.platform}-${process.arch}`);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { opts, rest } = parseFlags(raw);
|
|
86
|
+
const sub = rest[0];
|
|
87
|
+
|
|
88
|
+
if (sub === 'scan') return require('./cmd-scan.js')(rest.slice(1), opts);
|
|
89
|
+
if (sub === 'report') return require('./report.js').show(rest[1], opts) || 0;
|
|
90
|
+
if (sub === 'rules') return require('./cmd-rules.js')(rest.slice(1), opts);
|
|
91
|
+
if (sub === 'trust') return require('./cmd-trust.js').trust(rest.slice(1), opts);
|
|
92
|
+
if (sub === 'untrust') return require('./cmd-trust.js').untrust(rest.slice(1), opts);
|
|
93
|
+
if (sub === 'allow') return require('./cmd-allow.js')(rest.slice(1), opts);
|
|
94
|
+
if (sub === 'mode') return require('./cmd-mode.js')(rest.slice(1), opts);
|
|
95
|
+
if (sub === 'init') return require('./cmd-init.js')(rest.slice(1), opts);
|
|
96
|
+
if (sub === 'update') return require('./cmd-update.js')(opts);
|
|
97
|
+
if (sub === 'test') return require('./cmd-test.js')(rest.slice(1), opts);
|
|
98
|
+
if (sub === 'policy') {
|
|
99
|
+
const p = require('./policy.js').load(opts);
|
|
100
|
+
if (rest[1] === 'path') console.log(path.join(require('os').homedir(), '.sentrion', 'policy.json'));
|
|
101
|
+
else console.log(JSON.stringify(p, null, 2));
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
if (sub === 'doctor') return require('./cmd-doctor.js')();
|
|
105
|
+
if (sub === 'shell-init') return require('./cmd-shell-init.js')(rest[1]);
|
|
106
|
+
|
|
107
|
+
// otherwise: guard a command. "run -- cmd" or "npm install ..." etc.
|
|
108
|
+
let cmd = rest;
|
|
109
|
+
if (sub === 'run') {
|
|
110
|
+
const dd = rest.indexOf('--');
|
|
111
|
+
cmd = dd >= 0 ? rest.slice(dd + 1) : rest.slice(1);
|
|
112
|
+
}
|
|
113
|
+
if (!cmd.length) { console.error('sentrion: nothing to run. See sentrion --help'); return 2; }
|
|
114
|
+
return require('./guard.js').run(cmd, opts);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = { main, HELP };
|
package/lib/cmd-allow.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion allow <RULE-ID>` — set a rule's action to "allow" in your user policy
|
|
3
|
+
// (the precise counterpart to an incident that names the exact rule that fired).
|
|
4
|
+
const store = require('./store.js');
|
|
5
|
+
const { RULES } = require('./rules.js');
|
|
6
|
+
const { c, tag } = require('./ui.js');
|
|
7
|
+
|
|
8
|
+
module.exports = function allow(args) {
|
|
9
|
+
const id = (args[0] || '').toUpperCase();
|
|
10
|
+
if (!id) { console.error('sentrion allow: give a rule id, e.g. sentrion allow NET-02'); return 2; }
|
|
11
|
+
if (!RULES[id]) { console.error(`sentrion allow: no rule "${id}". Run sentrion rules for the list.`); return 2; }
|
|
12
|
+
const f = store.update((o) => { o.rules = o.rules || {}; o.rules[id] = 'allow'; });
|
|
13
|
+
console.log(`\n ${tag()} ${c.green('allow')} · ${c.white(id)} ${RULES[id].title} — set to allow (user policy)`);
|
|
14
|
+
console.log(c.dim(` ${f} · undo by removing it from "rules"\n`));
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const cp = require('child_process');
|
|
3
|
+
const { c, tag } = require('./ui.js');
|
|
4
|
+
|
|
5
|
+
function has(bin, args = ['--version']) {
|
|
6
|
+
try { cp.execFileSync(bin, args, { stdio: 'ignore', timeout: 4000 }); return true; }
|
|
7
|
+
catch { return false; }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = function doctor() {
|
|
11
|
+
const p = process.platform;
|
|
12
|
+
process.stdout.write(`\n ${tag()} ${c.dim('doctor — what this machine lets Sentrion see and block')}\n\n`);
|
|
13
|
+
const rows = [];
|
|
14
|
+
rows.push(['platform', p]);
|
|
15
|
+
rows.push(['node', process.version]);
|
|
16
|
+
rows.push(['Tier-1 Node hook', c.green('yes') + c.dim(' (always available)')]);
|
|
17
|
+
|
|
18
|
+
if (p === 'linux') {
|
|
19
|
+
rows.push(['process tree', '/proc ' + c.green('yes')]);
|
|
20
|
+
rows.push(['kill tree', 'process groups ' + c.green('yes')]);
|
|
21
|
+
rows.push(['pause tree', 'SIGSTOP ' + c.green('yes')]);
|
|
22
|
+
rows.push(['egress lock', 'nft ' + (has('nft', ['-v']) ? c.green('yes (root)') : c.yellow('needs nft + root'))]);
|
|
23
|
+
rows.push(['deep mode', 'eBPF/auditd ' + c.dim('optional, root')]);
|
|
24
|
+
} else if (p === 'darwin') {
|
|
25
|
+
rows.push(['process tree', 'ps ' + (has('ps', ['-V']) || has('ps', []) ? c.green('yes') : c.yellow('no'))]);
|
|
26
|
+
rows.push(['kill tree', 'process groups ' + c.green('yes')]);
|
|
27
|
+
rows.push(['pause tree', 'SIGSTOP ' + c.green('yes')]);
|
|
28
|
+
rows.push(['egress lock', 'pf ' + c.yellow('needs root')]);
|
|
29
|
+
rows.push(['confine', 'sandbox-exec ' + (has('sandbox-exec', []) ? c.green('yes') : c.yellow('no'))]);
|
|
30
|
+
} else if (p === 'win32') {
|
|
31
|
+
rows.push(['process tree', 'Win32_Process ' + (has('powershell', ['-Command', '$PSVersionTable.PSVersion']) ? c.green('yes') : c.yellow('no'))]);
|
|
32
|
+
rows.push(['kill tree', 'taskkill /T ' + c.green('yes')]);
|
|
33
|
+
rows.push(['pause tree', c.yellow('held at source (no suspend in v0.1)')]);
|
|
34
|
+
rows.push(['egress lock', 'Windows Firewall ' + c.yellow('needs admin')]);
|
|
35
|
+
}
|
|
36
|
+
const w = Math.max(...rows.map((r) => r[0].length));
|
|
37
|
+
for (const [k, v] of rows) process.stdout.write(` ${k.padEnd(w)} ${v}\n`);
|
|
38
|
+
process.stdout.write(`\n ${c.dim('base mode needs no root; egress lock and deep mode use the privileged helper')}\n\n`);
|
|
39
|
+
return 0;
|
|
40
|
+
};
|
package/lib/cmd-init.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion init` — scaffold ./.sentrion.json so a repo carries its own mode and
|
|
3
|
+
// allow list. A project file may only make the guard STRICTER, never looser.
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { c, tag } = require('./ui.js');
|
|
7
|
+
|
|
8
|
+
const TEMPLATE = {
|
|
9
|
+
$schema: 'https://github.com/imeerai/sentrion#project-policy',
|
|
10
|
+
mode: 'prompt',
|
|
11
|
+
install: { allowHosts: [], minPackageAgeHours: 48 },
|
|
12
|
+
rules: {},
|
|
13
|
+
trust: {},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = function init(args) {
|
|
17
|
+
const file = path.join(process.cwd(), '.sentrion.json');
|
|
18
|
+
if (fs.existsSync(file) && !args.includes('--force')) {
|
|
19
|
+
console.error(`sentrion init: ${file} already exists. Use sentrion init --force to overwrite.`);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
fs.writeFileSync(file, JSON.stringify(TEMPLATE, null, 2) + '\n');
|
|
23
|
+
console.log(`\n ${tag()} ${c.green('created')} ./.sentrion.json`);
|
|
24
|
+
console.log(c.dim(' commit it so everyone who clones this repo gets the same guard.\n'));
|
|
25
|
+
return 0;
|
|
26
|
+
};
|
package/lib/cmd-mode.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion mode <name>` — set the default mode in ~/.sentrion/policy.json.
|
|
3
|
+
const store = require('./store.js');
|
|
4
|
+
const { c, tag } = require('./ui.js');
|
|
5
|
+
|
|
6
|
+
const MODES = ['prompt', 'enforce', 'audit', 'learn'];
|
|
7
|
+
|
|
8
|
+
module.exports = function mode(args) {
|
|
9
|
+
const m = (args[0] || '').toLowerCase();
|
|
10
|
+
if (!m) { // show current
|
|
11
|
+
const cur = store.read().mode || 'prompt';
|
|
12
|
+
console.log(`${tag()} default mode = ${c.white(cur)} ${c.dim('(' + store.file() + ')')}`);
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
if (!MODES.includes(m)) {
|
|
16
|
+
console.error('sentrion mode: choose one of ' + MODES.join(', '));
|
|
17
|
+
return 2;
|
|
18
|
+
}
|
|
19
|
+
const f = store.update((o) => { o.mode = m; });
|
|
20
|
+
console.log(`${tag()} default mode = ${c.white(m)} ${c.dim('(' + f + ')')}`);
|
|
21
|
+
return 0;
|
|
22
|
+
};
|
package/lib/cmd-rules.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion rules` — list every rule and its default action
|
|
3
|
+
// `sentrion rules NET-01` — show one rule in detail
|
|
4
|
+
// `sentrion rules --json` — machine-readable
|
|
5
|
+
const { RULES } = require('./rules.js');
|
|
6
|
+
const { c, tag, sev } = require('./ui.js');
|
|
7
|
+
|
|
8
|
+
const ACT = { block: c.red, ask: c.yellow, warn: c.dim, allow: c.green };
|
|
9
|
+
|
|
10
|
+
module.exports = function rules(args, opts = {}) {
|
|
11
|
+
const want = (args[0] || '').toUpperCase();
|
|
12
|
+
|
|
13
|
+
if (want && RULES[want]) {
|
|
14
|
+
const r = RULES[want];
|
|
15
|
+
if (opts.json) { console.log(JSON.stringify({ id: want, ...r }, null, 2)); return 0; }
|
|
16
|
+
console.log(`\n ${tag()} ${(sev[r.sev] || c.yellow)(want)} ${r.title}`);
|
|
17
|
+
console.log(` severity ${r.sev}`);
|
|
18
|
+
console.log(` install ${(ACT[r.install] || c.dim)(r.install)}`);
|
|
19
|
+
console.log(` run ${(ACT[r.run] || c.dim)(r.run)}\n`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
if (want) { console.error(`sentrion rules: no rule "${want}". Run sentrion rules for the list.`); return 2; }
|
|
23
|
+
|
|
24
|
+
const ids = Object.keys(RULES);
|
|
25
|
+
if (opts.json) { console.log(JSON.stringify(RULES, null, 2)); return 0; }
|
|
26
|
+
|
|
27
|
+
const tally = { block: 0, ask: 0, warn: 0, allow: 0 };
|
|
28
|
+
for (const id of ids) tally[RULES[id].install] = (tally[RULES[id].install] || 0) + 1;
|
|
29
|
+
|
|
30
|
+
process.stdout.write(`\n ${tag()} ${c.dim('rule set — default action shown per phase (install / run)')}\n\n`);
|
|
31
|
+
let group = '';
|
|
32
|
+
for (const id of ids) {
|
|
33
|
+
const g = id.split('-')[0];
|
|
34
|
+
if (g !== group) { group = g; process.stdout.write(` ${c.dim(groupName(g))}\n`); }
|
|
35
|
+
const r = RULES[id];
|
|
36
|
+
const col = sev[r.sev] || c.yellow;
|
|
37
|
+
process.stdout.write(` ${col(id.padEnd(9))} ${r.title.padEnd(52)} ${(ACT[r.install] || c.dim)(r.install)}${c.dim(' / ')}${(ACT[r.run] || c.dim)(r.run)}\n`);
|
|
38
|
+
}
|
|
39
|
+
process.stdout.write(`\n ${ids.length} rules · ${tally.block} block · ${tally.ask} ask · ${tally.warn} warn · ${tally.allow || 0} allow ${c.dim('(by install default)')}\n`);
|
|
40
|
+
process.stdout.write(c.dim(` sentrion rules <ID> for one rule · override in policy with "rules": { "${ids[0]}": "warn" }\n\n`));
|
|
41
|
+
return 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function groupName(g) {
|
|
45
|
+
return ({
|
|
46
|
+
SCAN: 'SCAN · static pre-flight', REPO: 'REPO · repository traps',
|
|
47
|
+
PROC: 'PROC · process behaviour', PERS: 'PERS · persistence',
|
|
48
|
+
FILE: 'FILE · secret reads & dangerous writes', NET: 'NET · network',
|
|
49
|
+
TOK: 'TOK · token abuse',
|
|
50
|
+
})[g] || g;
|
|
51
|
+
}
|
package/lib/cmd-scan.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { scanRepo, scanName } = require('./scan.js');
|
|
4
|
+
const { load } = require('./policy.js');
|
|
5
|
+
const { c, tag, sev } = require('./ui.js');
|
|
6
|
+
const { baseAction } = require('./rules.js');
|
|
7
|
+
|
|
8
|
+
module.exports = function scanCmd(args, opts) {
|
|
9
|
+
const target = args[0];
|
|
10
|
+
if (!target) { console.error('sentrion scan: give a package name or a path. e.g. sentrion scan .'); return 2; }
|
|
11
|
+
const policy = load(opts);
|
|
12
|
+
|
|
13
|
+
let findings; let kind;
|
|
14
|
+
const asPath = target === '.' || target.startsWith('.') || target.startsWith('/') || fs.existsSync(target);
|
|
15
|
+
if (asPath) { findings = scanRepo(target); kind = 'repo'; }
|
|
16
|
+
else { findings = scanName(target, policy); kind = 'package'; }
|
|
17
|
+
|
|
18
|
+
if (opts.json) {
|
|
19
|
+
const out = findings.map((f) => ({
|
|
20
|
+
rule: f.rule, title: f.title, sev: f.sev,
|
|
21
|
+
action: f.rule === 'INFO' ? 'warn' : baseAction(f.rule, kind === 'repo' ? 'run' : 'install'),
|
|
22
|
+
detail: f.detail || null,
|
|
23
|
+
}));
|
|
24
|
+
const block = out.filter((o) => o.action === 'block').length;
|
|
25
|
+
const ask = out.filter((o) => o.action === 'ask').length;
|
|
26
|
+
console.log(JSON.stringify({
|
|
27
|
+
target, kind, verdict: block ? 'high-risk' : ask ? 'review' : 'ok',
|
|
28
|
+
counts: { block, ask, note: out.length - block - ask }, findings: out,
|
|
29
|
+
}, null, 2));
|
|
30
|
+
return block ? 87 : 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
process.stdout.write(`\n ${tag()} ${c.dim('scan only — nothing will run')}\n\n`);
|
|
34
|
+
process.stdout.write(` ${kind === 'repo' ? 'repo ' : 'package'} ${c.white(target)}\n\n`);
|
|
35
|
+
|
|
36
|
+
let block = 0, ask = 0, warn = 0;
|
|
37
|
+
if (!findings.length) {
|
|
38
|
+
process.stdout.write(` ${c.green('✓')} no risky patterns found\n`);
|
|
39
|
+
}
|
|
40
|
+
for (const f of findings) {
|
|
41
|
+
const act = f.rule === 'INFO' ? 'warn' : baseAction(f.rule, kind === 'repo' ? 'run' : 'install');
|
|
42
|
+
const mark = act === 'block' ? c.red('✕') : act === 'ask' ? c.yellow('!') : c.dim('·');
|
|
43
|
+
if (act === 'block') block++; else if (act === 'ask') ask++; else warn++;
|
|
44
|
+
const col = sev[f.sev] || c.dim;
|
|
45
|
+
const d = f.detail ? c.dim(' ' + JSON.stringify(f.detail).slice(0, 70)) : '';
|
|
46
|
+
process.stdout.write(` ${mark} ${col((f.rule || '').padEnd(8))} ${f.title}${d}\n`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const verdict = block ? c.redBg(' HIGH RISK ') : ask ? c.yellow(' REVIEW ') : c.green(' LOOKS OK ');
|
|
50
|
+
process.stdout.write(`\n verdict ${verdict} ${block} block ${ask} ask ${warn} note\n`);
|
|
51
|
+
if (block || ask) {
|
|
52
|
+
process.stdout.write(`\n ${c.bold('Do not run this directly.')}\n`);
|
|
53
|
+
process.stdout.write(` ${c.cyan('sentrion test -- <cmd>')} run it in a throwaway sandbox first\n`);
|
|
54
|
+
process.stdout.write(` ${c.cyan('sentrion <cmd>')} or run it guarded (secrets hidden, egress via proxy)\n`);
|
|
55
|
+
}
|
|
56
|
+
process.stdout.write('\n');
|
|
57
|
+
return block ? 87 : 0;
|
|
58
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { c } = require('./ui.js');
|
|
3
|
+
|
|
4
|
+
const MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'npx', 'pnpx', 'bunx', 'pip', 'pip3', 'uv', 'poetry'];
|
|
5
|
+
|
|
6
|
+
module.exports = function shellInit(shell) {
|
|
7
|
+
const sh = (shell || detect()).toLowerCase();
|
|
8
|
+
const lines = [];
|
|
9
|
+
if (sh === 'pwsh' || sh === 'powershell') {
|
|
10
|
+
for (const m of MANAGERS) lines.push(`function ${m} { sentrion ${m} @args }`);
|
|
11
|
+
} else {
|
|
12
|
+
for (const m of MANAGERS) lines.push(`alias ${m}='sentrion ${m}'`);
|
|
13
|
+
}
|
|
14
|
+
// header as comments so `eval "$(sentrion shell-init)"` is safe
|
|
15
|
+
const cmt = (sh === 'pwsh' || sh === 'powershell') ? '#' : '#';
|
|
16
|
+
process.stdout.write(`${cmt} Sentrion shell integration (${sh}). Add to your shell rc, or:\n`);
|
|
17
|
+
process.stdout.write(`${cmt} eval "$(sentrion shell-init)"\n`);
|
|
18
|
+
process.stdout.write(lines.join('\n') + '\n');
|
|
19
|
+
return 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function detect() {
|
|
23
|
+
const s = process.env.SHELL || '';
|
|
24
|
+
if (s.includes('zsh')) return 'zsh';
|
|
25
|
+
if (s.includes('bash')) return 'bash';
|
|
26
|
+
if (process.platform === 'win32') return 'pwsh';
|
|
27
|
+
return 'bash';
|
|
28
|
+
}
|
package/lib/cmd-test.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion test -- <cmd>` — run a command in a throwaway sandbox before you
|
|
3
|
+
// trust it: the guard runs in ENFORCE mode (every risky action blocked, no
|
|
4
|
+
// prompts) inside a temporary HOME and working directory, so writes never touch
|
|
5
|
+
// your project and secret-path reads land in an empty home. Lightweight, not a
|
|
6
|
+
// container: full OS isolation is the privileged/deep-mode path.
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { c, tag } = require('./ui.js');
|
|
12
|
+
|
|
13
|
+
module.exports = async function test(args, opts = {}) {
|
|
14
|
+
const dd = args.indexOf('--');
|
|
15
|
+
const cmd = dd >= 0 ? args.slice(dd + 1) : args;
|
|
16
|
+
if (!cmd.length) { console.error('sentrion test: nothing to run. e.g. sentrion test -- node app.js'); return 2; }
|
|
17
|
+
|
|
18
|
+
const box = fs.mkdtempSync(path.join(os.tmpdir(), 'sentrion-box-'));
|
|
19
|
+
process.stdout.write(`\n ${tag()} ${c.dim('test — throwaway sandbox (enforce mode · temp HOME & CWD · egress via proxy)')}\n`);
|
|
20
|
+
process.stdout.write(c.dim(` box ${box}\n`));
|
|
21
|
+
try {
|
|
22
|
+
return await require('./guard.js').run(cmd, { ...opts, mode: 'enforce', sandbox: box });
|
|
23
|
+
} finally {
|
|
24
|
+
try { fs.rmSync(box, { recursive: true, force: true }); } catch {}
|
|
25
|
+
}
|
|
26
|
+
};
|
package/lib/cmd-trust.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `sentrion trust <pkg[@range]> [scripts] [spawn:a,b] [net:host1,host2]`
|
|
3
|
+
// `sentrion untrust <pkg[@range]>`
|
|
4
|
+
// Writes a narrow trust entry to ~/.sentrion/policy.json. A trust entry pins one
|
|
5
|
+
// package + version range + the behaviour you allow, so a hijacked later version
|
|
6
|
+
// that does something new no longer matches and Sentrion asks again.
|
|
7
|
+
|
|
8
|
+
const store = require('./store.js');
|
|
9
|
+
const { c, tag } = require('./ui.js');
|
|
10
|
+
|
|
11
|
+
function trust(args) {
|
|
12
|
+
const spec = args[0];
|
|
13
|
+
if (!spec) { console.error('sentrion trust: give a package, e.g. sentrion trust esbuild@^0.20'); return 2; }
|
|
14
|
+
|
|
15
|
+
const entry = { scripts: 'allow' };
|
|
16
|
+
for (const tok of args.slice(1)) {
|
|
17
|
+
if (tok === 'scripts') entry.scripts = 'allow';
|
|
18
|
+
else if (tok.startsWith('spawn:')) entry.spawn = tok.slice(6).split(',').filter(Boolean);
|
|
19
|
+
else if (tok.startsWith('net:')) entry.hosts = tok.slice(4).split(',').filter(Boolean);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const f = store.update((o) => { o.trust = o.trust || {}; o.trust[spec] = entry; });
|
|
23
|
+
const name = spec.split('@')[0] || spec;
|
|
24
|
+
const range = spec.includes('@') ? spec.slice(spec.indexOf('@') + 1) : 'any';
|
|
25
|
+
console.log(`\n ${tag()} ${c.green('trusted')} · ${c.white(name)} ${range} · ${describe(entry)}`);
|
|
26
|
+
console.log(c.dim(` ${f}\n`));
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function describe(e) {
|
|
31
|
+
const parts = [];
|
|
32
|
+
if (e.scripts === 'allow') parts.push('build scripts allowed');
|
|
33
|
+
if (e.spawn && e.spawn.length) parts.push('may spawn ' + e.spawn.join('/'));
|
|
34
|
+
if (e.hosts && e.hosts.length) parts.push('may reach ' + e.hosts.join(', '));
|
|
35
|
+
return parts.join(' · ') || 'build scripts allowed';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function untrust(args) {
|
|
39
|
+
const spec = args[0];
|
|
40
|
+
if (!spec) { console.error('sentrion untrust: give a package, e.g. sentrion untrust esbuild'); return 2; }
|
|
41
|
+
let removed = 0;
|
|
42
|
+
const f = store.update((o) => {
|
|
43
|
+
o.trust = o.trust || {};
|
|
44
|
+
for (const key of Object.keys(o.trust)) {
|
|
45
|
+
if (key === spec || key.split('@')[0] === spec) { delete o.trust[key]; removed++; }
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (removed) console.log(`\n ${tag()} ${c.yellow('untrusted')} · removed ${removed} entr${removed === 1 ? 'y' : 'ies'} for ${c.white(spec)}\n ${c.dim(f)}\n`);
|
|
49
|
+
else console.log(`\n ${tag()} nothing trusted matched ${c.white(spec)}\n`);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { trust, untrust };
|