@seanmozeik/tripwire 0.7.0 → 0.7.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 +16 -14
- package/dist/index.js +35 -0
- package/dist/tripwire-cli.js +3 -0
- package/dist/tripwire-hook.js +3 -0
- package/dist/tripwire-pi.js +6 -4
- package/dist/tripwire.js +141 -0
- package/dist/types/dispatch.d.ts +18 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/lib/bash.d.ts +27 -0
- package/dist/types/lib/config.d.ts +110 -0
- package/dist/types/lib/cursor.d.ts +16 -0
- package/dist/types/lib/decision.d.ts +13 -0
- package/dist/types/lib/diff.d.ts +3 -0
- package/dist/types/lib/event.d.ts +45 -0
- package/dist/types/lib/log.d.ts +2 -0
- package/dist/types/lib/secrets.d.ts +41 -0
- package/dist/types/rules/bash-deny.d.ts +5 -0
- package/dist/types/rules/bash-git.d.ts +5 -0
- package/dist/types/rules/bash-network-install.d.ts +4 -0
- package/dist/types/rules/bash-redirect.d.ts +4 -0
- package/dist/types/rules/bash-scoped-rm.d.ts +5 -0
- package/dist/types/rules/bash-tar-explosion.d.ts +4 -0
- package/dist/types/rules/config-custom.d.ts +6 -0
- package/dist/types/rules/lazy-code.d.ts +4 -0
- package/dist/types/rules/path-protect.d.ts +12 -0
- package/dist/types/rules/post-secret-scrub.d.ts +12 -0
- package/dist/types/rules/read-protect.d.ts +4 -0
- package/dist/types/rules/tool-policy.d.ts +5 -0
- package/package.json +16 -13
- package/dist/tripwire +0 -0
- package/scripts/tripwire-cli +0 -12
- package/src/cli.ts +0 -271
- package/src/dispatch.ts +0 -562
- package/src/index.ts +0 -6
- package/src/lib/bash.ts +0 -1328
- package/src/lib/config.ts +0 -174
- package/src/lib/cursor.ts +0 -336
- package/src/lib/decision.ts +0 -36
- package/src/lib/diff.ts +0 -29
- package/src/lib/event.ts +0 -105
- package/src/lib/install.ts +0 -610
- package/src/lib/log.ts +0 -23
- package/src/lib/secrets.ts +0 -184
- package/src/main.ts +0 -31
- package/src/pi-extension.ts +0 -337
- package/src/rules/bash-deny.ts +0 -404
- package/src/rules/bash-git.ts +0 -590
- package/src/rules/bash-network-install.ts +0 -75
- package/src/rules/bash-redirect.ts +0 -91
- package/src/rules/bash-scoped-rm.ts +0 -84
- package/src/rules/bash-tar-explosion.ts +0 -77
- package/src/rules/config-custom.ts +0 -166
- package/src/rules/lazy-code.ts +0 -95
- package/src/rules/path-protect.ts +0 -131
- package/src/rules/post-secret-scrub.ts +0 -49
- package/src/rules/read-protect.ts +0 -57
- package/src/rules/tool-policy.ts +0 -54
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type Decision, allow, deny } from '../lib/decision';
|
|
2
|
-
import type { ReadInput } from '../lib/event';
|
|
3
|
-
import { classifyProtectedPath, type ProtectedPathSpec } from './path-protect';
|
|
4
|
-
|
|
5
|
-
const PROTECTIONS: readonly ProtectedPathSpec[] = [
|
|
6
|
-
{
|
|
7
|
-
rule: 'read-env',
|
|
8
|
-
pattern: /(?<prefix>^|\/)\.env(?<ext>\.[^/]+)?$/,
|
|
9
|
-
message:
|
|
10
|
-
'.env files hold secrets that should never enter the model context. Refuse to read. If the goal is documenting required env vars, look at .env.example or describe the schema from memory.',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
rule: 'read-dev-vars',
|
|
14
|
-
pattern: /(?<prefix>^|\/)\.dev\.vars(?<ext>\.[^/]+)?$/,
|
|
15
|
-
message: 'Refuse to read .dev.vars (Cloudflare/Wrangler secrets).',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
rule: 'read-ssh',
|
|
19
|
-
pattern: /(?<prefix>^|\/)\.ssh\//,
|
|
20
|
-
message: 'Refuse to read files inside ~/.ssh/.',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
rule: 'read-ssh-key',
|
|
24
|
-
pattern: /(?<prefix>^|\/)(?<key>id_rsa|id_ed25519|id_ecdsa|id_dsa)$/,
|
|
25
|
-
message: 'Refuse to read SSH private key files.',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
rule: 'read-private-key',
|
|
29
|
-
pattern: /\.(?<ext>pem|key|p12|pfx)$/i,
|
|
30
|
-
message: 'Refuse to read private-key-shaped files.',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
rule: 'read-aws-credentials',
|
|
34
|
-
pattern: /(?<prefix>^|\/)\.aws\/credentials$/,
|
|
35
|
-
message: 'Refuse to read ~/.aws/credentials.',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
rule: 'read-netrc',
|
|
39
|
-
pattern: /(?<prefix>^|\/)\.netrc$/,
|
|
40
|
-
message: 'Refuse to read ~/.netrc (host credentials).',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
rule: 'read-secrets-file',
|
|
44
|
-
pattern: /(?<prefix>^|\/)secrets?\.(?<ext>json|ya?ml|toml|env)$/i,
|
|
45
|
-
message: 'Refuse to read a file named secrets.{json,yaml,toml,env}.',
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
const readProtect = (input: ReadInput): Decision => {
|
|
50
|
-
const protection = classifyProtectedPath(input.file_path, 'read', PROTECTIONS);
|
|
51
|
-
if (protection !== null) {
|
|
52
|
-
return deny(protection.rule, protection.message);
|
|
53
|
-
}
|
|
54
|
-
return allow('read-protect');
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export { readProtect };
|
package/src/rules/tool-policy.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type Segment, hasBypass } from '../lib/bash';
|
|
2
|
-
import type { ToolPolicy } from '../lib/config';
|
|
3
|
-
import { type Decision, allow, deny, warn } from '../lib/decision';
|
|
4
|
-
|
|
5
|
-
const hasShortFlag = (flags: readonly string[], expected: string): boolean =>
|
|
6
|
-
flags.some(
|
|
7
|
-
(flag) => flag.startsWith('-') && !flag.startsWith('--') && flag.slice(1).includes(expected),
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const matches = (segment: Segment, policy: ToolPolicy): boolean => {
|
|
11
|
-
if (!policy.executables.includes(segment.head)) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const commandArguments = segment.tokens.slice(1);
|
|
16
|
-
const commandArgumentSet = new Set(commandArguments);
|
|
17
|
-
if (
|
|
18
|
-
!(policy.match?.argumentsIncludeAll ?? []).every((argument) => commandArgumentSet.has(argument))
|
|
19
|
-
) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (
|
|
23
|
-
!(policy.match?.argumentsStartWith ?? []).every(
|
|
24
|
-
(argument, index) => commandArguments[index] === argument,
|
|
25
|
-
)
|
|
26
|
-
) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return (policy.match?.shortFlagsIncludeAll ?? []).every((flag) =>
|
|
30
|
-
hasShortFlag(segment.flags, flag),
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const toolPolicy = (
|
|
35
|
-
segments: readonly Segment[],
|
|
36
|
-
command: string,
|
|
37
|
-
policies: readonly ToolPolicy[],
|
|
38
|
-
): Decision => {
|
|
39
|
-
if (hasBypass(command)) {
|
|
40
|
-
return allow('tool-policy');
|
|
41
|
-
}
|
|
42
|
-
for (const segment of segments) {
|
|
43
|
-
for (const policy of policies) {
|
|
44
|
-
if (matches(segment, policy)) {
|
|
45
|
-
return policy.action === 'deny'
|
|
46
|
-
? deny(policy.rule, policy.message)
|
|
47
|
-
: warn(policy.rule, policy.message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return allow('tool-policy');
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export { toolPolicy };
|