@agentic-kit/permissions 0.0.0-stage → 0.2.1

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.
Files changed (143) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +279 -2
  3. package/bash/analyze.d.ts +133 -0
  4. package/bash/analyze.js +442 -0
  5. package/bash/args.d.ts +45 -0
  6. package/bash/args.js +145 -0
  7. package/bash/braces.d.ts +6 -0
  8. package/bash/braces.js +72 -0
  9. package/bash/commands.d.ts +14 -0
  10. package/bash/commands.js +361 -0
  11. package/bash/file-commands.d.ts +22 -0
  12. package/bash/file-commands.js +278 -0
  13. package/bash/flows.d.ts +67 -0
  14. package/bash/flows.js +208 -0
  15. package/bash/git.d.ts +7 -0
  16. package/bash/git.js +163 -0
  17. package/bash/network.d.ts +24 -0
  18. package/bash/network.js +295 -0
  19. package/bash/quoting.d.ts +16 -0
  20. package/bash/quoting.js +164 -0
  21. package/bash/system.d.ts +16 -0
  22. package/bash/system.js +122 -0
  23. package/bash/tokenize.d.ts +67 -0
  24. package/bash/tokenize.js +440 -0
  25. package/bash/words.d.ts +9 -0
  26. package/bash/words.js +30 -0
  27. package/bash/wrappers.d.ts +32 -0
  28. package/bash/wrappers.js +237 -0
  29. package/classify.d.ts +22 -0
  30. package/classify.js +259 -0
  31. package/engine.d.ts +109 -0
  32. package/engine.js +144 -0
  33. package/env.d.ts +13 -0
  34. package/env.js +37 -0
  35. package/esm/bash/analyze.d.ts +133 -0
  36. package/esm/bash/analyze.js +405 -0
  37. package/esm/bash/args.d.ts +45 -0
  38. package/esm/bash/args.js +135 -0
  39. package/esm/bash/braces.d.ts +6 -0
  40. package/esm/bash/braces.js +69 -0
  41. package/esm/bash/commands.d.ts +14 -0
  42. package/esm/bash/commands.js +324 -0
  43. package/esm/bash/file-commands.d.ts +22 -0
  44. package/esm/bash/file-commands.js +233 -0
  45. package/esm/bash/flows.d.ts +67 -0
  46. package/esm/bash/flows.js +203 -0
  47. package/esm/bash/git.d.ts +7 -0
  48. package/esm/bash/git.js +127 -0
  49. package/esm/bash/network.d.ts +24 -0
  50. package/esm/bash/network.js +282 -0
  51. package/esm/bash/quoting.d.ts +16 -0
  52. package/esm/bash/quoting.js +153 -0
  53. package/esm/bash/system.d.ts +16 -0
  54. package/esm/bash/system.js +82 -0
  55. package/esm/bash/tokenize.d.ts +67 -0
  56. package/esm/bash/tokenize.js +437 -0
  57. package/esm/bash/words.d.ts +9 -0
  58. package/esm/bash/words.js +24 -0
  59. package/esm/bash/wrappers.d.ts +32 -0
  60. package/esm/bash/wrappers.js +200 -0
  61. package/esm/classify.d.ts +22 -0
  62. package/esm/classify.js +223 -0
  63. package/esm/engine.d.ts +109 -0
  64. package/esm/engine.js +108 -0
  65. package/esm/env.d.ts +13 -0
  66. package/esm/env.js +34 -0
  67. package/esm/findings.d.ts +7 -0
  68. package/esm/findings.js +9 -0
  69. package/esm/glob.d.ts +15 -0
  70. package/esm/glob.js +69 -0
  71. package/esm/grants.d.ts +36 -0
  72. package/esm/grants.js +99 -0
  73. package/esm/index.d.ts +19 -0
  74. package/esm/index.js +18 -0
  75. package/esm/node-fs.d.ts +6 -0
  76. package/esm/node-fs.js +34 -0
  77. package/esm/paths.d.ts +43 -0
  78. package/esm/paths.js +121 -0
  79. package/esm/policy.d.ts +21 -0
  80. package/esm/policy.js +85 -0
  81. package/esm/prompt.d.ts +14 -0
  82. package/esm/prompt.js +79 -0
  83. package/esm/roots.d.ts +75 -0
  84. package/esm/roots.js +148 -0
  85. package/esm/secret-files.d.ts +16 -0
  86. package/esm/secret-files.js +84 -0
  87. package/esm/secrets/collect.d.ts +19 -0
  88. package/esm/secrets/collect.js +60 -0
  89. package/esm/secrets/index.d.ts +5 -0
  90. package/esm/secrets/index.js +5 -0
  91. package/esm/secrets/parse.d.ts +19 -0
  92. package/esm/secrets/parse.js +140 -0
  93. package/esm/secrets/redact-result.d.ts +8 -0
  94. package/esm/secrets/redact-result.js +67 -0
  95. package/esm/secrets/rules.d.ts +34 -0
  96. package/esm/secrets/rules.js +101 -0
  97. package/esm/secrets/vault.d.ts +48 -0
  98. package/esm/secrets/vault.js +158 -0
  99. package/esm/signals.d.ts +14 -0
  100. package/esm/signals.js +26 -0
  101. package/esm/tool-input.d.ts +13 -0
  102. package/esm/tool-input.js +40 -0
  103. package/esm/types.d.ts +146 -0
  104. package/esm/types.js +20 -0
  105. package/findings.d.ts +7 -0
  106. package/findings.js +13 -0
  107. package/glob.d.ts +15 -0
  108. package/glob.js +73 -0
  109. package/grants.d.ts +36 -0
  110. package/grants.js +110 -0
  111. package/index.d.ts +19 -0
  112. package/index.js +52 -0
  113. package/node-fs.d.ts +6 -0
  114. package/node-fs.js +37 -0
  115. package/package.json +35 -3
  116. package/paths.d.ts +43 -0
  117. package/paths.js +164 -0
  118. package/policy.d.ts +21 -0
  119. package/policy.js +88 -0
  120. package/prompt.d.ts +14 -0
  121. package/prompt.js +83 -0
  122. package/roots.d.ts +75 -0
  123. package/roots.js +192 -0
  124. package/secret-files.d.ts +16 -0
  125. package/secret-files.js +124 -0
  126. package/secrets/collect.d.ts +19 -0
  127. package/secrets/collect.js +96 -0
  128. package/secrets/index.d.ts +5 -0
  129. package/secrets/index.js +21 -0
  130. package/secrets/parse.d.ts +19 -0
  131. package/secrets/parse.js +145 -0
  132. package/secrets/redact-result.d.ts +8 -0
  133. package/secrets/redact-result.js +70 -0
  134. package/secrets/rules.d.ts +34 -0
  135. package/secrets/rules.js +107 -0
  136. package/secrets/vault.d.ts +48 -0
  137. package/secrets/vault.js +163 -0
  138. package/signals.d.ts +14 -0
  139. package/signals.js +29 -0
  140. package/tool-input.d.ts +13 -0
  141. package/tool-input.js +46 -0
  142. package/types.d.ts +146 -0
  143. package/types.js +24 -0
package/bash/git.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * git: options that make it run programs, pushes that rewrite or leave for an
4
+ * unknown remote, config writes, and force-adding a secret file.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.git = git;
41
+ const path = __importStar(require("node:path"));
42
+ const secret_files_1 = require("../secret-files");
43
+ const args_1 = require("./args");
44
+ const words_1 = require("./words");
45
+ /** `git -c` keys that make git run a program. */
46
+ const GIT_EXEC_CONFIG = /^(alias\.|core\.(sshcommand|pager|editor|fsmonitor|hookspath|askpass|gitproxy)|diff\.|credential\.|sequence\.editor|gpg\.|filter\.|uploadpack\.|protocol\.|include\.|includeif\.|remote\..*\.(uploadpack|receivepack))/i;
47
+ /** `git -c remote.<name>.url=…`: the remote points somewhere else for this run. */
48
+ const GIT_REMOTE_URL_CONFIG = /^remote\.(.+)\.(url|pushurl)=/i;
49
+ /**
50
+ * `git push`: destructive when it rewrites or deletes refs, and an upload when
51
+ * it goes to a URL or to a remote this command added or repointed.
52
+ */
53
+ function push(ctx, p) {
54
+ const { analyzer } = ctx;
55
+ const force = (0, args_1.has)(p, '-f', '--force', '--force-if-includes', '--mirror', '-d', '--delete', '--prune') ||
56
+ [...p.flags].some((f) => f.startsWith('--force-with-lease')) ||
57
+ p.positionals.some((a) => a.text.startsWith('+') || a.text.startsWith(':'));
58
+ if (force)
59
+ analyzer.flag('destructive', 'it force-pushes or deletes refs on the remote');
60
+ const remote = (0, args_1.valuesOf)(p, '--repo')[0] ?? p.positionals[0];
61
+ if (!remote) {
62
+ if (analyzer.gitRemotes.size > 0)
63
+ analyzer.flag('upload', 'it uploads data: git push goes to a remote this command changed');
64
+ return;
65
+ }
66
+ if (remote.unknown || (0, words_1.isUrl)(remote.text) || (0, words_1.isRemoteSpec)(remote.text)) {
67
+ analyzer.flag('upload', `it uploads data: git push sends commits to ${remote.raw}`);
68
+ }
69
+ else if (analyzer.gitRemotes.has(remote.text)) {
70
+ analyzer.flag('upload', `it uploads data: git push goes to ${remote.raw}, a remote this command set`);
71
+ }
72
+ }
73
+ /** `git remote add|set-url NAME URL`: remember the name, so a later push is an upload. */
74
+ function remote(ctx, args) {
75
+ const p = (0, args_1.parse)(args, new Set(['-t', '-m']));
76
+ const [action, name] = p.positionals;
77
+ if ((action?.text === 'add' || action?.text === 'set-url') && name)
78
+ ctx.analyzer.gitRemotes.add(name.text);
79
+ }
80
+ /** `git add -f .env`: stages a file `.gitignore` keeps out, so its values would be committed. */
81
+ function add(ctx, args) {
82
+ const p = (0, args_1.parse)(args, new Set(['--chmod', '--pathspec-from-file']));
83
+ if ((0, args_1.has)(p, '-f', '--force')) {
84
+ for (const op of p.positionals) {
85
+ if (op.unknown || !(0, secret_files_1.isSecretFile)(op.text))
86
+ continue;
87
+ ctx.analyzer.flag('secret-file', `git add -f stages the secret file ${op.raw}, which .gitignore keeps out of the repo`);
88
+ ctx.analyzer.flag('secret-into-plain-file', `git add -f puts ${op.raw} into the repo, where its values are committed in the clear`);
89
+ }
90
+ }
91
+ (0, args_1.generic)(ctx, p.positionals.filter((a) => !(0, words_1.isUrl)(a.text)));
92
+ }
93
+ function git(ctx, rest) {
94
+ const { analyzer } = ctx;
95
+ let k = 0;
96
+ let base = analyzer.base;
97
+ for (; k < rest.length; k++) {
98
+ const t = rest[k].text;
99
+ if (t === '-C') {
100
+ const dir = rest[++k];
101
+ base = dir && !dir.unknown && base !== null ? path.resolve(base, dir.text) : null;
102
+ if (dir)
103
+ analyzer.addPath(dir, 'read', true);
104
+ }
105
+ else if (t === '-c') {
106
+ const kv = rest[++k];
107
+ if (kv && GIT_EXEC_CONFIG.test(kv.text))
108
+ analyzer.dynamic(`git -c ${kv.text} makes git run a program`);
109
+ const repointed = kv ? GIT_REMOTE_URL_CONFIG.exec(kv.text) : null;
110
+ if (repointed)
111
+ analyzer.gitRemotes.add(repointed[1]);
112
+ }
113
+ else if (/^--(git-dir|work-tree)=/.test(t)) {
114
+ analyzer.addPath({ ...rest[k], text: t.slice(t.indexOf('=') + 1) }, 'read', true);
115
+ }
116
+ else if (t.startsWith('--exec-path')) {
117
+ analyzer.dynamic('git --exec-path changes which programs git runs');
118
+ }
119
+ else if (!t.startsWith('-')) {
120
+ break;
121
+ }
122
+ }
123
+ const sub = rest[k]?.text;
124
+ const args = rest.slice(k + 1);
125
+ const saved = analyzer.base;
126
+ analyzer.base = base;
127
+ try {
128
+ if (sub === 'remote')
129
+ return remote(ctx, args);
130
+ if (sub === 'add')
131
+ return add(ctx, args);
132
+ if (sub === 'push')
133
+ return push(ctx, (0, args_1.parse)(args, new Set(['--repo', '-o', '--push-option', '--receive-pack', '--exec'])));
134
+ const p = (0, args_1.parse)(args, new Set(['-m', '-F', '-C', '-c', '--file', '-f', '-o', '--message', '--format']));
135
+ const here = { text: '.', raw: rest[k]?.raw ?? '.', unknown: base === null, glob: false };
136
+ if (sub === 'reset' && (0, args_1.has)(p, '--hard'))
137
+ analyzer.destroy(here, 'git reset --hard');
138
+ if (sub === 'clean' && (0, args_1.has)(p, '-f', '--force'))
139
+ analyzer.destroy(here, 'git clean -f');
140
+ if (sub === 'config') {
141
+ const reads = (0, args_1.has)(p, '--get', '--get-all', '--get-regexp', '--get-urlmatch', '--list', '-l', '--show-origin');
142
+ const edits = (0, args_1.has)(p, '--add', '--unset', '--unset-all', '--replace-all', '--rename-section', '--remove-section', '-e', '--edit');
143
+ if (!reads && (edits || p.positionals.length >= 2)) {
144
+ const file = (0, args_1.valuesOf)(p, '--file', '-f')[0];
145
+ if (file)
146
+ analyzer.addPath(file, 'write', true);
147
+ else if ((0, args_1.has)(p, '--global'))
148
+ analyzer.addPath({ ...here, text: `${analyzer.ctx.homeDir}/.gitconfig` }, 'write', true);
149
+ else if ((0, args_1.has)(p, '--system'))
150
+ analyzer.addPath({ ...here, text: '/etc/gitconfig' }, 'write', true);
151
+ else
152
+ analyzer.addPath({ ...here, text: '.git/config', raw: '.git/config' }, 'write', true);
153
+ }
154
+ return;
155
+ }
156
+ for (const f of (0, args_1.valuesOf)(p, '-F', '--file'))
157
+ analyzer.addPath(f, 'read', true);
158
+ (0, args_1.generic)(ctx, p.positionals.filter((a) => !(0, words_1.isUrl)(a.text)));
159
+ }
160
+ finally {
161
+ analyzer.base = saved;
162
+ }
163
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Commands that talk to other machines: uploads (`curl -d @file`, `scp` to a
3
+ * host, publishing a package), servers and tunnels that expose the project to
4
+ * the network, and raw network tools.
5
+ */
6
+ import type { Arg } from './analyze';
7
+ import { type CommandContext } from './args';
8
+ export declare function curl(ctx: CommandContext, rest: readonly Arg[]): void;
9
+ export declare function wget(ctx: CommandContext, rest: readonly Arg[]): void;
10
+ export declare function remoteCopy(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
11
+ export declare function ssh(ctx: CommandContext, rest: readonly Arg[]): void;
12
+ /** Tunnels that put a local port on the internet. */
13
+ export declare const TUNNELS: Set<string>;
14
+ export declare function tunnel(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
15
+ /** `python -m http.server` binds every interface unless `--bind` says otherwise. */
16
+ export declare function pythonServer(ctx: CommandContext, module: string, args: readonly Arg[]): void;
17
+ /** `php -S host:port`. */
18
+ export declare function phpServer(ctx: CommandContext, rest: readonly Arg[]): void;
19
+ /** `ruby -run -e httpd`. */
20
+ export declare function rubyServer(ctx: CommandContext, rest: readonly Arg[]): void;
21
+ /** `busybox httpd -p [ip:]port`. */
22
+ export declare function busyboxServer(ctx: CommandContext, rest: readonly Arg[]): void;
23
+ /** `npm publish`, `docker push`, …: an upload. */
24
+ export declare function publishes(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ /**
3
+ * Commands that talk to other machines: uploads (`curl -d @file`, `scp` to a
4
+ * host, publishing a package), servers and tunnels that expose the project to
5
+ * the network, and raw network tools.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.TUNNELS = void 0;
9
+ exports.curl = curl;
10
+ exports.wget = wget;
11
+ exports.remoteCopy = remoteCopy;
12
+ exports.ssh = ssh;
13
+ exports.tunnel = tunnel;
14
+ exports.pythonServer = pythonServer;
15
+ exports.phpServer = phpServer;
16
+ exports.rubyServer = rubyServer;
17
+ exports.busyboxServer = busyboxServer;
18
+ exports.publishes = publishes;
19
+ const args_1 = require("./args");
20
+ const words_1 = require("./words");
21
+ const CURL_WITH_VALUE = new Set([
22
+ '-d',
23
+ '-F',
24
+ '-T',
25
+ '-H',
26
+ '-o',
27
+ '-u',
28
+ '-X',
29
+ '-A',
30
+ '-e',
31
+ '-b',
32
+ '-c',
33
+ '-K',
34
+ '-E',
35
+ '-x',
36
+ '-w',
37
+ '-m',
38
+ '-y',
39
+ '-Y',
40
+ '-z',
41
+ '-C',
42
+ '-r',
43
+ '-Q',
44
+ '-D',
45
+ '-U',
46
+ '-t',
47
+ '--data',
48
+ '--data-binary',
49
+ '--data-raw',
50
+ '--data-ascii',
51
+ '--data-urlencode',
52
+ '--json',
53
+ '--form',
54
+ '--form-string',
55
+ '--upload-file',
56
+ '--header',
57
+ '--output',
58
+ '--config',
59
+ '--url',
60
+ '--user',
61
+ '--request',
62
+ '--cookie',
63
+ '--cookie-jar',
64
+ '--proxy',
65
+ '--cert',
66
+ '--key',
67
+ '--cacert',
68
+ '--dump-header',
69
+ '--write-out',
70
+ '--max-time',
71
+ '--connect-timeout',
72
+ '--retry',
73
+ '--referer',
74
+ '--user-agent',
75
+ '--range',
76
+ '--resolve',
77
+ '--output-dir'
78
+ ]);
79
+ function isLocalUrl(url) {
80
+ const m = /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^@/]*@)?(\[[^\]]*\]|[^:/?#]*)/i.exec(url);
81
+ return (0, words_1.isLoopbackHost)(m?.[1] ?? '');
82
+ }
83
+ function curl(ctx, rest) {
84
+ const { analyzer } = ctx;
85
+ const p = (0, args_1.parse)(rest, CURL_WITH_VALUE);
86
+ const say = (detail) => analyzer.flag('upload', `it uploads data: ${detail}`);
87
+ let dataForms = false;
88
+ for (const key of ['-d', '--data', '--data-binary', '--data-raw', '--data-ascii', '--json']) {
89
+ for (const v of p.values.get(key) ?? []) {
90
+ dataForms = true;
91
+ if (v.unknown)
92
+ say(`curl ${key} with a value from a variable or substitution`);
93
+ if (v.text.startsWith('@')) {
94
+ say(`curl ${key} ${v.text} sends a file's contents`);
95
+ if (v.text !== '@-')
96
+ analyzer.addPath({ ...v, text: v.text.slice(1) }, 'read', true);
97
+ }
98
+ }
99
+ }
100
+ for (const v of p.values.get('--data-urlencode') ?? []) {
101
+ dataForms = true;
102
+ const at = v.text.indexOf('@');
103
+ if (at >= 0) {
104
+ say(`curl --data-urlencode ${v.text} sends a file's contents`);
105
+ const file = v.text.slice(at + 1);
106
+ if (file !== '-')
107
+ analyzer.addPath({ ...v, text: file }, 'read', true);
108
+ }
109
+ }
110
+ for (const v of (0, args_1.valuesOf)(p, '-F', '--form')) {
111
+ dataForms = true;
112
+ const m = /=([@<])([^;]*)/.exec(v.text);
113
+ if (m) {
114
+ say(`curl -F ${v.text} sends a file`);
115
+ if (m[2] !== '-')
116
+ analyzer.addPath({ ...v, text: m[2] }, 'read', true);
117
+ }
118
+ }
119
+ for (const v of (0, args_1.valuesOf)(p, '-T', '--upload-file')) {
120
+ dataForms = true;
121
+ say(`curl -T ${v.text} uploads a file`);
122
+ if (v.text !== '-' && v.text !== '.')
123
+ analyzer.addPath(v, 'read', true);
124
+ }
125
+ for (const v of (0, args_1.valuesOf)(p, '-H', '--header')) {
126
+ if (v.text.startsWith('@')) {
127
+ say(`curl -H ${v.text} sends headers from a file`);
128
+ analyzer.addPath({ ...v, text: v.text.slice(1) }, 'read', true);
129
+ }
130
+ }
131
+ for (const v of (0, args_1.valuesOf)(p, '-K', '--config')) {
132
+ analyzer.dynamic(`curl ${v.text === '-' ? 'reads its options from stdin' : `reads its options from ${v.raw}`}`);
133
+ if (v.text !== '-')
134
+ analyzer.addPath(v, 'read', true);
135
+ }
136
+ for (const v of (0, args_1.valuesOf)(p, '-o', '--output', '-c', '--cookie-jar', '-D', '--dump-header')) {
137
+ if (v.text !== '-')
138
+ analyzer.addPath(v, 'write', true);
139
+ }
140
+ for (const v of (0, args_1.valuesOf)(p, '--output-dir'))
141
+ analyzer.addPath(v, 'write', true);
142
+ for (const v of (0, args_1.valuesOf)(p, '-E', '--cert', '--key', '--cacert', '-b', '--cookie')) {
143
+ if ((0, words_1.isPathLike)(v.text))
144
+ analyzer.addPath(v, 'read', true);
145
+ }
146
+ const urls = [...p.positionals, ...(0, args_1.valuesOf)(p, '--url')];
147
+ for (const u of p.positionals)
148
+ if (!(0, words_1.isUrl)(u.text) && (0, words_1.isPathLike)(u.text) && !/^[\w.-]+:\d/.test(u.text))
149
+ analyzer.operand(u);
150
+ const remote = urls.length === 0 || urls.some((u) => u.unknown || !isLocalUrl(u.text));
151
+ if (ctx.stdinFed && dataForms)
152
+ say('curl sends data it reads from stdin');
153
+ else if (ctx.stdinFed && remote)
154
+ say('curl gets piped input and talks to a remote host');
155
+ }
156
+ function wget(ctx, rest) {
157
+ const { analyzer } = ctx;
158
+ const p = (0, args_1.parse)(rest, new Set(['-O', '-o', '-a', '-P', '-i', '--post-file', '--body-file', '--post-data', '--body-data', '--output-document', '--input-file']));
159
+ for (const v of (0, args_1.valuesOf)(p, '--post-file', '--body-file')) {
160
+ analyzer.flag('upload', `it uploads data: wget sends ${v.raw}`);
161
+ analyzer.addPath(v, 'read', true);
162
+ }
163
+ // Like curl -d: a body built from a variable may carry anything.
164
+ for (const key of ['--post-data', '--body-data']) {
165
+ for (const v of p.values.get(key) ?? []) {
166
+ if (v.unknown)
167
+ analyzer.flag('upload', `it uploads data: wget ${key} with a value from a variable or substitution`);
168
+ }
169
+ }
170
+ for (const v of (0, args_1.valuesOf)(p, '-O', '--output-document', '-o', '-a', '-P')) {
171
+ if (v.text !== '-')
172
+ analyzer.addPath(v, 'write', true);
173
+ }
174
+ for (const v of (0, args_1.valuesOf)(p, '-i', '--input-file'))
175
+ if (v.text !== '-')
176
+ analyzer.addPath(v, 'read', true);
177
+ const remote = p.positionals.length === 0 || p.positionals.some((u) => u.unknown || !isLocalUrl(u.text));
178
+ if (ctx.stdinFed && remote)
179
+ analyzer.flag('upload', 'it uploads data: wget gets piped input and talks to a remote host');
180
+ }
181
+ function remoteCopy(name, ctx, rest) {
182
+ const { analyzer } = ctx;
183
+ const withValue = name === 'scp'
184
+ ? new Set(['-i', '-F', '-P', '-o', '-c', '-l', '-S', '-J'])
185
+ : new Set(['-e', '--rsh', '--exclude', '--include', '--exclude-from', '--include-from', '--files-from', '-f', '--filter']);
186
+ const p = (0, args_1.parse)(rest, withValue);
187
+ for (const v of (0, args_1.valuesOf)(p, '-i', '-F', '--exclude-from', '--include-from', '--files-from')) {
188
+ if (v.text === '-')
189
+ analyzer.flag('stdin-operands', `${name} takes file names from its input, which cannot be checked before it runs`);
190
+ else
191
+ analyzer.addPath(v, 'read', true);
192
+ }
193
+ const ops = p.positionals;
194
+ if (ops.length === 0)
195
+ return;
196
+ const dest = ops[ops.length - 1];
197
+ const sources = ops.slice(0, -1);
198
+ if ((0, words_1.isRemoteSpec)(dest.text) || dest.unknown) {
199
+ analyzer.flag('upload', `it uploads data: ${name} copies to the remote ${dest.raw}`);
200
+ }
201
+ else {
202
+ analyzer.addPath(dest, 'write', true);
203
+ }
204
+ for (const s of sources)
205
+ if (!(0, words_1.isRemoteSpec)(s.text))
206
+ analyzer.addPath(s, 'read', true);
207
+ }
208
+ function ssh(ctx, rest) {
209
+ const { analyzer } = ctx;
210
+ const p = (0, args_1.parse)(rest, new Set(['-i', '-F', '-o', '-p', '-l', '-J', '-L', '-R', '-D', '-E', '-S', '-W', '-b', '-c', '-e', '-m', '-O', '-Q', '-w']));
211
+ for (const v of (0, args_1.valuesOf)(p, '-i', '-F'))
212
+ analyzer.addPath(v, 'read', true);
213
+ if ((0, args_1.has)(p, '-R'))
214
+ expose(ctx, 'ssh -R forwards a port from a remote host to this machine');
215
+ if (ctx.stdinFed)
216
+ analyzer.flag('upload', 'it uploads data: ssh gets piped input');
217
+ }
218
+ function expose(ctx, what) {
219
+ ctx.analyzer.flag('network-exposure', `it exposes this machine to the network: ${what}`);
220
+ }
221
+ /** Tunnels that put a local port on the internet. */
222
+ exports.TUNNELS = new Set(['ngrok', 'cloudflared', 'localtunnel', 'lt']);
223
+ function tunnel(name, ctx, rest) {
224
+ expose(ctx, `${name} opens a public tunnel to a local port`);
225
+ (0, args_1.generic)(ctx, rest.filter((a) => (0, words_1.isPathLike)(a.text)));
226
+ }
227
+ /** The value of one option, as `-b X`, `-bX`, `--bind X` or `--bind=X`. */
228
+ function optionValue(rest, short, long) {
229
+ for (let k = 0; k < rest.length; k++) {
230
+ const t = rest[k].text;
231
+ if (t === short || t === long)
232
+ return rest[k + 1]?.text ?? '';
233
+ if (long && t.startsWith(`${long}=`))
234
+ return t.slice(long.length + 1);
235
+ if (short && t.startsWith(short) && t.length > short.length && !t.startsWith('--'))
236
+ return t.slice(short.length);
237
+ }
238
+ return undefined;
239
+ }
240
+ /** The host of `host:port`, `[::1]:port` or a bare host. */
241
+ function hostOf(address) {
242
+ const v6 = /^\[([^\]]*)\]/.exec(address);
243
+ if (v6)
244
+ return v6[1];
245
+ const colon = address.lastIndexOf(':');
246
+ return colon > 0 && address.indexOf(':') === colon ? address.slice(0, colon) : address;
247
+ }
248
+ /** A dev server that serves files on an address: asks unless it is loopback only. */
249
+ function serves(ctx, what, address) {
250
+ if (address !== undefined && address !== '' && (0, words_1.isLoopbackHost)(hostOf(address)))
251
+ return;
252
+ expose(ctx, `${what} serves files on ${address ? hostOf(address) : 'every network interface'}`);
253
+ }
254
+ /** `python -m http.server` binds every interface unless `--bind` says otherwise. */
255
+ function pythonServer(ctx, module, args) {
256
+ if (module === 'SimpleHTTPServer')
257
+ serves(ctx, 'python -m SimpleHTTPServer', undefined);
258
+ else if (module === 'http.server')
259
+ serves(ctx, 'python -m http.server', optionValue(args, '-b', '--bind'));
260
+ }
261
+ /** `php -S host:port`. */
262
+ function phpServer(ctx, rest) {
263
+ const address = optionValue(rest, '-S', null);
264
+ if (address !== undefined)
265
+ serves(ctx, 'php -S', address);
266
+ }
267
+ /** `ruby -run -e httpd`. */
268
+ function rubyServer(ctx, rest) {
269
+ const un = rest.some((a, k) => a.text === '-run' || (a.text === '-r' && rest[k + 1]?.text === 'un'));
270
+ if (un && rest.some((a) => a.text === 'httpd'))
271
+ serves(ctx, 'ruby -run -e httpd', optionValue(rest, null, '--bind-address'));
272
+ }
273
+ /** `busybox httpd -p [ip:]port`. */
274
+ function busyboxServer(ctx, rest) {
275
+ const port = optionValue(rest, '-p', null);
276
+ serves(ctx, 'busybox httpd', port !== undefined && port.includes(':') ? port : undefined);
277
+ }
278
+ /** Commands that send a package or an image to a registry, by program, and the subcommand that does. */
279
+ const PUBLISH = new Map([
280
+ ['npm', 'publish'],
281
+ ['pnpm', 'publish'],
282
+ ['yarn', 'publish'],
283
+ ['bun', 'publish'],
284
+ ['gem', 'push'],
285
+ ['twine', 'upload'],
286
+ ['cargo', 'publish'],
287
+ ['docker', 'push'],
288
+ ['podman', 'push']
289
+ ]);
290
+ /** `npm publish`, `docker push`, …: an upload. */
291
+ function publishes(name, ctx, rest) {
292
+ const sub = PUBLISH.get(name);
293
+ if (sub && rest.some((a) => a.text === sub))
294
+ ctx.analyzer.flag('upload', `it uploads data: ${name} ${sub} sends it to a registry`);
295
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Quoting and bracket matching for the lexer: where a quote, a substitution or
3
+ * a `${…}` ends, and how `$'…'` decodes. Every helper throws `LexError` on
4
+ * input that does not close, and the lexer turns that into `shell-dynamic`.
5
+ */
6
+ export declare class LexError extends Error {
7
+ }
8
+ /** Find the `)` that closes a `(` at `open`, skipping quotes and nested parens. */
9
+ export declare function matchParen(s: string, open: number): number;
10
+ export declare function matchBacktick(s: string, open: number): number;
11
+ export declare function matchBrace(s: string, open: number): number;
12
+ /** Decode a `$'…'` body (ANSI-C quoting), so `$'\x72m'` reads as `rm`. */
13
+ export declare function decodeAnsiC(body: string): string;
14
+ export declare function findAnsiClose(s: string, from: number): number;
15
+ export declare function unescapeBackticks(inner: string): string;
16
+ export declare function stripQuotes(text: string): string;
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /**
3
+ * Quoting and bracket matching for the lexer: where a quote, a substitution or
4
+ * a `${…}` ends, and how `$'…'` decodes. Every helper throws `LexError` on
5
+ * input that does not close, and the lexer turns that into `shell-dynamic`.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.LexError = void 0;
9
+ exports.matchParen = matchParen;
10
+ exports.matchBacktick = matchBacktick;
11
+ exports.matchBrace = matchBrace;
12
+ exports.decodeAnsiC = decodeAnsiC;
13
+ exports.findAnsiClose = findAnsiClose;
14
+ exports.unescapeBackticks = unescapeBackticks;
15
+ exports.stripQuotes = stripQuotes;
16
+ class LexError extends Error {
17
+ }
18
+ exports.LexError = LexError;
19
+ /** Find the `)` that closes a `(` at `open`, skipping quotes and nested parens. */
20
+ function matchParen(s, open) {
21
+ let depth = 0;
22
+ for (let i = open; i < s.length; i++) {
23
+ const ch = s[i];
24
+ if (ch === '\\') {
25
+ i++;
26
+ }
27
+ else if (ch === "'") {
28
+ const end = s.indexOf("'", i + 1);
29
+ if (end < 0)
30
+ throw new LexError('unterminated single quote');
31
+ i = end;
32
+ }
33
+ else if (ch === '"') {
34
+ i = skipDouble(s, i);
35
+ }
36
+ else if (ch === '`') {
37
+ i = matchBacktick(s, i);
38
+ }
39
+ else if (ch === '(') {
40
+ depth++;
41
+ }
42
+ else if (ch === ')') {
43
+ depth--;
44
+ if (depth === 0)
45
+ return i;
46
+ }
47
+ }
48
+ throw new LexError('unterminated substitution');
49
+ }
50
+ function skipDouble(s, open) {
51
+ for (let i = open + 1; i < s.length; i++) {
52
+ const ch = s[i];
53
+ if (ch === '\\')
54
+ i++;
55
+ else if (ch === '"')
56
+ return i;
57
+ else if (ch === '$' && s[i + 1] === '(')
58
+ i = matchParen(s, i + 1);
59
+ else if (ch === '`')
60
+ i = matchBacktick(s, i);
61
+ }
62
+ throw new LexError('unterminated double quote');
63
+ }
64
+ function matchBacktick(s, open) {
65
+ for (let i = open + 1; i < s.length; i++) {
66
+ if (s[i] === '\\')
67
+ i++;
68
+ else if (s[i] === '`')
69
+ return i;
70
+ }
71
+ throw new LexError('unterminated backtick');
72
+ }
73
+ function matchBrace(s, open) {
74
+ let depth = 0;
75
+ for (let i = open; i < s.length; i++) {
76
+ const ch = s[i];
77
+ if (ch === '\\')
78
+ i++;
79
+ else if (ch === "'") {
80
+ const end = s.indexOf("'", i + 1);
81
+ if (end < 0)
82
+ throw new LexError('unterminated single quote');
83
+ i = end;
84
+ }
85
+ else if (ch === '"')
86
+ i = skipDouble(s, i);
87
+ else if (ch === '{')
88
+ depth++;
89
+ else if (ch === '}') {
90
+ depth--;
91
+ if (depth === 0)
92
+ return i;
93
+ }
94
+ }
95
+ throw new LexError('unterminated ${');
96
+ }
97
+ const ANSI_ESCAPES = {
98
+ n: '\n',
99
+ t: '\t',
100
+ r: '\r',
101
+ a: '\x07',
102
+ b: '\b',
103
+ e: '\x1b',
104
+ E: '\x1b',
105
+ f: '\f',
106
+ v: '\v',
107
+ '\\': '\\',
108
+ "'": "'",
109
+ '"': '"',
110
+ '?': '?'
111
+ };
112
+ /** Decode a `$'…'` body (ANSI-C quoting), so `$'\x72m'` reads as `rm`. */
113
+ function decodeAnsiC(body) {
114
+ let out = '';
115
+ for (let i = 0; i < body.length; i++) {
116
+ const ch = body[i];
117
+ if (ch !== '\\' || i + 1 >= body.length) {
118
+ out += ch;
119
+ continue;
120
+ }
121
+ const next = body[++i];
122
+ if (ANSI_ESCAPES[next] !== undefined) {
123
+ out += ANSI_ESCAPES[next];
124
+ }
125
+ else if (next === 'x') {
126
+ const hex = /^[0-9a-fA-F]{1,2}/.exec(body.slice(i + 1))?.[0] ?? '';
127
+ out += hex ? String.fromCharCode(parseInt(hex, 16)) : '\\x';
128
+ i += hex.length;
129
+ }
130
+ else if (next === 'u' || next === 'U') {
131
+ const hex = new RegExp(`^[0-9a-fA-F]{1,${next === 'u' ? 4 : 8}}`).exec(body.slice(i + 1))?.[0] ?? '';
132
+ out += hex ? String.fromCodePoint(parseInt(hex, 16)) : `\\${next}`;
133
+ i += hex.length;
134
+ }
135
+ else if (/[0-7]/.test(next)) {
136
+ const oct = /^[0-7]{1,3}/.exec(body.slice(i))?.[0] ?? next;
137
+ out += String.fromCharCode(parseInt(oct, 8));
138
+ i += oct.length - 1;
139
+ }
140
+ else if (next === 'c') {
141
+ out += String.fromCharCode((body.charCodeAt(i + 1) || 64) & 31);
142
+ i++;
143
+ }
144
+ else {
145
+ out += `\\${next}`;
146
+ }
147
+ }
148
+ return out;
149
+ }
150
+ function findAnsiClose(s, from) {
151
+ for (let i = from; i < s.length; i++) {
152
+ if (s[i] === '\\')
153
+ i++;
154
+ else if (s[i] === "'")
155
+ return i;
156
+ }
157
+ throw new LexError("unterminated $'");
158
+ }
159
+ function unescapeBackticks(inner) {
160
+ return inner.replace(/\\([`$\\])/g, '$1');
161
+ }
162
+ function stripQuotes(text) {
163
+ return text.replace(/^(['"])(.*)\1$/s, '$2');
164
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Commands that reach past the project into the machine: jobs and services
3
+ * that outlive the session, the macOS keychain, the clipboard, and archivers
4
+ * that take their file names from stdin.
5
+ */
6
+ import type { Arg } from './analyze';
7
+ import { type CommandContext } from './args';
8
+ /** `crontab`, `at`, `launchctl load`, `defaults write`: a change that lasts past this session. */
9
+ export declare function persistence(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
10
+ /** `security find-generic-password`, …: a read of the keychain, which the hard-deny list blocks. */
11
+ export declare function security(ctx: CommandContext, rest: readonly Arg[]): void;
12
+ export declare const CLIPBOARD: Set<string>;
13
+ /** The clipboard: a paste shows the model what the user copied, a copy may carry a secret file out. */
14
+ export declare function clipboard(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
15
+ /** `cpio -o`, `tar -T -`, `zip -@`: the file names come from stdin. */
16
+ export declare function namesFromStdin(name: string, rest: readonly Arg[]): boolean;