@r_masseater/h56m 0.0.0 → 0.2.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 +87 -0
- package/README.md +77 -1
- package/THIRD-PARTY-NOTICES.txt +531 -0
- package/dist/cli-DK1xNWFT.mjs +38 -0
- package/dist/cli-DK1xNWFT.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +9 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index-C3x2L0fZ.d.mts +53 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +1 -0
- package/dist/section-CRZpQXpe.mjs +210 -0
- package/dist/section-CRZpQXpe.mjs.map +1 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.mjs +1 -0
- package/logo.svg +7 -0
- package/package.json +90 -5
- package/skills/scan-secrets/SKILL.md +83 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { Array, Boolean, Console, Effect, FileSystem, Function, Layer, Match, Option, Order, Path, Predicate, Record, Schema, String as String$1, pipe } from "effect";
|
|
3
|
+
import { runMain } from "@effect/platform-node/NodeRuntime";
|
|
4
|
+
import { layer } from "@effect/platform-node/NodeServices";
|
|
5
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
6
|
+
import { FetchHttpClient } from "effect/http";
|
|
7
|
+
import { Otlp, OtlpSerialization } from "effect/observability";
|
|
8
|
+
import { resolveConfigFromFile } from "vite-plus";
|
|
9
|
+
// ../lint-host/src/shared/lib/target.ts
|
|
10
|
+
const abiOf = (platform) => Match.value(platform).pipe(Match.when("linux", () => "-gnu"), Match.when("win32", () => "-msvc"), Match.orElse(() => ""));
|
|
11
|
+
const platformTarget = `${process.platform}-${process.arch}${abiOf(process.platform)}`;
|
|
12
|
+
const addonFileOf = (binary) => `${binary}.${platformTarget}.node`;
|
|
13
|
+
// ../lint-host/src/features/build-addon/model/build.ts
|
|
14
|
+
const taggedError$1 = Schema.TaggedError;
|
|
15
|
+
var AddonBuildFailed = class extends taggedError$1()("AddonBuildFailed", { message: Schema.String }) {};
|
|
16
|
+
const LIBRARY = {
|
|
17
|
+
linux: (name) => `lib${name}.so`,
|
|
18
|
+
darwin: (name) => `lib${name}.dylib`,
|
|
19
|
+
win32: (name) => `${name}.dll`
|
|
20
|
+
};
|
|
21
|
+
const SUCCESS = 0;
|
|
22
|
+
const cargo = Effect.fn("cargo")(function* cargo(crate, workspace) {
|
|
23
|
+
const exitCode = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("cargo", [
|
|
24
|
+
"build",
|
|
25
|
+
"--release",
|
|
26
|
+
"--locked",
|
|
27
|
+
"-p",
|
|
28
|
+
crate
|
|
29
|
+
], {
|
|
30
|
+
cwd: workspace,
|
|
31
|
+
stdout: "inherit",
|
|
32
|
+
stderr: "inherit"
|
|
33
|
+
}));
|
|
34
|
+
const failure = AddonBuildFailed.make({ message: `cargo exited with ${String(exitCode)}` });
|
|
35
|
+
yield* Effect.when(Effect.fail(failure), Effect.sync(() => Number(exitCode) !== SUCCESS));
|
|
36
|
+
});
|
|
37
|
+
Effect.fn("buildAddon")(function* build(options) {
|
|
38
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
39
|
+
const path = yield* Path.Path;
|
|
40
|
+
const library = yield* Effect.fromOption(Record.get(LIBRARY, process.platform)).pipe(Effect.mapError(() => AddonBuildFailed.make({ message: `no native build for ${process.platform}` })));
|
|
41
|
+
yield* cargo(options.crate, options.workspaceDir);
|
|
42
|
+
const output = path.join(options.packageDir, "native");
|
|
43
|
+
yield* fileSystem.makeDirectory(output, { recursive: true });
|
|
44
|
+
const built = library(String$1.replaceAll("-", "_")(options.crate));
|
|
45
|
+
yield* fileSystem.copyFile(path.join(options.workspaceDir, "target", "release", built), path.join(output, addonFileOf(options.binary)));
|
|
46
|
+
});
|
|
47
|
+
// ../lint-host/src/features/load-addon/model/load.ts
|
|
48
|
+
const loadAddon = ({ packageName, binary, from, isAddon, failWith }) => {
|
|
49
|
+
const requireFrom = createRequire(from);
|
|
50
|
+
const loadFrom = (specifier) => Effect.try({
|
|
51
|
+
try: () => requireFrom(specifier),
|
|
52
|
+
catch: failWith(`could not load ${specifier}`)
|
|
53
|
+
});
|
|
54
|
+
return loadFrom(`${packageName}-${platformTarget}`).pipe(Effect.catchCause(() => loadFrom(`${packageName}/native/${addonFileOf(binary)}`)), Effect.filterOrFail(isAddon, (found) => failWith(`no ${binary} addon for ${platformTarget}`)(found)));
|
|
55
|
+
};
|
|
56
|
+
const callAddon = ({ addon, name, files, call, failWith }) => addon.pipe(Effect.flatMap((loaded) => Effect.try({
|
|
57
|
+
try: () => call(loaded),
|
|
58
|
+
catch: failWith(`${name} could not lint`)
|
|
59
|
+
}).pipe(Effect.tap(() => Effect.promise(() => loaded.flushTelemetry())))), Effect.withSpan(`${name}.native`, { attributes: { [`${name}.files`]: files } }));
|
|
60
|
+
// ../lint-host/src/features/run-cli/model/cli.ts
|
|
61
|
+
const CONFIG_FILES = [
|
|
62
|
+
"vite.config.ts",
|
|
63
|
+
"vite.config.mts",
|
|
64
|
+
"vite.config.js",
|
|
65
|
+
"vite.config.mjs"
|
|
66
|
+
];
|
|
67
|
+
const FAILED = 1;
|
|
68
|
+
const DATA_FIRST_ARITY$1 = 2;
|
|
69
|
+
const ARGUMENTS_START = 2;
|
|
70
|
+
const readSectionIn = (source, root) => Effect.gen(function* readConfig() {
|
|
71
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
72
|
+
const path = yield* Path.Path;
|
|
73
|
+
const found = yield* pipe(CONFIG_FILES, Array.map((name) => path.join(root, name)), Effect.filter((file) => fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))));
|
|
74
|
+
const loaded = yield* Option.match(Array.head(found), {
|
|
75
|
+
onNone: () => Effect.succeed({}),
|
|
76
|
+
onSome: (file) => Effect.tryPromise({
|
|
77
|
+
try: () => resolveConfigFromFile(file),
|
|
78
|
+
catch: source.failWith(`could not load ${file}`)
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
return source.section(loaded);
|
|
82
|
+
}).pipe(Effect.withSpan(`${source.name}.config`));
|
|
83
|
+
Function.dual(DATA_FIRST_ARITY$1, readSectionIn);
|
|
84
|
+
const failWhen = (failed) => Effect.when(Effect.sync(() => {
|
|
85
|
+
process.exitCode = FAILED;
|
|
86
|
+
}), Effect.succeed(failed)).pipe(Effect.asVoid);
|
|
87
|
+
const printAll = (found, format) => Array.match(found, {
|
|
88
|
+
onEmpty: () => Effect.void,
|
|
89
|
+
onNonEmpty: (all) => Console.log(pipe(all, Array.map(format), Array.join("\n")))
|
|
90
|
+
});
|
|
91
|
+
const toolMainOf = (tool) => Effect.gen(function* main() {
|
|
92
|
+
const root = process.cwd();
|
|
93
|
+
const config = yield* readSectionIn(tool, root);
|
|
94
|
+
const found = yield* tool.scan({
|
|
95
|
+
root,
|
|
96
|
+
config,
|
|
97
|
+
args: process.argv.slice(ARGUMENTS_START)
|
|
98
|
+
});
|
|
99
|
+
yield* printAll(found, tool.format);
|
|
100
|
+
yield* failWhen(Array.isReadonlyArrayNonEmpty(found));
|
|
101
|
+
});
|
|
102
|
+
const runTraced = (name, program) => {
|
|
103
|
+
const services = Otlp.layerFromConfig({ resource: { serviceName: name } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer), Layer.provideMerge(layer));
|
|
104
|
+
runMain(program.pipe(Effect.provide(services)));
|
|
105
|
+
};
|
|
106
|
+
const runTool = (tool) => {
|
|
107
|
+
runTraced(tool.name, toolMainOf(tool));
|
|
108
|
+
};
|
|
109
|
+
Function.dual(2, (value, build) => Option.match(value, {
|
|
110
|
+
onNone: () => ({}),
|
|
111
|
+
onSome: build
|
|
112
|
+
}));
|
|
113
|
+
// ../lint-host/src/shared/lib/trace.ts
|
|
114
|
+
const SAMPLED = "01";
|
|
115
|
+
const NOT_SAMPLED = "00";
|
|
116
|
+
const LINE_START = 0;
|
|
117
|
+
const flagsOf = (sampled) => Boolean.match(sampled, {
|
|
118
|
+
onFalse: () => NOT_SAMPLED,
|
|
119
|
+
onTrue: () => SAMPLED
|
|
120
|
+
});
|
|
121
|
+
const traceparent = Effect.currentSpan.pipe(Effect.map((span) => `00-${span.traceId}-${span.spanId}-${flagsOf(span.sampled)}`), Effect.option);
|
|
122
|
+
Order.combine(Order.mapInput(Order.String, (found) => found.path), Order.combine(Order.mapInput(Order.Number, (found) => found.line), Order.mapInput(Order.Number, (found) => found.column ?? LINE_START)));
|
|
123
|
+
// src/shared/config/types.ts
|
|
124
|
+
const FindingSchema = Schema.Struct({
|
|
125
|
+
rule: Schema.String,
|
|
126
|
+
description: Schema.String,
|
|
127
|
+
confidence: Schema.Literals([
|
|
128
|
+
"low",
|
|
129
|
+
"medium",
|
|
130
|
+
"high"
|
|
131
|
+
]),
|
|
132
|
+
path: Schema.String,
|
|
133
|
+
line: Schema.Int,
|
|
134
|
+
column: Schema.Int,
|
|
135
|
+
endLine: Schema.Int,
|
|
136
|
+
endColumn: Schema.Int,
|
|
137
|
+
secret: Schema.String,
|
|
138
|
+
digest: Schema.String,
|
|
139
|
+
commit: Schema.optionalKey(Schema.String),
|
|
140
|
+
encoded: Schema.Boolean
|
|
141
|
+
});
|
|
142
|
+
// src/shared/lib/errors.ts
|
|
143
|
+
const taggedError = Schema.TaggedError;
|
|
144
|
+
var H56mError = class extends taggedError()("H56mError", { message: Schema.String }) {};
|
|
145
|
+
const failedWith = (message) => (cause) => H56mError.make({ message: `${message}: ${String(cause)}` });
|
|
146
|
+
// src/shared/native/index.ts
|
|
147
|
+
const isNative = (value) => Predicate.hasProperty(value, "SecretDetector") && Predicate.isFunction(value.SecretDetector) && Predicate.hasProperty(value, "flushTelemetry") && Predicate.isFunction(value.flushTelemetry);
|
|
148
|
+
const native = loadAddon({
|
|
149
|
+
packageName: "@r_masseater/h56m",
|
|
150
|
+
binary: "h56m",
|
|
151
|
+
from: import.meta.url,
|
|
152
|
+
isAddon: isNative,
|
|
153
|
+
failWith: failedWith
|
|
154
|
+
});
|
|
155
|
+
// src/app/detector.ts
|
|
156
|
+
const ONE_FILE = 1;
|
|
157
|
+
const WHOLE_REPOSITORY = 0;
|
|
158
|
+
const decodeFindings = Schema.decodeUnknownEffect(Schema.Array(FindingSchema));
|
|
159
|
+
const withParent = (input) => traceparent.pipe(Effect.map(Option.match({
|
|
160
|
+
onNone: () => input,
|
|
161
|
+
onSome: (value) => ({
|
|
162
|
+
...input,
|
|
163
|
+
traceparent: value
|
|
164
|
+
})
|
|
165
|
+
})));
|
|
166
|
+
const run = ({ name, files, call }) => callAddon({
|
|
167
|
+
addon: native,
|
|
168
|
+
name,
|
|
169
|
+
files,
|
|
170
|
+
call,
|
|
171
|
+
failWith: failedWith
|
|
172
|
+
}).pipe(Effect.flatMap((found) => decodeFindings(found).pipe(Effect.mapError(failedWith("h56m returned an unknown shape")))));
|
|
173
|
+
const scannerOf = (detector) => ({
|
|
174
|
+
scanText: (scan) => withParent(scan).pipe(Effect.flatMap((input) => run({
|
|
175
|
+
name: "h56m.text",
|
|
176
|
+
files: ONE_FILE,
|
|
177
|
+
call: () => detector.scan(input)
|
|
178
|
+
})), Effect.withSpan("h56m.scan_text")),
|
|
179
|
+
scanGit: (scan) => withParent(scan).pipe(Effect.flatMap((input) => run({
|
|
180
|
+
name: "h56m.git",
|
|
181
|
+
files: WHOLE_REPOSITORY,
|
|
182
|
+
call: () => detector.scanGit(input)
|
|
183
|
+
})), Effect.withSpan("h56m.scan_git", { attributes: { "h56m.source": scan.source.type } }))
|
|
184
|
+
});
|
|
185
|
+
const makeDetector = Effect.fn("h56m.detector")(function* makeDetector(config = {}) {
|
|
186
|
+
const { ignoredSecrets = [], ...rest } = config;
|
|
187
|
+
const input = yield* withParent({
|
|
188
|
+
config: rest,
|
|
189
|
+
ignored: ignoredSecrets
|
|
190
|
+
});
|
|
191
|
+
const detector = yield* callAddon({
|
|
192
|
+
addon: native,
|
|
193
|
+
name: "h56m",
|
|
194
|
+
files: WHOLE_REPOSITORY,
|
|
195
|
+
call: (addon) => new addon.SecretDetector(input),
|
|
196
|
+
failWith: failedWith
|
|
197
|
+
});
|
|
198
|
+
return scannerOf(detector);
|
|
199
|
+
});
|
|
200
|
+
// src/app/format.ts
|
|
201
|
+
const START = 0;
|
|
202
|
+
const SHORT_COMMIT = 12;
|
|
203
|
+
const commitOf = (finding) => pipe(Option.fromNullishOr(finding.commit), Option.map((commit) => ` (${String$1.slice(START, SHORT_COMMIT)(commit)})`), Option.getOrElse(() => ""));
|
|
204
|
+
const format = (finding) => `${finding.path}:${String(finding.line)}:${String(finding.column)} ${finding.rule} ${finding.description} sha256:${finding.digest}${commitOf(finding)}`;
|
|
205
|
+
// src/app/section.ts
|
|
206
|
+
const hasSection = (value) => Predicate.hasProperty(value, "h56m") && Predicate.isObject(value.h56m);
|
|
207
|
+
const h56mSection = (config) => pipe(Option.liftPredicate(config, hasSection), Option.map((value) => value.h56m), Option.getOrElse(() => ({})));
|
|
208
|
+
export { failedWith as a, H56mError as i, format as n, runTool as o, makeDetector as r, h56mSection as t };
|
|
209
|
+
|
|
210
|
+
//# sourceMappingURL=section-CRZpQXpe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section-CRZpQXpe.mjs","names":["taggedError","Rec","Str","DATA_FIRST_ARITY","Arr","Fn","nodeServices","Fn","Bool","Str"],"sources":["../../lint-host/src/shared/lib/target.ts","../../lint-host/src/features/build-addon/model/build.ts","../../lint-host/src/features/load-addon/model/load.ts","../../lint-host/src/features/run-cli/model/cli.ts","../../lint-host/src/shared/lib/present.ts","../../lint-host/src/shared/lib/trace.ts","../src/shared/config/types.ts","../src/shared/lib/errors.ts","../src/shared/native/index.ts","../src/app/detector.ts","../src/app/format.ts","../src/app/section.ts"],"sourcesContent":["import { Match } from \"effect\";\n\nconst abiOf = (platform: string): string =>\n Match.value(platform).pipe(\n Match.when(\"linux\", () => \"-gnu\"),\n Match.when(\"win32\", () => \"-msvc\"),\n Match.orElse(() => \"\"),\n );\n\nexport const platformTarget = `${process.platform}-${process.arch}${abiOf(process.platform)}`;\n\nexport const addonFileOf = (binary: string): string => `${binary}.${platformTarget}.node`;\n","import { runMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport { Effect, FileSystem, Path, Record as Rec, Schema, String as Str } from \"effect\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\n\nimport { addonFileOf } from \"#/shared/lib/target.ts\";\n\nconst taggedError = Schema.TaggedError;\n\nclass AddonBuildFailed extends taggedError<AddonBuildFailed, { readonly brand: unique symbol }>()(\n \"AddonBuildFailed\",\n { message: Schema.String },\n) {}\n\nconst LIBRARY: Readonly<Record<string, (name: string) => string>> = {\n linux: (name) => `lib${name}.so`,\n darwin: (name) => `lib${name}.dylib`,\n win32: (name) => `${name}.dll`,\n};\n\nconst SUCCESS = 0;\n\nexport interface AddonBuild {\n readonly crate: string;\n readonly binary: string;\n readonly packageDir: string;\n readonly workspaceDir: string;\n}\n\nconst cargo = Effect.fn(\"cargo\")(function* cargo(crate: string, workspace: string) {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const exitCode = yield* spawner.exitCode(\n ChildProcess.make(\"cargo\", [\"build\", \"--release\", \"--locked\", \"-p\", crate], {\n cwd: workspace,\n stdout: \"inherit\",\n stderr: \"inherit\",\n }),\n );\n const failure = AddonBuildFailed.make({ message: `cargo exited with ${String(exitCode)}` });\n yield* Effect.when(\n Effect.fail(failure),\n Effect.sync(() => Number(exitCode) !== SUCCESS),\n );\n});\n\nconst build = Effect.fn(\"buildAddon\")(function* build(options: AddonBuild) {\n const fileSystem = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const library = yield* Effect.fromOption(Rec.get(LIBRARY, process.platform)).pipe(\n Effect.mapError(() =>\n AddonBuildFailed.make({ message: `no native build for ${process.platform}` }),\n ),\n );\n yield* cargo(options.crate, options.workspaceDir);\n const output = path.join(options.packageDir, \"native\");\n yield* fileSystem.makeDirectory(output, { recursive: true });\n const built = library(Str.replaceAll(\"-\", \"_\")(options.crate));\n yield* fileSystem.copyFile(\n path.join(options.workspaceDir, \"target\", \"release\", built),\n path.join(output, addonFileOf(options.binary)),\n );\n});\n\nexport const buildAddon = (options: AddonBuild): void => {\n runMain(build(options).pipe(Effect.provide(nodeServices)));\n};\n","import { createRequire } from \"node:module\";\n\nimport { Effect } from \"effect\";\n\nimport type { FailWith } from \"#/shared/lib/fail.ts\";\nimport { addonFileOf, platformTarget } from \"#/shared/lib/target.ts\";\n\nexport interface AddonSource<Addon, Failure> {\n readonly packageName: string;\n readonly binary: string;\n readonly from: string;\n readonly isAddon: (value: unknown) => value is Addon;\n readonly failWith: FailWith<Failure>;\n}\n\nexport const loadAddon = <Addon, Failure>({\n packageName,\n binary,\n from,\n isAddon,\n failWith,\n}: AddonSource<Addon, Failure>): Effect.Effect<Addon, Failure> => {\n const requireFrom = createRequire(from);\n const loadFrom = (specifier: string): Effect.Effect<unknown, Failure> =>\n Effect.try({\n try: (): unknown => requireFrom(specifier),\n catch: failWith(`could not load ${specifier}`),\n });\n return loadFrom(`${packageName}-${platformTarget}`).pipe(\n Effect.catchCause(() => loadFrom(`${packageName}/native/${addonFileOf(binary)}`)),\n Effect.filterOrFail(isAddon, (found) =>\n failWith(`no ${binary} addon for ${platformTarget}`)(found),\n ),\n );\n};\n\nexport interface Telemetered {\n readonly flushTelemetry: () => Promise<void>;\n}\n\nexport interface AddonCall<Addon extends Telemetered, Result, Failure> {\n readonly addon: Effect.Effect<Addon, Failure>;\n readonly name: string;\n readonly files: number;\n readonly call: (addon: Addon) => Result;\n readonly failWith: FailWith<Failure>;\n}\n\nexport const callAddon = <Addon extends Telemetered, Result, Failure>({\n addon,\n name,\n files,\n call,\n failWith,\n}: AddonCall<Addon, Result, Failure>): Effect.Effect<Result, Failure> =>\n addon.pipe(\n Effect.flatMap((loaded) =>\n Effect.try({ try: () => call(loaded), catch: failWith(`${name} could not lint`) }).pipe(\n Effect.tap(() => Effect.promise(() => loaded.flushTelemetry())),\n ),\n ),\n Effect.withSpan(`${name}.native`, { attributes: { [`${name}.files`]: files } }),\n );\n","import { runMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport {\n Array as Arr,\n Console,\n Effect,\n FileSystem,\n Function as Fn,\n Layer,\n Option,\n Path,\n String as Str,\n pipe,\n} from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { Otlp, OtlpSerialization } from \"effect/observability\";\nimport type { PlatformError } from \"effect/PlatformError\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport { resolveConfigFromFile } from \"vite-plus\";\n\nimport type { FailWith } from \"#/shared/lib/fail.ts\";\n\nconst CONFIG_FILES = [\"vite.config.ts\", \"vite.config.mts\", \"vite.config.js\", \"vite.config.mjs\"];\nconst FAILED = 1;\nconst DATA_FIRST_ARITY = 2;\nconst ARGUMENTS_START = 2;\n\nexport interface Reported {\n readonly severity: string;\n}\n\nexport interface LintCall<Config, Failure> {\n readonly root: string;\n readonly files: readonly string[];\n readonly projectFiles: readonly string[];\n readonly config: Config;\n readonly read: (file: string) => Effect.Effect<string, Failure>;\n}\n\nexport interface PathspecRequest<Config> {\n readonly config: Config;\n readonly patterns?: readonly string[];\n}\n\nexport interface SectionSource<Config, Failure> {\n readonly name: string;\n readonly section: (config: unknown) => Config;\n readonly failWith: FailWith<Failure>;\n}\n\nexport interface Cli<Config, Found extends Reported, Failure> extends SectionSource<\n Config,\n Failure\n> {\n readonly pathspecs: (request: PathspecRequest<Config>) => readonly string[];\n readonly lint: (call: LintCall<Config, Failure>) => Effect.Effect<readonly Found[], Failure>;\n readonly format: (found: Found) => string;\n}\n\nexport interface ToolCall<Config> {\n readonly root: string;\n readonly config: Config;\n readonly args: readonly string[];\n}\n\nexport interface Tool<Config, Found, Failure> extends SectionSource<Config, Failure> {\n readonly scan: (call: ToolCall<Config>) => Effect.Effect<readonly Found[], Failure>;\n readonly format: (found: Found) => string;\n}\n\ntype CliServices = FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner;\n\nconst readSectionIn = <Config, Failure>(\n source: SectionSource<Config, Failure>,\n root: string,\n): Effect.Effect<Config, Failure, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function* readConfig() {\n const fileSystem = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const found = yield* pipe(\n CONFIG_FILES,\n Arr.map((name) => path.join(root, name)),\n Effect.filter((file) => fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))),\n );\n const loaded = yield* Option.match(Arr.head(found), {\n onNone: () => Effect.succeed<unknown>({}),\n onSome: (file) =>\n Effect.tryPromise({\n try: () => resolveConfigFromFile(file),\n catch: source.failWith(`could not load ${file}`),\n }),\n });\n return source.section(loaded);\n }).pipe(Effect.withSpan(`${source.name}.config`));\n\n/** @internal */\nexport const readSection: {\n (\n root: string,\n ): <Config, Failure>(\n source: SectionSource<Config, Failure>,\n ) => Effect.Effect<Config, Failure, FileSystem.FileSystem | Path.Path>;\n <Config, Failure>(\n source: SectionSource<Config, Failure>,\n root: string,\n ): Effect.Effect<Config, Failure, FileSystem.FileSystem | Path.Path>;\n} = Fn.dual(DATA_FIRST_ARITY, readSectionIn);\n\nconst trackedFiles = (\n root: string,\n pathspecs: readonly string[],\n): Effect.Effect<readonly string[], PlatformError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function* listFiles() {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const output = yield* spawner.string(\n ChildProcess.make(\n \"git\",\n [\"ls-files\", \"-co\", \"--exclude-standard\", \"-z\", \"--\", ...pathspecs],\n { cwd: root },\n ),\n );\n return pipe(Str.split(output, \"\\0\"), Arr.filter(Str.isNonEmpty));\n });\n\nconst requestOf = <Config>(config: Config, patterns: readonly string[]): PathspecRequest<Config> =>\n Arr.match(patterns, {\n onEmpty: () => ({ config }),\n onNonEmpty: (given) => ({ config, patterns: given }),\n });\n\nconst hasError = (found: readonly Reported[]): boolean =>\n pipe(\n found,\n Arr.some(({ severity }) => severity === \"error\"),\n );\n\nconst failWhen = (failed: boolean): Effect.Effect<void> =>\n Effect.when(\n Effect.sync(() => {\n process.exitCode = FAILED;\n }),\n Effect.succeed(failed),\n ).pipe(Effect.asVoid);\n\nconst printAll = <Found>(\n found: readonly Found[],\n format: (found: Found) => string,\n): Effect.Effect<void> =>\n Arr.match(found, {\n onEmpty: () => Effect.void,\n onNonEmpty: (all) => Console.log(pipe(all, Arr.map(format), Arr.join(\"\\n\"))),\n });\n\nconst readerIn = <Failure>(\n root: string,\n failWith: FailWith<Failure>,\n): Effect.Effect<\n (file: string) => Effect.Effect<string, Failure>,\n never,\n FileSystem.FileSystem | Path.Path\n> =>\n Effect.gen(function* reader() {\n const fileSystem = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n return (file: string): Effect.Effect<string, Failure> =>\n fileSystem\n .readFileString(path.resolve(root, file))\n .pipe(Effect.mapError(failWith(`could not read ${file}`)));\n });\n\nconst mainOf = <Config, Found extends Reported, Failure>(\n cli: Cli<Config, Found, Failure>,\n): Effect.Effect<void, Failure | PlatformError, CliServices> =>\n Effect.gen(function* main() {\n const root = process.cwd();\n const config = yield* readSectionIn(cli, root);\n const patterns = process.argv.slice(ARGUMENTS_START);\n const pathspecs = cli.pathspecs(requestOf(config, patterns));\n const { files, projectFiles } = yield* Effect.all(\n {\n files: trackedFiles(root, pathspecs).pipe(Effect.withSpan(`${cli.name}.files`)),\n projectFiles: trackedFiles(root, []).pipe(Effect.withSpan(`${cli.name}.project`)),\n },\n { concurrency: \"unbounded\" },\n );\n const read = yield* readerIn(root, cli.failWith);\n const found = yield* cli.lint({ root, files, projectFiles, config, read });\n yield* printAll(found, cli.format);\n yield* failWhen(hasError(found));\n });\n\nconst toolMainOf = <Config, Found, Failure>(\n tool: Tool<Config, Found, Failure>,\n): Effect.Effect<void, Failure | PlatformError, CliServices> =>\n Effect.gen(function* main() {\n const root = process.cwd();\n const config = yield* readSectionIn(tool, root);\n const found = yield* tool.scan({ root, config, args: process.argv.slice(ARGUMENTS_START) });\n yield* printAll(found, tool.format);\n yield* failWhen(Arr.isReadonlyArrayNonEmpty(found));\n });\n\nconst runTraced = <Failure>(\n name: string,\n program: Effect.Effect<void, Failure, CliServices>,\n): void => {\n const services = Otlp.layerFromConfig({ resource: { serviceName: name } }).pipe(\n Layer.provide(OtlpSerialization.layerJson),\n Layer.provide(FetchHttpClient.layer),\n Layer.provideMerge(nodeServices),\n );\n runMain(program.pipe(Effect.provide(services)));\n};\n\nexport const runCli = <Config, Found extends Reported, Failure>(\n cli: Cli<Config, Found, Failure>,\n): void => {\n runTraced(cli.name, mainOf(cli));\n};\n\nexport const runTool = <Config, Found, Failure>(tool: Tool<Config, Found, Failure>): void => {\n runTraced(tool.name, toolMainOf(tool));\n};\n","import { Function as Fn, Option } from \"effect\";\n\nconst DATA_FIRST_ARITY = 2;\n\nexport const present: {\n <Value, Fields extends object>(\n build: (value: Value) => Fields,\n ): (value: Option.Option<Value>) => Partial<Fields>;\n <Value, Fields extends object>(\n value: Option.Option<Value>,\n build: (value: Value) => Fields,\n ): Partial<Fields>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n <Value, Fields extends object>(\n value: Option.Option<Value>,\n build: (value: Value) => Fields,\n ): Partial<Fields> => Option.match(value, { onNone: (): Partial<Fields> => ({}), onSome: build }),\n);\n","import { Array as Arr, Boolean as Bool, Effect, Order } from \"effect\";\nimport type { Option } from \"effect\";\n\nconst SAMPLED = \"01\";\nconst NOT_SAMPLED = \"00\";\n\nexport interface Positioned {\n readonly path: string;\n readonly line: number;\n readonly column?: number;\n}\n\nconst LINE_START = 0;\n\nconst flagsOf = (sampled: boolean): string =>\n Bool.match(sampled, { onFalse: () => NOT_SAMPLED, onTrue: () => SAMPLED });\n\nexport const traceparent: Effect.Effect<Option.Option<string>> = Effect.currentSpan.pipe(\n Effect.map((span) => `00-${span.traceId}-${span.spanId}-${flagsOf(span.sampled)}`),\n Effect.option,\n);\n\nconst byPosition: Order.Order<Positioned> = Order.combine(\n Order.mapInput(Order.String, (found: Positioned) => found.path),\n Order.combine(\n Order.mapInput(Order.Number, (found: Positioned) => found.line),\n Order.mapInput(Order.Number, (found: Positioned) => found.column ?? LINE_START),\n ),\n);\n\nexport const sortByPosition = <Found extends Positioned>(found: readonly Found[]): Found[] =>\n Arr.sort(found, byPosition);\n","import { Schema } from \"effect\";\n\nexport interface H56mRule {\n readonly id: string;\n readonly description?: string;\n readonly keywords?: readonly string[];\n readonly regex?: string;\n readonly path?: string;\n readonly valueGroup?: number;\n readonly specificity?: number;\n readonly tags?: readonly string[];\n readonly skipReport?: boolean;\n readonly filter?: string;\n readonly confidence?: \"low\" | \"medium\" | \"high\";\n}\n\nexport interface H56mExtend {\n readonly path?: string;\n readonly disabledRules?: readonly string[];\n}\n\nexport interface H56mConfig {\n readonly extend?: H56mExtend;\n readonly maxDecodeDepth?: number;\n readonly prefilter?: string;\n readonly filter?: string;\n readonly rules?: readonly H56mRule[];\n readonly ignoredSecrets?: readonly string[];\n}\n\nexport const FindingSchema = Schema.Struct({\n rule: Schema.String,\n description: Schema.String,\n confidence: Schema.Literals([\"low\", \"medium\", \"high\"]),\n path: Schema.String,\n line: Schema.Int,\n column: Schema.Int,\n endLine: Schema.Int,\n endColumn: Schema.Int,\n secret: Schema.String,\n digest: Schema.String,\n commit: Schema.optionalKey(Schema.String),\n encoded: Schema.Boolean,\n});\n\nexport type Finding = typeof FindingSchema.Type;\n\nexport type GitSource =\n | { readonly type: \"history\"; readonly bases?: readonly string[]; readonly head: string }\n | { readonly type: \"staged\" }\n | { readonly type: \"snapshot\"; readonly revision: string };\n","import { Schema } from \"effect\";\n\nconst taggedError = Schema.TaggedError;\n\nexport class H56mError extends taggedError<H56mError, { readonly brand: unique symbol }>()(\n \"H56mError\",\n { message: Schema.String },\n) {}\n\nexport const failedWith =\n (message: string) =>\n (cause: unknown): H56mError =>\n H56mError.make({ message: `${message}: ${String(cause)}` });\n","import { loadAddon } from \"@masseater.dev/lint-host\";\nimport { Predicate } from \"effect\";\nimport type { Effect } from \"effect\";\n\nimport type { H56mConfig } from \"#/shared/config/index.ts\";\nimport { failedWith } from \"#/shared/lib/errors.ts\";\nimport type { H56mError } from \"#/shared/lib/errors.ts\";\n\nexport interface DetectorInput {\n readonly config: Omit<H56mConfig, \"ignoredSecrets\">;\n readonly ignored: readonly string[];\n readonly traceparent?: string;\n}\n\nexport interface TextInput {\n readonly path: string;\n readonly text: string;\n readonly traceparent?: string;\n}\n\nexport interface GitInput {\n readonly root: string;\n readonly source: unknown;\n readonly traceparent?: string;\n}\n\nexport interface NativeDetector {\n readonly scan: (input: TextInput) => unknown;\n readonly scanGit: (input: GitInput) => unknown;\n}\n\nexport interface Native {\n readonly SecretDetector: new (input: DetectorInput) => NativeDetector;\n readonly flushTelemetry: () => Promise<void>;\n}\n\nconst isNative = (value: unknown): value is Native =>\n Predicate.hasProperty(value, \"SecretDetector\") &&\n Predicate.isFunction(value.SecretDetector) &&\n Predicate.hasProperty(value, \"flushTelemetry\") &&\n Predicate.isFunction(value.flushTelemetry);\n\nexport const native: Effect.Effect<Native, H56mError> = loadAddon({\n packageName: \"@r_masseater/h56m\",\n binary: \"h56m\",\n from: import.meta.url,\n isAddon: isNative,\n failWith: failedWith,\n});\n","import { callAddon, traceparent } from \"@masseater.dev/lint-host\";\nimport { Effect, Option, Schema } from \"effect\";\n\nimport { FindingSchema } from \"#/shared/config/index.ts\";\nimport type { Finding, GitSource, H56mConfig } from \"#/shared/config/index.ts\";\nimport { failedWith } from \"#/shared/lib/errors.ts\";\nimport type { H56mError } from \"#/shared/lib/errors.ts\";\nimport { native } from \"#/shared/native/index.ts\";\nimport type { NativeDetector } from \"#/shared/native/index.ts\";\n\nconst ONE_FILE = 1;\nconst WHOLE_REPOSITORY = 0;\n\nconst decodeFindings = Schema.decodeUnknownEffect(Schema.Array(FindingSchema));\n\nexport interface TextScan {\n readonly path: string;\n readonly text: string;\n}\n\nexport interface GitScan {\n readonly root: string;\n readonly source: GitSource;\n}\n\nexport interface Detector {\n readonly scanText: (scan: TextScan) => Effect.Effect<readonly Finding[], H56mError>;\n readonly scanGit: (scan: GitScan) => Effect.Effect<readonly Finding[], H56mError>;\n}\n\ntype Traced<Input> = Input | (Input & { readonly traceparent: string });\n\nconst withParent = <Input extends object>(input: Input): Effect.Effect<Traced<Input>> =>\n traceparent.pipe(\n Effect.map(\n Option.match({\n onNone: (): Traced<Input> => input,\n onSome: (value): Traced<Input> => ({ ...input, traceparent: value }),\n }),\n ),\n );\n\ninterface NativeScan {\n readonly name: string;\n readonly files: number;\n readonly call: () => unknown;\n}\n\nconst run = ({ name, files, call }: NativeScan): Effect.Effect<readonly Finding[], H56mError> =>\n callAddon({ addon: native, name, files, call, failWith: failedWith }).pipe(\n Effect.flatMap((found) =>\n decodeFindings(found).pipe(Effect.mapError(failedWith(\"h56m returned an unknown shape\"))),\n ),\n );\n\nconst scannerOf = (detector: NativeDetector): Detector => ({\n scanText: (scan) =>\n withParent(scan).pipe(\n Effect.flatMap((input) =>\n run({ name: \"h56m.text\", files: ONE_FILE, call: () => detector.scan(input) }),\n ),\n Effect.withSpan(\"h56m.scan_text\"),\n ),\n scanGit: (scan) =>\n withParent(scan).pipe(\n Effect.flatMap((input) =>\n run({ name: \"h56m.git\", files: WHOLE_REPOSITORY, call: () => detector.scanGit(input) }),\n ),\n Effect.withSpan(\"h56m.scan_git\", { attributes: { \"h56m.source\": scan.source.type } }),\n ),\n});\n\nexport const makeDetector = Effect.fn(\"h56m.detector\")(function* makeDetector(\n config: H56mConfig = {},\n) {\n const { ignoredSecrets = [], ...rest } = config;\n const input = yield* withParent({ config: rest, ignored: ignoredSecrets });\n const detector = yield* callAddon({\n addon: native,\n name: \"h56m\",\n files: WHOLE_REPOSITORY,\n call: (addon) => new addon.SecretDetector(input),\n failWith: failedWith,\n });\n return scannerOf(detector);\n});\n","import { Option, String as Str, pipe } from \"effect\";\n\nimport type { Finding } from \"#/shared/config/index.ts\";\n\nconst START = 0;\nconst SHORT_COMMIT = 12;\n\nconst commitOf = (finding: Finding): string =>\n pipe(\n Option.fromNullishOr(finding.commit),\n Option.map((commit) => ` (${Str.slice(START, SHORT_COMMIT)(commit)})`),\n Option.getOrElse(() => \"\"),\n );\n\nexport const format = (finding: Finding): string =>\n `${finding.path}:${String(finding.line)}:${String(finding.column)} ${finding.rule} ${finding.description} sha256:${finding.digest}${commitOf(finding)}`;\n","import { Option, Predicate, pipe } from \"effect\";\n\nimport type { H56mConfig } from \"#/shared/config/index.ts\";\n\nconst hasSection = (value: unknown): value is { readonly h56m: H56mConfig } =>\n Predicate.hasProperty(value, \"h56m\") && Predicate.isObject(value.h56m);\n\nexport const h56mSection = (config: unknown): H56mConfig =>\n pipe(\n Option.liftPredicate(config, hasSection),\n Option.map((value) => value.h56m),\n Option.getOrElse((): H56mConfig => ({})),\n );\n"],"mappings":";;;;;;;;;AAEA,MAAM,SAAS,aACb,MAAM,MAAM,QAAQ,CAAC,CAAC,KACpB,MAAM,KAAK,eAAe,MAAM,GAChC,MAAM,KAAK,eAAe,OAAO,GACjC,MAAM,aAAa,EAAE,CACvB;AAEF,MAAa,iBAAiB,GAAG,QAAQ,SAAS,GAAG,QAAQ,OAAO,MAAM,QAAQ,QAAQ;AAE1F,MAAa,eAAe,WAA2B,GAAG,OAAO,GAAG,eAAe;;ACJnF,MAAMA,gBAAc,OAAO;AAE3B,IAAM,mBAAN,cAA+BA,cAAiE,CAAC,CAC/F,oBACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,UAA8D;CAClE,QAAQ,SAAS,MAAM,KAAK;CAC5B,SAAS,SAAS,MAAM,KAAK;CAC7B,QAAQ,SAAS,GAAG,KAAK;AAC3B;AAEA,MAAM,UAAU;AASh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/C,UAAU;CACZ,CAAC;CACD,OAAO,UAAU,QAAQ;AAC3B,CAAC;;ACjFD,MAAM,QAAQ;AACd,MAAM,eAAe;AAErB,MAAM,YAAY,YAChB,KACE,OAAO,cAAc,QAAQ,MAAM,GACnC,OAAO,KAAK,WAAW,KAAKC,SAAI,MAAM,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE,GACrE,OAAO,gBAAgB,EAAE,CAC3B;AAEF,MAAa,UAAU,YACrB,GAAG,QAAQ,KAAK,GAAG,OAAO,QAAQ,IAAI,EAAE,GAAG,OAAO,QAAQ,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,QAAQ,YAAY,UAAU,QAAQ,SAAS,SAAS,OAAO;;ACXtJ,MAAM,cAAc,UAClB,UAAU,YAAY,OAAO,MAAM,KAAK,UAAU,SAAS,MAAM,IAAI;AAEvE,MAAa,eAAe,WAC1B,KACE,OAAO,cAAc,QAAQ,UAAU,GACvC,OAAO,KAAK,UAAU,MAAM,IAAI,GAChC,OAAO,iBAA6B,CAAC,EAAE,CACzC"}
|
package/dist/vite.d.mts
ADDED
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/logo.svg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="68 70 384 384">
|
|
2
|
+
<rect width="512" height="512" fill="#1C2440"/>
|
|
3
|
+
<circle cx="324" cy="160" r="84" fill="#F6F1E4"/>
|
|
4
|
+
<path d="M28 296 C 112 206, 206 352, 300 292 C 204 384, 120 300, 46 384 Z" fill="#EE8FB5"/>
|
|
5
|
+
<path d="M300 292 C 362 244, 420 232, 484 132 L 492 214 C 440 284, 380 306, 300 292 Z" fill="#F7C3D7"/>
|
|
6
|
+
<path d="M60 456 C 160 384, 244 474, 340 400 C 398 356, 440 364, 486 312 L 490 344 C 444 390, 404 384, 352 424 C 252 500, 170 416, 60 456 Z" fill="#9FD8E6"/>
|
|
7
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,7 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/h56m",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A secret scanner engine written in Rust that scans git history, the staged changes or any text with Betterleaks-format rules from a preset, configured from vite.config.ts.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"betterleaks",
|
|
7
|
+
"gitleaks",
|
|
8
|
+
"secrets",
|
|
9
|
+
"security",
|
|
10
|
+
"tanstack-intent",
|
|
11
|
+
"vite-plus"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/masseater/masseater.dev/tree/main/libs/h56m#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/masseater/masseater.dev/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT AND CC-BY-SA-4.0",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/masseater/masseater.dev.git",
|
|
21
|
+
"directory": "libs/h56m"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"h56m": "./dist/cli.mjs"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"THIRD-PARTY-NOTICES.txt",
|
|
29
|
+
"dist",
|
|
30
|
+
"logo.svg",
|
|
31
|
+
"skills/scan-secrets"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"imports": {
|
|
35
|
+
"#/*": "./src/*"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.mts",
|
|
40
|
+
"default": "./dist/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./vite": {
|
|
43
|
+
"types": "./dist/vite.d.mts",
|
|
44
|
+
"default": "./dist/vite.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@effect/platform-node": "^4.1.5"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@effect/vitest": "4.1.5",
|
|
57
|
+
"@masseater.dev/lint-host": "0.0.0",
|
|
58
|
+
"@r_masseater/vitest-otlp": "0.2.2",
|
|
59
|
+
"@types/node": "26.6.6",
|
|
60
|
+
"effect": "4.1.5",
|
|
61
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000",
|
|
62
|
+
"vite-plus": "1.7.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"effect": "^4.1.2",
|
|
66
|
+
"vite": "*",
|
|
67
|
+
"vite-plus": ">=1.5.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"vite": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"vite-plus": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": "v26.13.1"
|
|
79
|
+
},
|
|
80
|
+
"native": {
|
|
81
|
+
"binary": "h56m",
|
|
82
|
+
"targets": [
|
|
83
|
+
"linux-x64-gnu",
|
|
84
|
+
"win32-x64-msvc"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"@r_masseater/h56m-linux-x64-gnu": "0.2.0",
|
|
89
|
+
"@r_masseater/h56m-win32-x64-msvc": "0.2.0"
|
|
90
|
+
},
|
|
91
|
+
"scripts": {}
|
|
92
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: scan-secrets
|
|
3
|
+
description: >
|
|
4
|
+
Use when setting up @r_masseater/h56m in vite.config.ts, scanning commits, staged changes or
|
|
5
|
+
text for leaked secrets, writing a custom secret rule or filter, or silencing a finding that is
|
|
6
|
+
not a secret. Covers extending a preset, the Betterleaks-format settings, ignoredSecrets, h56m:allow, the CLI and
|
|
7
|
+
makeDetector.
|
|
8
|
+
metadata:
|
|
9
|
+
type: core
|
|
10
|
+
library: "@r_masseater/h56m"
|
|
11
|
+
library_version: 0.1.0
|
|
12
|
+
sources:
|
|
13
|
+
- src/app/index.ts
|
|
14
|
+
- src/shared/config/types.ts
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# scan-secrets
|
|
18
|
+
|
|
19
|
+
h56m finds secrets with its own engine, which follows Betterleaks. It has no rules of its own, so extend a preset from
|
|
20
|
+
`@r_masseater/h56m-presets` or a TOML file of your own. It never sends a secret anywhere to check
|
|
21
|
+
whether it is live.
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
vp add -D @r_masseater/h56m @r_masseater/h56m-presets
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import "@r_masseater/h56m/vite";
|
|
31
|
+
import { betterleaks } from "@r_masseater/h56m-presets";
|
|
32
|
+
import { defineConfig } from "vite-plus";
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
h56m: {
|
|
36
|
+
extend: { path: betterleaks, disabledRules: ["generic-api-key"] },
|
|
37
|
+
filter:
|
|
38
|
+
'matchesAny(finding.line, [`EXAMPLE_KEY`]) || matchesAny(attributes["path"], [`^fixtures/`])',
|
|
39
|
+
rules: [{ id: "my-token", regex: "\\b(my_[A-Za-z0-9]{20})\\b", keywords: ["my_"] }],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The settings use the Betterleaks format. `extend.path` names the preset file and
|
|
45
|
+
`disabledRules` turns off rules of it. Without `extend`, only `rules` run. `extend.useDefault` is
|
|
46
|
+
rejected. `filter` on the top level or on a rule is an
|
|
47
|
+
Expr expression that drops a finding when it is true. It sees `finding` (`secret`, `line`, ...)
|
|
48
|
+
and `attributes["path"]`, and has `matchesAny`, `entropy` and the other Betterleaks helpers.
|
|
49
|
+
|
|
50
|
+
## CLI
|
|
51
|
+
|
|
52
|
+
`h56m` scans the commits after the first of the given revisions, or after `origin/HEAD`,
|
|
53
|
+
`origin/main` or `origin/master`, and scans the whole history when none resolves.
|
|
54
|
+
`h56m --staged` scans the index only. Each finding is printed as
|
|
55
|
+
`path:line:column rule description sha256:<digest> (commit)`, without the secret, and the exit code
|
|
56
|
+
is 1 when anything is found.
|
|
57
|
+
|
|
58
|
+
## Silencing a finding
|
|
59
|
+
|
|
60
|
+
Fix a real secret by removing it and rotating it. For a value that is not a secret, prefer these
|
|
61
|
+
in order:
|
|
62
|
+
|
|
63
|
+
- Add `h56m:allow` on the same line.
|
|
64
|
+
- Add the digest the CLI printed to `ignoredSecrets`.
|
|
65
|
+
- Match the line or the path in `filter`.
|
|
66
|
+
|
|
67
|
+
## From code
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { makeDetector } from "@r_masseater/h56m";
|
|
71
|
+
|
|
72
|
+
const program = Effect.gen(function* () {
|
|
73
|
+
const detector = yield* makeDetector({ extend: { path: betterleaks } });
|
|
74
|
+
const inText = yield* detector.scanText({ path: "chat.md", text });
|
|
75
|
+
const staged = yield* detector.scanGit({ root, source: { type: "staged" } });
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`scanGit` takes `{ type: "history", bases, head }`, which scans the commits after the first of `bases`
|
|
80
|
+
that names a commit, `{ type: "staged" }` or
|
|
81
|
+
`{ type: "snapshot", revision }`. A finding has `rule`, `confidence`, 1-based `line` and `column`
|
|
82
|
+
in UTF-16 code units, `secret`, its SHA-256 `digest`, and `commit` for history scans. Errors are
|
|
83
|
+
`H56mError`.
|