@quantakrypto/core 0.4.2 → 0.4.3
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 +201 -0
- package/README.md +38 -10
- package/dist/agent-types.js.map +1 -1
- package/dist/baseline.js.map +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/cbom.js.map +1 -1
- package/dist/changed.js.map +1 -1
- package/dist/codemods/config-toggle.js.map +1 -1
- package/dist/codemods/registry.js.map +1 -1
- package/dist/comments.d.ts +26 -0
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +141 -1
- package/dist/comments.js.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/cwe.js.map +1 -1
- package/dist/dependencies.d.ts +3 -2
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +138 -2
- package/dist/dependencies.js.map +1 -1
- package/dist/detect-utils.d.ts +14 -3
- package/dist/detect-utils.d.ts.map +1 -1
- package/dist/detect-utils.js +32 -4
- package/dist/detect-utils.js.map +1 -1
- package/dist/detectors/c.d.ts.map +1 -1
- package/dist/detectors/c.js +190 -2
- package/dist/detectors/c.js.map +1 -1
- package/dist/detectors/csharp.d.ts.map +1 -1
- package/dist/detectors/csharp.js +141 -3
- package/dist/detectors/csharp.js.map +1 -1
- package/dist/detectors/go.d.ts +5 -3
- package/dist/detectors/go.d.ts.map +1 -1
- package/dist/detectors/go.js +187 -3
- package/dist/detectors/go.js.map +1 -1
- package/dist/detectors/java.d.ts.map +1 -1
- package/dist/detectors/java.js +168 -3
- package/dist/detectors/java.js.map +1 -1
- package/dist/detectors/pem.d.ts.map +1 -1
- package/dist/detectors/pem.js +49 -1
- package/dist/detectors/pem.js.map +1 -1
- package/dist/detectors/python.d.ts.map +1 -1
- package/dist/detectors/python.js +74 -3
- package/dist/detectors/python.js.map +1 -1
- package/dist/detectors/ruby.d.ts +9 -5
- package/dist/detectors/ruby.d.ts.map +1 -1
- package/dist/detectors/ruby.js +122 -2
- package/dist/detectors/ruby.js.map +1 -1
- package/dist/detectors/rust.d.ts +8 -3
- package/dist/detectors/rust.d.ts.map +1 -1
- package/dist/detectors/rust.js +185 -3
- package/dist/detectors/rust.js.map +1 -1
- package/dist/detectors/source.d.ts.map +1 -1
- package/dist/detectors/source.js +117 -7
- package/dist/detectors/source.js.map +1 -1
- package/dist/detectors/stateful-hbs.d.ts +22 -0
- package/dist/detectors/stateful-hbs.d.ts.map +1 -0
- package/dist/detectors/stateful-hbs.js +139 -0
- package/dist/detectors/stateful-hbs.js.map +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/evidence.d.ts +48 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +76 -0
- package/dist/evidence.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/inventory.d.ts +2 -0
- package/dist/inventory.d.ts.map +1 -1
- package/dist/inventory.js +27 -1
- package/dist/inventory.js.map +1 -1
- package/dist/parallel.js.map +1 -1
- package/dist/patch-policy.js.map +1 -1
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +39 -0
- package/dist/redact.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +4 -2
- package/dist/registry.js.map +1 -1
- package/dist/remediate-pipeline.d.ts +3 -0
- package/dist/remediate-pipeline.d.ts.map +1 -1
- package/dist/remediate-pipeline.js +50 -0
- package/dist/remediate-pipeline.js.map +1 -1
- package/dist/remediate-request.js.map +1 -1
- package/dist/remediation.d.ts +9 -3
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +17 -5
- package/dist/remediation.js.map +1 -1
- package/dist/report.d.ts +9 -0
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +31 -0
- package/dist/report.js.map +1 -1
- package/dist/scan-worker.js.map +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +8 -1
- package/dist/scan.js.map +1 -1
- package/dist/severity.js.map +1 -1
- package/dist/triage.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/verify.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/walk.js.map +1 -1
- package/dist/worktree.js.map +1 -1
- package/package.json +1 -1
- package/src/comments.ts +140 -1
- package/src/dependencies.ts +143 -4
- package/src/detect-utils.ts +33 -4
- package/src/detectors/c.ts +202 -2
- package/src/detectors/csharp.ts +154 -3
- package/src/detectors/go.ts +209 -6
- package/src/detectors/java.ts +189 -3
- package/src/detectors/pem.ts +53 -1
- package/src/detectors/python.ts +82 -3
- package/src/detectors/ruby.ts +138 -7
- package/src/detectors/rust.ts +211 -7
- package/src/detectors/source.ts +149 -6
- package/src/detectors/stateful-hbs.ts +177 -0
- package/src/evidence.ts +124 -0
- package/src/index.ts +5 -1
- package/src/inventory.ts +31 -1
- package/src/redact.ts +41 -0
- package/src/registry.ts +4 -2
- package/src/remediate-pipeline.ts +55 -0
- package/src/remediation.ts +23 -8
- package/src/report.ts +41 -2
- package/src/scan.ts +13 -1
- package/src/types.ts +1 -1
- package/src/version.ts +1 -1
package/dist/detect-utils.js
CHANGED
|
@@ -159,14 +159,42 @@ export const RUST_EXTENSIONS = [".rs"];
|
|
|
159
159
|
export const RUBY_EXTENSIONS = [".rb"];
|
|
160
160
|
/** C / C++ source extensions handled by the OpenSSL detector. */
|
|
161
161
|
export const C_EXTENSIONS = [".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hh"];
|
|
162
|
+
/**
|
|
163
|
+
* Prose/documentation extensions. The language-agnostic *token* detectors (SSH
|
|
164
|
+
* public keys, TLS cipher suites, certificate signature algorithms) must not run
|
|
165
|
+
* on these: a changelog or README that mentions `ssh-rsa` or `ECDHE-RSA` in a
|
|
166
|
+
* sentence is prose, not crypto config. (PEM/`-----BEGIN` material stays in scope
|
|
167
|
+
* everywhere, so a key pasted into docs is still caught.)
|
|
168
|
+
*/
|
|
169
|
+
export const DOC_EXTENSIONS = [
|
|
170
|
+
".md",
|
|
171
|
+
".markdown",
|
|
172
|
+
".mdown",
|
|
173
|
+
".mkd",
|
|
174
|
+
".rst",
|
|
175
|
+
".adoc",
|
|
176
|
+
".asciidoc",
|
|
177
|
+
".textile",
|
|
178
|
+
".org",
|
|
179
|
+
".rdoc",
|
|
180
|
+
".pod",
|
|
181
|
+
];
|
|
162
182
|
/**
|
|
163
183
|
* File-literal surfaces where a JWT/JOSE algorithm string (`"RS256"`, `"ES256"`)
|
|
164
184
|
* is the same evidence regardless of language. Used to un-gate the JWT detector
|
|
165
|
-
* from JS-only.
|
|
166
|
-
*
|
|
167
|
-
*
|
|
185
|
+
* from JS-only. Covers the languages whose JWT libraries pass the alg as a quoted
|
|
186
|
+
* token — JS/TS, Python, Go (`jwt.GetSigningMethod("RS256")`) and Ruby
|
|
187
|
+
* (`JWT.encode(payload, key, 'RS256')`) — so the regex stays precise (`HS*` HMAC
|
|
188
|
+
* tokens are excluded by `RE_JWT_ALG`). Java/C# pass the alg as an *identifier*
|
|
189
|
+
* (`SignatureAlgorithm.RS256`), which needs its own pattern — a later pass.
|
|
190
|
+
* YAML/JSON config carry unquoted tokens and higher FP risk, so they wait too.
|
|
168
191
|
*/
|
|
169
|
-
export const JWT_HOST_EXTENSIONS = [
|
|
192
|
+
export const JWT_HOST_EXTENSIONS = [
|
|
193
|
+
...JS_TS_EXTENSIONS,
|
|
194
|
+
...PYTHON_EXTENSIONS,
|
|
195
|
+
...GO_EXTENSIONS,
|
|
196
|
+
...RUBY_EXTENSIONS,
|
|
197
|
+
];
|
|
170
198
|
/**
|
|
171
199
|
* Extensions the scanner can actually analyze for inline crypto usage today
|
|
172
200
|
* (the language-specific source detectors). A scan that walked files but found
|
package/dist/detect-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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G,CAAC,IAAI,GAAG,EAAE,CAAC;YAC5B,IAAI,GAAG,GAAG,CAAC;YACX,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,EAAU,EACV,OAAe,EACf,OAAyC;IAEzC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;IACjE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtC,OAAO,CAAC,CAAC,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS;YAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,qCAAqC;IACnF,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared helpers for the regex-based source detectors: turning a string offset\n * into a 1-based line/column, extracting a trimmed single-line snippet, and a\n * small factory for building Finding objects with consistent remediation text.\n */\nimport type {\n AlgorithmFamily,\n Confidence,\n Finding,\n FindingCategory,\n RuleMeta,\n Severity,\n} from \"./types.js\";\nimport { remediationText } from \"./remediation.js\";\n\n/** A 1-based line/column position derived from a character offset. */\nexport interface LineCol {\n line: number;\n column: number;\n}\n\n/**\n * Memoized line-start offsets for the CURRENT content string. A scan processes\n * all of one file's findings consecutively against the same `content` reference,\n * so a single-entry cache turns the previously O(offset)-per-finding line/column\n * math into O(log n) — the whole file is O(n log n) instead of O(n²). Without\n * this, a large file with many findings scaled quadratically (a real perf cliff,\n * caught by the ReDoS/time-budget test).\n */\nlet cachedContent: string | null = null;\nlet cachedLineStarts: number[] = [];\nfunction lineStartsFor(content: string): number[] {\n if (content === cachedContent) return cachedLineStarts;\n const starts = [0];\n for (let i = 0; i < content.length; i++) {\n if (content.charCodeAt(i) === 10 /* \\n */) starts.push(i + 1);\n }\n cachedContent = content;\n cachedLineStarts = starts;\n return starts;\n}\n\n/** Index of the line containing `offset` (0-based into the line-starts array). */\nfunction lineIndexFor(starts: readonly number[], offset: number): number {\n let lo = 0;\n let hi = starts.length - 1;\n let best = 0;\n while (lo <= hi) {\n const mid = (lo + hi) >>> 1;\n if (starts[mid] <= offset) {\n best = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n return best;\n}\n\n/**\n * Convert a 0-based character offset within `content` into a 1-based\n * line/column. Newlines are LF; CR is treated as an ordinary character, so on\n * CRLF files the column includes the trailing CR offset harmlessly.\n */\nexport function offsetToLineCol(content: string, offset: number): LineCol {\n const starts = lineStartsFor(content);\n const idx = lineIndexFor(starts, offset);\n return { line: idx + 1, column: offset - starts[idx] + 1 };\n}\n\n/** Extract the (trimmed) single source line containing `offset`. */\nexport function lineAt(content: string, offset: number): string {\n const starts = lineStartsFor(content);\n const idx = lineIndexFor(starts, offset);\n const start = starts[idx];\n const nextStart = idx + 1 < starts.length ? starts[idx + 1] : content.length + 1;\n // nextStart points just past the '\\n'; the line content ends before it.\n const end = Math.min(nextStart - 1, content.length);\n return content.slice(start, end).replace(/\\r$/, \"\").trim();\n}\n\n/** Inputs for {@link makeFinding}. */\nexport interface FindingSpec {\n ruleId: string;\n title: string;\n category: FindingCategory;\n severity: Severity;\n confidence: Confidence;\n algorithm?: AlgorithmFamily;\n hndl: boolean;\n message: string;\n /** Override the auto-derived remediation text. */\n remediation?: string;\n /** Associated CWE id (e.g. \"CWE-327\"). */\n cwe?: string;\n /** Marks the matched snippet as the sensitive value itself (key material). */\n sensitive?: boolean;\n /** The matched source text and its start offset within `content`. */\n file: string;\n content: string;\n index: number;\n /** Length of the match, used to compute endLine for multi-line matches. */\n matchLength?: number;\n}\n\n/**\n * Build a {@link Finding} with location info derived from a match offset. When\n * no explicit remediation is given but an algorithm is, the canonical\n * remediation text for that family is used.\n */\nexport function makeFinding(spec: FindingSpec): Finding {\n const { line, column } = offsetToLineCol(spec.content, spec.index);\n const snippet = lineAt(spec.content, spec.index);\n\n const remediation =\n spec.remediation ?? (spec.algorithm ? remediationText(spec.algorithm) : undefined);\n\n const location: Finding[\"location\"] = {\n file: spec.file,\n line,\n column,\n snippet: snippet.length > 200 ? `${snippet.slice(0, 197)}...` : snippet,\n };\n\n if (spec.matchLength && spec.matchLength > 0) {\n const matched = spec.content.slice(spec.index, spec.index + spec.matchLength);\n const extraLines = (matched.match(/\\n/g) ?? []).length;\n if (extraLines > 0) location.endLine = line + extraLines;\n }\n\n const finding: Finding = {\n ruleId: spec.ruleId,\n title: spec.title,\n category: spec.category,\n severity: spec.severity,\n confidence: spec.confidence,\n hndl: spec.hndl,\n message: spec.message,\n location,\n };\n if (spec.algorithm) finding.algorithm = spec.algorithm;\n if (remediation) finding.remediation = remediation;\n if (spec.cwe) finding.cwe = spec.cwe;\n if (spec.sensitive) finding.sensitive = true;\n return finding;\n}\n\n/** Where a match occurred, plus optional per-finding field overrides. */\nexport interface RuleMatch {\n file: string;\n content: string;\n /** Match start offset within `content`. */\n index: number;\n /** Length of the match (used to compute endLine for multi-line matches). */\n matchLength?: number;\n}\n\n/**\n * Fields of a {@link RuleMeta} a detector may refine at match time. Multi-variant\n * rules (e.g. key generation across algorithm families) override these; fixed\n * rules pass none and inherit the catalog metadata verbatim.\n */\nexport type RuleOverrides = Partial<\n Pick<\n RuleMeta,\n \"title\" | \"category\" | \"severity\" | \"confidence\" | \"algorithm\" | \"hndl\" | \"message\" | \"cwe\"\n >\n> & { remediation?: string };\n\n/**\n * Build a {@link Finding} from a rule's catalog metadata plus a match location,\n * applying any per-finding overrides. This is the single construction path for\n * detector findings: the invariant fields (title/severity/category/…) live once\n * in the {@link RuleMeta} declaration, so they can't drift from what the SARIF\n * catalog and the MCP resolver report.\n */\nexport function findingFromRule(rule: RuleMeta, at: RuleMatch, overrides?: RuleOverrides): Finding {\n return makeFinding({\n ruleId: rule.id,\n title: overrides?.title ?? rule.title,\n category: overrides?.category ?? rule.category,\n severity: overrides?.severity ?? rule.severity,\n confidence: overrides?.confidence ?? rule.confidence,\n algorithm: overrides?.algorithm ?? rule.algorithm,\n hndl: overrides?.hndl ?? rule.hndl,\n cwe: overrides?.cwe ?? rule.cwe,\n remediation: overrides?.remediation ?? rule.remediation,\n sensitive: rule.sensitive,\n message: overrides?.message ?? rule.message,\n file: at.file,\n content: at.content,\n index: at.index,\n matchLength: at.matchLength,\n });\n}\n\n/** True if `filePath` has one of the given (lower-case, dotted) extensions. */\nexport function hasExtension(filePath: string, exts: readonly string[]): boolean {\n const lower = filePath.toLowerCase();\n return exts.some((e) => lower.endsWith(e));\n}\n\n/**\n * JavaScript / TypeScript source extensions handled by the source detectors.\n * `.vue` / `.svelte` single-file components embed a `<script>` block, so the\n * lexical detectors catch crypto usage inside them.\n */\nexport const JS_TS_EXTENSIONS: readonly string[] = [\n \".js\",\n \".jsx\",\n \".ts\",\n \".tsx\",\n \".mjs\",\n \".cjs\",\n \".vue\",\n \".svelte\",\n];\n\n/** Python source extensions handled by the Python detector. */\nexport const PYTHON_EXTENSIONS: readonly string[] = [\".py\", \".pyi\", \".pyw\"];\n\n/** Go source extensions handled by the Go detector. */\nexport const GO_EXTENSIONS: readonly string[] = [\".go\"];\n\n/** Java / Kotlin source extensions handled by the JCA detector. */\nexport const JAVA_EXTENSIONS: readonly string[] = [\".java\", \".kt\", \".kts\"];\n\n/** C# source extensions handled by the .NET detector. */\nexport const CSHARP_EXTENSIONS: readonly string[] = [\".cs\"];\n\n/** Rust source extensions handled by the Rust detector. */\nexport const RUST_EXTENSIONS: readonly string[] = [\".rs\"];\n\n/** Ruby source extensions handled by the Ruby detector. */\nexport const RUBY_EXTENSIONS: readonly string[] = [\".rb\"];\n\n/** C / C++ source extensions handled by the OpenSSL detector. */\nexport const C_EXTENSIONS: readonly string[] = [\".c\", \".h\", \".cc\", \".cpp\", \".cxx\", \".hpp\", \".hh\"];\n\n/**\n * Prose/documentation extensions. The language-agnostic *token* detectors (SSH\n * public keys, TLS cipher suites, certificate signature algorithms) must not run\n * on these: a changelog or README that mentions `ssh-rsa` or `ECDHE-RSA` in a\n * sentence is prose, not crypto config. (PEM/`-----BEGIN` material stays in scope\n * everywhere, so a key pasted into docs is still caught.)\n */\nexport const DOC_EXTENSIONS: readonly string[] = [\n \".md\",\n \".markdown\",\n \".mdown\",\n \".mkd\",\n \".rst\",\n \".adoc\",\n \".asciidoc\",\n \".textile\",\n \".org\",\n \".rdoc\",\n \".pod\",\n];\n\n/**\n * File-literal surfaces where a JWT/JOSE algorithm string (`\"RS256\"`, `\"ES256\"`)\n * is the same evidence regardless of language. Used to un-gate the JWT detector\n * from JS-only. Covers the languages whose JWT libraries pass the alg as a quoted\n * token — JS/TS, Python, Go (`jwt.GetSigningMethod(\"RS256\")`) and Ruby\n * (`JWT.encode(payload, key, 'RS256')`) — so the regex stays precise (`HS*` HMAC\n * tokens are excluded by `RE_JWT_ALG`). Java/C# pass the alg as an *identifier*\n * (`SignatureAlgorithm.RS256`), which needs its own pattern — a later pass.\n * YAML/JSON config carry unquoted tokens and higher FP risk, so they wait too.\n */\nexport const JWT_HOST_EXTENSIONS: readonly string[] = [\n ...JS_TS_EXTENSIONS,\n ...PYTHON_EXTENSIONS,\n ...GO_EXTENSIONS,\n ...RUBY_EXTENSIONS,\n];\n\n/**\n * Extensions the scanner can actually analyze for inline crypto usage today\n * (the language-specific source detectors). A scan that walked files but found\n * none of these has NOT meaningfully assessed the codebase — reporters surface\n * that ({@link CryptoInventory}/coverage), so a bare 100/100 can't masquerade as\n * \"safe\" on, say, a Go or Rust repo. PEM / SSH / dependency detectors run on any\n * file and are intentionally excluded here.\n */\nexport const ANALYZABLE_SOURCE_EXTENSIONS: readonly string[] = [\n ...JS_TS_EXTENSIONS,\n ...PYTHON_EXTENSIONS,\n ...GO_EXTENSIONS,\n ...JAVA_EXTENSIONS,\n ...CSHARP_EXTENSIONS,\n ...RUST_EXTENSIONS,\n ...RUBY_EXTENSIONS,\n ...C_EXTENSIONS,\n];\n\n/**\n * Human label for the source languages the scanner can analyze for inline\n * crypto, shown in coverage output. Kept next to {@link\n * ANALYZABLE_SOURCE_EXTENSIONS} so a new language pack updates one place.\n */\nexport const ANALYZABLE_LANGUAGES_LABEL = \"JS/TS, Python, Go, Java, C#, Rust, Ruby, C/C++\";\n\n/** True when a path is in a source language the scanner can analyze for crypto. */\nexport function isAnalyzableSource(filePath: string): boolean {\n return hasExtension(filePath, ANALYZABLE_SOURCE_EXTENSIONS);\n}\n\n/**\n * Given a SORTED ascending array of call offsets, return true when `idx` is at\n * or after some call offset `c` with `idx - c < window`. Runs in O(log n) by\n * binary-searching the largest call offset ≤ `idx` and checking the gap. This\n * replaces the previous O(matches × calls) linear scan (`nearCall`).\n */\nexport function nearSortedCall(\n sortedCalls: readonly number[],\n idx: number,\n window: number,\n): boolean {\n // Find the rightmost element <= idx.\n let lo = 0;\n let hi = sortedCalls.length - 1;\n let best = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >>> 1;\n if (sortedCalls[mid] <= idx) {\n best = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (best < 0) return false;\n return idx - sortedCalls[best] < window;\n}\n\n/**\n * Run a global regex over `content`, invoking `onMatch` for each hit. Resets\n * lastIndex and guards against zero-width matches (which would loop forever).\n */\nexport function eachMatch(\n re: RegExp,\n content: string,\n onMatch: (match: RegExpExecArray) => void,\n): void {\n const g = re.global ? re : new RegExp(re.source, `${re.flags}g`);\n g.lastIndex = 0;\n let m: RegExpExecArray | null;\n while ((m = g.exec(content)) !== null) {\n onMatch(m);\n if (m.index === g.lastIndex) g.lastIndex++; // avoid infinite loop on empty match\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c.d.ts","sourceRoot":"","sources":["../../src/detectors/c.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"c.d.ts","sourceRoot":"","sources":["../../src/detectors/c.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAsQ/D,8DAA8D;AAC9D,eAAO,MAAM,SAAS,EAAE,QAoDvB,CAAC"}
|
package/dist/detectors/c.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { C_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
|
|
2
|
-
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
2
|
+
import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from "../cwe.js";
|
|
3
3
|
const RE_C_RSA = /\bRSA_generate_key(?:_ex)?\s*\(|\bEVP_RSA_gen\s*\(/g;
|
|
4
4
|
const RE_C_EC = /\bEC_KEY_generate_key\s*\(|\bEC_KEY_new_by_curve_name\s*\(/g;
|
|
5
5
|
const RE_C_ECDSA = /\bECDSA_do_sign\s*\(|\bECDSA_sign\s*\(/g;
|
|
6
6
|
const RE_C_ECDH = /\bECDH_compute_key\s*\(/g;
|
|
7
7
|
const RE_C_DSA = /\bDSA_generate_key\s*\(|\bDSA_generate_parameters(?:_ex)?\s*\(/g;
|
|
8
8
|
const RE_C_DH = /\bDH_generate_key\s*\(|\bDH_generate_parameters(?:_ex)?\s*\(/g;
|
|
9
|
+
// Modern OpenSSL 3.x EVP API (the legacy *_generate_key forms above are
|
|
10
|
+
// deprecated) + libsodium — the biggest C false-negative surface (audit F1).
|
|
11
|
+
const RE_C_EVP_KEYGEN = /\bEVP_PKEY_(?:Q_)?keygen\s*\(|\bEVP_PKEY_paramgen\s*\(/g;
|
|
12
|
+
const RE_C_EVP_DERIVE = /\bEVP_PKEY_derive\s*\(/g;
|
|
13
|
+
const RE_C_EVP_CRYPT = /\bEVP_PKEY_(?:encrypt|decrypt)\s*\(/g;
|
|
14
|
+
const RE_C_EVP_SIGN = /\bEVP_DigestSign(?:Init)?\s*\(|\bEVP_DigestVerify(?:Init)?\s*\(/g;
|
|
15
|
+
// X25519: crypto_box / crypto_kx key pairs (incl. the fully-qualified
|
|
16
|
+
// curve25519xsalsa20poly1305 form) plus the low-level crypto_scalarmult
|
|
17
|
+
// primitive — all classical Curve25519 key agreement (audit recall gap).
|
|
18
|
+
const RE_C_SODIUM_BOX = /\bcrypto_box_(?:curve25519xsalsa20poly1305_)?(?:seed_)?keypair\s*\(|\bcrypto_kx_keypair\s*\(|\bcrypto_scalarmult_(?:curve25519|base)\s*\(/g;
|
|
19
|
+
// EdDSA: crypto_sign key pairs, including the explicit _ed25519 forms and the
|
|
20
|
+
// deterministic seed_keypair variants (audit recall gap: _ed25519_keypair).
|
|
21
|
+
const RE_C_SODIUM_SIGN = /\bcrypto_sign_(?:ed25519_)?(?:seed_)?keypair\s*\(/g;
|
|
22
|
+
// Legacy verify / decrypt counterparts to the *_sign / *_encrypt rules above
|
|
23
|
+
// (audit F4-c): the classic OpenSSL RSA/ECDSA verification and RSA raw
|
|
24
|
+
// decryption call forms that the modern EVP + legacy keygen rules don't cover.
|
|
25
|
+
const RE_C_ECDSA_VERIFY = /\bECDSA_verify\s*\(/g;
|
|
26
|
+
const RE_C_RSA_VERIFY = /\bRSA_verify\s*\(/g;
|
|
27
|
+
const RE_C_RSA_CRYPT = /\bRSA_public_encrypt\s*\(|\bRSA_private_decrypt\s*\(/g;
|
|
28
|
+
// C/OpenSSL legacy TLS configuration (mirrors source.ts tlsDetector): forcing a
|
|
29
|
+
// deprecated protocol version or disabling certificate verification.
|
|
30
|
+
const RE_C_TLS_VERSION = /\bTLSv1_method\b|\bSSLv3_method\b/g;
|
|
31
|
+
const RE_C_TLS_VERIFY_NONE = /\bSSL_VERIFY_NONE\b/g;
|
|
9
32
|
const RULE_C_RSA = {
|
|
10
33
|
id: "c-rsa-keygen",
|
|
11
34
|
title: "C/OpenSSL RSA key generation",
|
|
@@ -81,13 +104,167 @@ const RULE_C_DH = {
|
|
|
81
104
|
cwe: CWE_BROKEN_CRYPTO,
|
|
82
105
|
message: "Finite-field Diffie-Hellman (C/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
83
106
|
};
|
|
107
|
+
const RULE_C_EVP_KEYGEN = {
|
|
108
|
+
id: "c-evp-keygen",
|
|
109
|
+
title: "C/OpenSSL EVP key generation",
|
|
110
|
+
description: "OpenSSL 3.x EVP_PKEY_keygen / EVP_PKEY_Q_keygen / paramgen",
|
|
111
|
+
category: "key-exchange",
|
|
112
|
+
severity: "high",
|
|
113
|
+
confidence: "high",
|
|
114
|
+
algorithm: "unknown",
|
|
115
|
+
hndl: true,
|
|
116
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
117
|
+
message: "Generates an asymmetric key via the OpenSSL 3.x EVP API (the key type — RSA/EC/DH/X25519 — is set on the CTX). Treated conservatively as key-exchange-capable (harvest-now-decrypt-later).",
|
|
118
|
+
remediation: "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
|
|
119
|
+
};
|
|
120
|
+
const RULE_C_EVP_DERIVE = {
|
|
121
|
+
id: "c-evp-derive",
|
|
122
|
+
title: "C/OpenSSL EVP key agreement",
|
|
123
|
+
description: "OpenSSL 3.x EVP_PKEY_derive (ECDH / DH shared secret)",
|
|
124
|
+
category: "key-exchange",
|
|
125
|
+
severity: "high",
|
|
126
|
+
confidence: "high",
|
|
127
|
+
algorithm: "ECDH",
|
|
128
|
+
hndl: true,
|
|
129
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
130
|
+
message: "Derives an (EC)DH shared secret via the OpenSSL EVP API — broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
131
|
+
};
|
|
132
|
+
const RULE_C_EVP_CRYPT = {
|
|
133
|
+
id: "c-evp-pkey-crypt",
|
|
134
|
+
title: "C/OpenSSL EVP public-key encryption",
|
|
135
|
+
description: "OpenSSL 3.x EVP_PKEY_encrypt / EVP_PKEY_decrypt (RSA)",
|
|
136
|
+
category: "kem",
|
|
137
|
+
severity: "high",
|
|
138
|
+
confidence: "high",
|
|
139
|
+
algorithm: "RSA",
|
|
140
|
+
hndl: true,
|
|
141
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
142
|
+
message: "RSA public-key encryption/decryption via the OpenSSL EVP API is harvest-now-decrypt-later exposed.",
|
|
143
|
+
};
|
|
144
|
+
const RULE_C_EVP_SIGN = {
|
|
145
|
+
id: "c-evp-sign",
|
|
146
|
+
title: "C/OpenSSL EVP signing",
|
|
147
|
+
description: "OpenSSL 3.x EVP_DigestSign* / EVP_DigestVerify*",
|
|
148
|
+
category: "signature",
|
|
149
|
+
severity: "high",
|
|
150
|
+
confidence: "high",
|
|
151
|
+
algorithm: "unknown",
|
|
152
|
+
hndl: false,
|
|
153
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
154
|
+
message: "Classical signature via the OpenSSL EVP API (RSA/ECDSA/EdDSA) is forgeable by a quantum attacker.",
|
|
155
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
156
|
+
};
|
|
157
|
+
const RULE_C_SODIUM_BOX = {
|
|
158
|
+
id: "c-libsodium-box",
|
|
159
|
+
title: "libsodium X25519 key pair",
|
|
160
|
+
description: "libsodium crypto_box / crypto_kx keypair + crypto_scalarmult (X25519 key agreement)",
|
|
161
|
+
category: "key-exchange",
|
|
162
|
+
severity: "medium",
|
|
163
|
+
confidence: "high",
|
|
164
|
+
algorithm: "X25519",
|
|
165
|
+
hndl: true,
|
|
166
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
167
|
+
message: "libsodium crypto_box uses X25519 key agreement — modern but classical, and harvest-now-decrypt-later exposed.",
|
|
168
|
+
};
|
|
169
|
+
const RULE_C_SODIUM_SIGN = {
|
|
170
|
+
id: "c-libsodium-sign",
|
|
171
|
+
title: "libsodium Ed25519 key pair",
|
|
172
|
+
description: "libsodium crypto_sign(_ed25519)(_seed)_keypair (Ed25519 signatures)",
|
|
173
|
+
category: "signature",
|
|
174
|
+
severity: "low",
|
|
175
|
+
confidence: "high",
|
|
176
|
+
algorithm: "EdDSA",
|
|
177
|
+
hndl: false,
|
|
178
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
179
|
+
message: "libsodium crypto_sign uses Ed25519 signatures — classical and forgeable by a quantum attacker.",
|
|
180
|
+
};
|
|
181
|
+
const RULE_C_ECDSA_VERIFY = {
|
|
182
|
+
id: "c-ecdsa-verify",
|
|
183
|
+
title: "C/OpenSSL ECDSA signature verification",
|
|
184
|
+
description: "OpenSSL ECDSA_verify",
|
|
185
|
+
category: "signature",
|
|
186
|
+
severity: "high",
|
|
187
|
+
confidence: "high",
|
|
188
|
+
algorithm: "ECDSA",
|
|
189
|
+
hndl: false,
|
|
190
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
191
|
+
message: "Classical ECDSA verification (C/OpenSSL) trusts signatures forgeable by a quantum attacker.",
|
|
192
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
193
|
+
};
|
|
194
|
+
const RULE_C_RSA_VERIFY = {
|
|
195
|
+
id: "c-rsa-verify",
|
|
196
|
+
title: "C/OpenSSL RSA signature verification",
|
|
197
|
+
description: "OpenSSL RSA_verify",
|
|
198
|
+
category: "signature",
|
|
199
|
+
severity: "high",
|
|
200
|
+
confidence: "high",
|
|
201
|
+
algorithm: "RSA",
|
|
202
|
+
hndl: false,
|
|
203
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
204
|
+
message: "Classical RSA signature verification (C/OpenSSL) trusts signatures forgeable by a quantum attacker.",
|
|
205
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
206
|
+
};
|
|
207
|
+
const RULE_C_RSA_CRYPT = {
|
|
208
|
+
id: "c-rsa-crypt",
|
|
209
|
+
title: "C/OpenSSL RSA public-key encryption",
|
|
210
|
+
description: "OpenSSL RSA_public_encrypt / RSA_private_decrypt",
|
|
211
|
+
category: "kem",
|
|
212
|
+
severity: "high",
|
|
213
|
+
confidence: "high",
|
|
214
|
+
algorithm: "RSA",
|
|
215
|
+
hndl: true,
|
|
216
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
217
|
+
message: "Legacy RSA public-key encryption/decryption (C/OpenSSL) is harvest-now-decrypt-later exposed.",
|
|
218
|
+
};
|
|
219
|
+
const RULE_C_TLS_VERSION = {
|
|
220
|
+
id: "c-tls-legacy-version",
|
|
221
|
+
title: "Legacy TLS/SSL version pinned (C/OpenSSL)",
|
|
222
|
+
description: "OpenSSL TLSv1_method / SSLv3_method",
|
|
223
|
+
category: "tls",
|
|
224
|
+
severity: "medium",
|
|
225
|
+
confidence: "high",
|
|
226
|
+
hndl: false,
|
|
227
|
+
cwe: CWE_WEAK_STRENGTH,
|
|
228
|
+
message: "TLS 1.0 / SSLv3 are deprecated and insecure; require TLS 1.3.",
|
|
229
|
+
remediation: "Use TLS_method() with a minimum of TLS 1.3 and prefer PQC-hybrid key exchange.",
|
|
230
|
+
};
|
|
231
|
+
const RULE_C_TLS_VERIFY_NONE = {
|
|
232
|
+
id: "c-tls-verify-none",
|
|
233
|
+
title: "TLS certificate verification disabled (C/OpenSSL)",
|
|
234
|
+
description: "OpenSSL SSL_VERIFY_NONE",
|
|
235
|
+
category: "tls",
|
|
236
|
+
severity: "high",
|
|
237
|
+
confidence: "high",
|
|
238
|
+
hndl: false,
|
|
239
|
+
cwe: CWE_CERT_VALIDATION,
|
|
240
|
+
message: "SSL_VERIFY_NONE disables TLS certificate verification (MITM risk).",
|
|
241
|
+
remediation: "Use SSL_VERIFY_PEER and verify certificates properly.",
|
|
242
|
+
};
|
|
84
243
|
/** Detects classical asymmetric crypto in C/C++ (OpenSSL). */
|
|
85
244
|
export const cDetector = {
|
|
86
245
|
id: "c-crypto",
|
|
87
246
|
description: "Classical asymmetric crypto in C/C++ (OpenSSL)",
|
|
88
247
|
scope: "source",
|
|
89
248
|
language: "c",
|
|
90
|
-
rules: [
|
|
249
|
+
rules: [
|
|
250
|
+
RULE_C_RSA,
|
|
251
|
+
RULE_C_EC,
|
|
252
|
+
RULE_C_ECDSA,
|
|
253
|
+
RULE_C_ECDH,
|
|
254
|
+
RULE_C_DSA,
|
|
255
|
+
RULE_C_DH,
|
|
256
|
+
RULE_C_EVP_KEYGEN,
|
|
257
|
+
RULE_C_EVP_DERIVE,
|
|
258
|
+
RULE_C_EVP_CRYPT,
|
|
259
|
+
RULE_C_EVP_SIGN,
|
|
260
|
+
RULE_C_SODIUM_BOX,
|
|
261
|
+
RULE_C_SODIUM_SIGN,
|
|
262
|
+
RULE_C_ECDSA_VERIFY,
|
|
263
|
+
RULE_C_RSA_VERIFY,
|
|
264
|
+
RULE_C_RSA_CRYPT,
|
|
265
|
+
RULE_C_TLS_VERSION,
|
|
266
|
+
RULE_C_TLS_VERIFY_NONE,
|
|
267
|
+
],
|
|
91
268
|
appliesTo: (f) => hasExtension(f, C_EXTENSIONS),
|
|
92
269
|
detect({ file, content }) {
|
|
93
270
|
const findings = [];
|
|
@@ -98,6 +275,17 @@ export const cDetector = {
|
|
|
98
275
|
add(RE_C_ECDH, RULE_C_ECDH);
|
|
99
276
|
add(RE_C_DSA, RULE_C_DSA);
|
|
100
277
|
add(RE_C_DH, RULE_C_DH);
|
|
278
|
+
add(RE_C_EVP_KEYGEN, RULE_C_EVP_KEYGEN);
|
|
279
|
+
add(RE_C_EVP_DERIVE, RULE_C_EVP_DERIVE);
|
|
280
|
+
add(RE_C_EVP_CRYPT, RULE_C_EVP_CRYPT);
|
|
281
|
+
add(RE_C_EVP_SIGN, RULE_C_EVP_SIGN);
|
|
282
|
+
add(RE_C_SODIUM_BOX, RULE_C_SODIUM_BOX);
|
|
283
|
+
add(RE_C_SODIUM_SIGN, RULE_C_SODIUM_SIGN);
|
|
284
|
+
add(RE_C_ECDSA_VERIFY, RULE_C_ECDSA_VERIFY);
|
|
285
|
+
add(RE_C_RSA_VERIFY, RULE_C_RSA_VERIFY);
|
|
286
|
+
add(RE_C_RSA_CRYPT, RULE_C_RSA_CRYPT);
|
|
287
|
+
add(RE_C_TLS_VERSION, RULE_C_TLS_VERSION);
|
|
288
|
+
add(RE_C_TLS_VERIFY_NONE, RULE_C_TLS_VERIFY_NONE);
|
|
101
289
|
return findings;
|
|
102
290
|
},
|
|
103
291
|
};
|
package/dist/detectors/c.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c.js","sourceRoot":"","sources":["../../src/detectors/c.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,QAAQ,GAAG,qDAAqD,CAAC;AACvE,MAAM,OAAO,GAAG,6DAA6D,CAAC;AAC9E,MAAM,UAAU,GAAG,yCAAyC,CAAC;AAC7D,MAAM,SAAS,GAAG,0BAA0B,CAAC;AAC7C,MAAM,QAAQ,GAAG,iEAAiE,CAAC;AACnF,MAAM,OAAO,GAAG,+DAA+D,CAAC;AAEhF,MAAM,UAAU,GAAa;IAC3B,EAAE,EAAE,cAAc;IAClB,KAAK,EAAE,8BAA8B;IACrC,WAAW,EAAE,6CAA6C;IAC1D,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,MAAM;IACh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EAAE,UAAU,CAAC,CAAC;QAC1B,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACxB,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAC9B,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5B,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1B,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACxB,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAC1C,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;QAC5C,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAC1C,GAAG,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in C / C++ using\n * OpenSSL (the dominant crypto library for the ecosystem). Lexical, same\n * strategy as the other packs; the OpenSSL function names are distinctive.\n *\n * NOTE: scanning OpenSSL's OWN source/headers will naturally light up (the\n * library declares these symbols) — that is inherent to lexical scanning of a\n * crypto library, not a false positive in application code. Matches the classic\n * `*_generate_key` / `ECDSA_sign` / `ECDH_compute_key` call forms plus the\n * `EVP_RSA_gen` helper.\n *\n * HNDL: RSA encryption and (EC)DH key agreement are harvest-now-decrypt-later\n * exposed (hndl:true); ECDSA / DSA signatures are hndl:false but forgeable.\n * `EC_KEY_generate_key` is ambiguous (feeds ECDSA + ECDH), classified\n * conservatively as key-exchange-capable (hndl:true).\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { C_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst RE_C_RSA = /\\bRSA_generate_key(?:_ex)?\\s*\\(|\\bEVP_RSA_gen\\s*\\(/g;\nconst RE_C_EC = /\\bEC_KEY_generate_key\\s*\\(|\\bEC_KEY_new_by_curve_name\\s*\\(/g;\nconst RE_C_ECDSA = /\\bECDSA_do_sign\\s*\\(|\\bECDSA_sign\\s*\\(/g;\nconst RE_C_ECDH = /\\bECDH_compute_key\\s*\\(/g;\nconst RE_C_DSA = /\\bDSA_generate_key\\s*\\(|\\bDSA_generate_parameters(?:_ex)?\\s*\\(/g;\nconst RE_C_DH = /\\bDH_generate_key\\s*\\(|\\bDH_generate_parameters(?:_ex)?\\s*\\(/g;\n// Modern OpenSSL 3.x EVP API (the legacy *_generate_key forms above are\n// deprecated) + libsodium — the biggest C false-negative surface (audit F1).\nconst RE_C_EVP_KEYGEN = /\\bEVP_PKEY_(?:Q_)?keygen\\s*\\(|\\bEVP_PKEY_paramgen\\s*\\(/g;\nconst RE_C_EVP_DERIVE = /\\bEVP_PKEY_derive\\s*\\(/g;\nconst RE_C_EVP_CRYPT = /\\bEVP_PKEY_(?:encrypt|decrypt)\\s*\\(/g;\nconst RE_C_EVP_SIGN = /\\bEVP_DigestSign(?:Init)?\\s*\\(|\\bEVP_DigestVerify(?:Init)?\\s*\\(/g;\n// X25519: crypto_box / crypto_kx key pairs (incl. the fully-qualified\n// curve25519xsalsa20poly1305 form) plus the low-level crypto_scalarmult\n// primitive — all classical Curve25519 key agreement (audit recall gap).\nconst RE_C_SODIUM_BOX =\n /\\bcrypto_box_(?:curve25519xsalsa20poly1305_)?(?:seed_)?keypair\\s*\\(|\\bcrypto_kx_keypair\\s*\\(|\\bcrypto_scalarmult_(?:curve25519|base)\\s*\\(/g;\n// EdDSA: crypto_sign key pairs, including the explicit _ed25519 forms and the\n// deterministic seed_keypair variants (audit recall gap: _ed25519_keypair).\nconst RE_C_SODIUM_SIGN = /\\bcrypto_sign_(?:ed25519_)?(?:seed_)?keypair\\s*\\(/g;\n// Legacy verify / decrypt counterparts to the *_sign / *_encrypt rules above\n// (audit F4-c): the classic OpenSSL RSA/ECDSA verification and RSA raw\n// decryption call forms that the modern EVP + legacy keygen rules don't cover.\nconst RE_C_ECDSA_VERIFY = /\\bECDSA_verify\\s*\\(/g;\nconst RE_C_RSA_VERIFY = /\\bRSA_verify\\s*\\(/g;\nconst RE_C_RSA_CRYPT = /\\bRSA_public_encrypt\\s*\\(|\\bRSA_private_decrypt\\s*\\(/g;\n// C/OpenSSL legacy TLS configuration (mirrors source.ts tlsDetector): forcing a\n// deprecated protocol version or disabling certificate verification.\nconst RE_C_TLS_VERSION = /\\bTLSv1_method\\b|\\bSSLv3_method\\b/g;\nconst RE_C_TLS_VERIFY_NONE = /\\bSSL_VERIFY_NONE\\b/g;\n\nconst RULE_C_RSA: RuleMeta = {\n id: \"c-rsa-keygen\",\n title: \"C/OpenSSL RSA key generation\",\n description: \"OpenSSL RSA_generate_key(_ex) / EVP_RSA_gen\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Generates a classical RSA key pair (C/OpenSSL), which is not quantum-safe.\",\n};\nconst RULE_C_EC: RuleMeta = {\n id: \"c-ec-keygen\",\n title: \"C/OpenSSL EC key generation\",\n description: \"OpenSSL EC_KEY_generate_key / EC_KEY_new_by_curve_name\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical EC key pair (C/OpenSSL). EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_C_ECDSA: RuleMeta = {\n id: \"c-ecdsa\",\n title: \"C/OpenSSL ECDSA signature\",\n description: \"OpenSSL ECDSA_sign / ECDSA_do_sign\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (C/OpenSSL) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_C_ECDH: RuleMeta = {\n id: \"c-ecdh\",\n title: \"C/OpenSSL ECDH key agreement\",\n description: \"OpenSSL ECDH_compute_key\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Elliptic-curve Diffie-Hellman (C/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_C_DSA: RuleMeta = {\n id: \"c-dsa\",\n title: \"C/OpenSSL DSA key/usage\",\n description: \"OpenSSL DSA_generate_key / DSA_generate_parameters\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (C/OpenSSL) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_C_DH: RuleMeta = {\n id: \"c-dh\",\n title: \"C/OpenSSL Diffie-Hellman key exchange\",\n description: \"OpenSSL DH_generate_key / DH_generate_parameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (C/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_C_EVP_KEYGEN: RuleMeta = {\n id: \"c-evp-keygen\",\n title: \"C/OpenSSL EVP key generation\",\n description: \"OpenSSL 3.x EVP_PKEY_keygen / EVP_PKEY_Q_keygen / paramgen\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates an asymmetric key via the OpenSSL 3.x EVP API (the key type — RSA/EC/DH/X25519 — is set on the CTX). Treated conservatively as key-exchange-capable (harvest-now-decrypt-later).\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_C_EVP_DERIVE: RuleMeta = {\n id: \"c-evp-derive\",\n title: \"C/OpenSSL EVP key agreement\",\n description: \"OpenSSL 3.x EVP_PKEY_derive (ECDH / DH shared secret)\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Derives an (EC)DH shared secret via the OpenSSL EVP API — broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_C_EVP_CRYPT: RuleMeta = {\n id: \"c-evp-pkey-crypt\",\n title: \"C/OpenSSL EVP public-key encryption\",\n description: \"OpenSSL 3.x EVP_PKEY_encrypt / EVP_PKEY_decrypt (RSA)\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"RSA public-key encryption/decryption via the OpenSSL EVP API is harvest-now-decrypt-later exposed.\",\n};\nconst RULE_C_EVP_SIGN: RuleMeta = {\n id: \"c-evp-sign\",\n title: \"C/OpenSSL EVP signing\",\n description: \"OpenSSL 3.x EVP_DigestSign* / EVP_DigestVerify*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Classical signature via the OpenSSL EVP API (RSA/ECDSA/EdDSA) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_C_SODIUM_BOX: RuleMeta = {\n id: \"c-libsodium-box\",\n title: \"libsodium X25519 key pair\",\n description:\n \"libsodium crypto_box / crypto_kx keypair + crypto_scalarmult (X25519 key agreement)\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"libsodium crypto_box uses X25519 key agreement — modern but classical, and harvest-now-decrypt-later exposed.\",\n};\nconst RULE_C_SODIUM_SIGN: RuleMeta = {\n id: \"c-libsodium-sign\",\n title: \"libsodium Ed25519 key pair\",\n description: \"libsodium crypto_sign(_ed25519)(_seed)_keypair (Ed25519 signatures)\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"libsodium crypto_sign uses Ed25519 signatures — classical and forgeable by a quantum attacker.\",\n};\nconst RULE_C_ECDSA_VERIFY: RuleMeta = {\n id: \"c-ecdsa-verify\",\n title: \"C/OpenSSL ECDSA signature verification\",\n description: \"OpenSSL ECDSA_verify\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Classical ECDSA verification (C/OpenSSL) trusts signatures forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_C_RSA_VERIFY: RuleMeta = {\n id: \"c-rsa-verify\",\n title: \"C/OpenSSL RSA signature verification\",\n description: \"OpenSSL RSA_verify\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Classical RSA signature verification (C/OpenSSL) trusts signatures forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_C_RSA_CRYPT: RuleMeta = {\n id: \"c-rsa-crypt\",\n title: \"C/OpenSSL RSA public-key encryption\",\n description: \"OpenSSL RSA_public_encrypt / RSA_private_decrypt\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Legacy RSA public-key encryption/decryption (C/OpenSSL) is harvest-now-decrypt-later exposed.\",\n};\nconst RULE_C_TLS_VERSION: RuleMeta = {\n id: \"c-tls-legacy-version\",\n title: \"Legacy TLS/SSL version pinned (C/OpenSSL)\",\n description: \"OpenSSL TLSv1_method / SSLv3_method\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"TLS 1.0 / SSLv3 are deprecated and insecure; require TLS 1.3.\",\n remediation: \"Use TLS_method() with a minimum of TLS 1.3 and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_C_TLS_VERIFY_NONE: RuleMeta = {\n id: \"c-tls-verify-none\",\n title: \"TLS certificate verification disabled (C/OpenSSL)\",\n description: \"OpenSSL SSL_VERIFY_NONE\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"SSL_VERIFY_NONE disables TLS certificate verification (MITM risk).\",\n remediation: \"Use SSL_VERIFY_PEER and verify certificates properly.\",\n};\n\n/** Detects classical asymmetric crypto in C/C++ (OpenSSL). */\nexport const cDetector: Detector = {\n id: \"c-crypto\",\n description: \"Classical asymmetric crypto in C/C++ (OpenSSL)\",\n scope: \"source\",\n language: \"c\",\n rules: [\n RULE_C_RSA,\n RULE_C_EC,\n RULE_C_ECDSA,\n RULE_C_ECDH,\n RULE_C_DSA,\n RULE_C_DH,\n RULE_C_EVP_KEYGEN,\n RULE_C_EVP_DERIVE,\n RULE_C_EVP_CRYPT,\n RULE_C_EVP_SIGN,\n RULE_C_SODIUM_BOX,\n RULE_C_SODIUM_SIGN,\n RULE_C_ECDSA_VERIFY,\n RULE_C_RSA_VERIFY,\n RULE_C_RSA_CRYPT,\n RULE_C_TLS_VERSION,\n RULE_C_TLS_VERIFY_NONE,\n ],\n appliesTo: (f) => hasExtension(f, C_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n const add = (re: RegExp, rule: RuleMeta) =>\n eachMatch(re, content, (m) =>\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n ),\n );\n add(RE_C_RSA, RULE_C_RSA);\n add(RE_C_EC, RULE_C_EC);\n add(RE_C_ECDSA, RULE_C_ECDSA);\n add(RE_C_ECDH, RULE_C_ECDH);\n add(RE_C_DSA, RULE_C_DSA);\n add(RE_C_DH, RULE_C_DH);\n add(RE_C_EVP_KEYGEN, RULE_C_EVP_KEYGEN);\n add(RE_C_EVP_DERIVE, RULE_C_EVP_DERIVE);\n add(RE_C_EVP_CRYPT, RULE_C_EVP_CRYPT);\n add(RE_C_EVP_SIGN, RULE_C_EVP_SIGN);\n add(RE_C_SODIUM_BOX, RULE_C_SODIUM_BOX);\n add(RE_C_SODIUM_SIGN, RULE_C_SODIUM_SIGN);\n add(RE_C_ECDSA_VERIFY, RULE_C_ECDSA_VERIFY);\n add(RE_C_RSA_VERIFY, RULE_C_RSA_VERIFY);\n add(RE_C_RSA_CRYPT, RULE_C_RSA_CRYPT);\n add(RE_C_TLS_VERSION, RULE_C_TLS_VERSION);\n add(RE_C_TLS_VERIFY_NONE, RULE_C_TLS_VERIFY_NONE);\n return findings;\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AA8L/D,gFAAgF;AAChF,eAAO,MAAM,cAAc,EAAE,QA8C5B,CAAC"}
|
package/dist/detectors/csharp.js
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import { CSHARP_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
|
|
2
|
-
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
2
|
+
import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from "../cwe.js";
|
|
3
3
|
const RE_CS_RSA = /\bRSA\.Create\s*\(|\bnew\s+RSACryptoServiceProvider\s*\(|\bnew\s+RSACng\s*\(|\bnew\s+RSAOpenSsl\s*\(/g;
|
|
4
4
|
const RE_CS_ECDSA = /\bECDsa\.Create\s*\(|\bnew\s+ECDsaCng\s*\(|\bnew\s+ECDsaOpenSsl\s*\(/g;
|
|
5
5
|
const RE_CS_ECDH = /\bECDiffieHellman\.Create\s*\(|\bnew\s+ECDiffieHellmanCng\s*\(|\bnew\s+ECDiffieHellmanOpenSsl\s*\(/g;
|
|
6
6
|
const RE_CS_DSA = /\bDSA\.Create\s*\(|\bnew\s+DSACryptoServiceProvider\s*\(|\bnew\s+DSACng\s*\(/g;
|
|
7
|
+
// Insecure TLS configuration (.NET). Mirrors source.ts's tlsDetector split of a
|
|
8
|
+
// cert-verification-disabled rule (tls-reject-unauthorized) and a legacy-version
|
|
9
|
+
// rule (tls-legacy-version) for the equivalent C# idioms:
|
|
10
|
+
// - DangerousAcceptAnyServerCertificateValidator / a custom
|
|
11
|
+
// ServerCertificateCustomValidationCallback → accepts any cert (MITM).
|
|
12
|
+
// - SslProtocols.Ssl3 / .Tls / .Tls11 → deprecated SSL 3.0 / TLS 1.0 / 1.1.
|
|
13
|
+
// `SslProtocols.Tls` (no suffix) is the legacy TLS 1.0 constant; `Tls12`/`Tls13`
|
|
14
|
+
// are excluded by the trailing \b (the following digit is a word char).
|
|
15
|
+
const RE_CS_TLS_CERT_VALIDATION = /\bDangerousAcceptAnyServerCertificateValidator\b|ServerCertificateCustomValidationCallback\s*=/g;
|
|
16
|
+
const RE_CS_TLS_LEGACY_VERSION = /\bSslProtocols\.(?:Tls|Tls11|Ssl3)\b/g;
|
|
17
|
+
// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string
|
|
18
|
+
// alg token ("RS256") is caught by the language-agnostic jwt-jose detector, but
|
|
19
|
+
// Microsoft.IdentityModel passes the alg as an IDENTIFIER, not a string literal:
|
|
20
|
+
// SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256.
|
|
21
|
+
const RE_CS_JWT_ALG = /\bSecurityAlgorithms\.(?:Rsa|Ecdsa)Sha(?:256|384|512)\b/g;
|
|
22
|
+
// BouncyCastle (Org.BouncyCastle) modern-curve and finite-field DH primitives,
|
|
23
|
+
// which System.Security.Cryptography does not expose directly. Each regex is
|
|
24
|
+
// anchored to the distinctive BouncyCastle class names for one family so it
|
|
25
|
+
// can't misfire on unrelated identifiers:
|
|
26
|
+
// - Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters → EdDSA
|
|
27
|
+
// - X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters → X25519
|
|
28
|
+
// - X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters → X448
|
|
29
|
+
// - DHParametersGenerator / DHBasicAgreement / DH(Basic)KeyPairGenerator / DHParameters → DH
|
|
30
|
+
// The trailing \b keeps each token whole (e.g. Ed25519KeyGenerationParameters,
|
|
31
|
+
// X25519PublicKeyParameters and DHKeyGenerationParameters are NOT matched).
|
|
32
|
+
const RE_CS_BC_EDDSA = /\bEd25519(?:KeyPairGenerator|Signer|PrivateKeyParameters)\b/g;
|
|
33
|
+
const RE_CS_BC_X25519 = /\bX25519(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\b/g;
|
|
34
|
+
const RE_CS_BC_X448 = /\bX448(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\b/g;
|
|
35
|
+
const RE_CS_BC_DH = /\bDH(?:ParametersGenerator|BasicAgreement|BasicKeyPairGenerator|KeyPairGenerator|Parameters)\b/g;
|
|
7
36
|
const RULE_CS_RSA = {
|
|
8
37
|
id: "csharp-rsa",
|
|
9
38
|
title: "C# RSA key/usage",
|
|
@@ -54,13 +83,111 @@ const RULE_CS_DSA = {
|
|
|
54
83
|
message: "Classical DSA (.NET) is deprecated and forgeable by a quantum attacker.",
|
|
55
84
|
remediation: "Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).",
|
|
56
85
|
};
|
|
86
|
+
const RULE_CS_TLS_CERT = {
|
|
87
|
+
id: "csharp-tls-cert-validation",
|
|
88
|
+
title: "C# TLS certificate verification disabled",
|
|
89
|
+
description: "DangerousAcceptAnyServerCertificateValidator / ServerCertificateCustomValidationCallback override",
|
|
90
|
+
category: "tls",
|
|
91
|
+
severity: "high",
|
|
92
|
+
confidence: "high",
|
|
93
|
+
hndl: false,
|
|
94
|
+
cwe: CWE_CERT_VALIDATION,
|
|
95
|
+
message: "Accepting any server certificate disables TLS certificate verification (MITM risk).",
|
|
96
|
+
remediation: "Remove the custom validator and verify certificates properly; prefer PQC-hybrid key exchange.",
|
|
97
|
+
};
|
|
98
|
+
const RULE_CS_TLS_LEGACY = {
|
|
99
|
+
id: "csharp-tls-legacy-version",
|
|
100
|
+
title: "C# legacy TLS/SSL version pinned",
|
|
101
|
+
description: "SslProtocols pinned to Ssl3 / TLS 1.0 / TLS 1.1",
|
|
102
|
+
category: "tls",
|
|
103
|
+
severity: "medium",
|
|
104
|
+
confidence: "high",
|
|
105
|
+
hndl: false,
|
|
106
|
+
cwe: CWE_WEAK_STRENGTH,
|
|
107
|
+
message: "SSL 3.0 / TLS 1.0 / TLS 1.1 are deprecated and insecure; require TLS 1.2+ (prefer 1.3).",
|
|
108
|
+
remediation: "Use SslProtocols.Tls13 (or Tls12) and prefer PQC-hybrid key exchange.",
|
|
109
|
+
};
|
|
110
|
+
const RULE_CS_JWT_ALG = {
|
|
111
|
+
id: "csharp-jwt-alg",
|
|
112
|
+
title: "C# identifier-form JWT/JOSE algorithm",
|
|
113
|
+
description: "Microsoft.IdentityModel SecurityAlgorithms.RsaSha* / EcdsaSha*",
|
|
114
|
+
category: "signature",
|
|
115
|
+
severity: "high",
|
|
116
|
+
confidence: "high",
|
|
117
|
+
algorithm: "unknown",
|
|
118
|
+
hndl: false,
|
|
119
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
120
|
+
message: "A classical JWT/JOSE signature algorithm (.NET, identifier form) is used, forgeable by a quantum attacker.",
|
|
121
|
+
remediation: "ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms",
|
|
122
|
+
};
|
|
123
|
+
const RULE_CS_BC_EDDSA = {
|
|
124
|
+
id: "csharp-bouncycastle-eddsa",
|
|
125
|
+
title: "C# Ed25519 signature (BouncyCastle)",
|
|
126
|
+
description: "Org.BouncyCastle Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters",
|
|
127
|
+
category: "signature",
|
|
128
|
+
severity: "high",
|
|
129
|
+
confidence: "high",
|
|
130
|
+
algorithm: "EdDSA",
|
|
131
|
+
hndl: false,
|
|
132
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
133
|
+
message: "Classical Ed25519 signing (BouncyCastle) is forgeable by a quantum attacker.",
|
|
134
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
135
|
+
};
|
|
136
|
+
const RULE_CS_BC_X25519 = {
|
|
137
|
+
id: "csharp-bouncycastle-x25519",
|
|
138
|
+
title: "C# X25519 key agreement (BouncyCastle)",
|
|
139
|
+
description: "Org.BouncyCastle X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters",
|
|
140
|
+
category: "key-exchange",
|
|
141
|
+
severity: "high",
|
|
142
|
+
confidence: "high",
|
|
143
|
+
algorithm: "X25519",
|
|
144
|
+
hndl: true,
|
|
145
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
146
|
+
message: "X25519 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
147
|
+
};
|
|
148
|
+
const RULE_CS_BC_X448 = {
|
|
149
|
+
id: "csharp-bouncycastle-x448",
|
|
150
|
+
title: "C# X448 key agreement (BouncyCastle)",
|
|
151
|
+
description: "Org.BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters",
|
|
152
|
+
category: "key-exchange",
|
|
153
|
+
severity: "high",
|
|
154
|
+
confidence: "high",
|
|
155
|
+
algorithm: "X448",
|
|
156
|
+
hndl: true,
|
|
157
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
158
|
+
message: "X448 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
159
|
+
};
|
|
160
|
+
const RULE_CS_BC_DH = {
|
|
161
|
+
id: "csharp-bouncycastle-dh",
|
|
162
|
+
title: "C# finite-field Diffie-Hellman (BouncyCastle)",
|
|
163
|
+
description: "Org.BouncyCastle DHParametersGenerator / DHBasicAgreement / DHKeyPairGenerator / DHParameters",
|
|
164
|
+
category: "key-exchange",
|
|
165
|
+
severity: "high",
|
|
166
|
+
confidence: "high",
|
|
167
|
+
algorithm: "DH",
|
|
168
|
+
hndl: true,
|
|
169
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
170
|
+
message: "Finite-field Diffie-Hellman (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
171
|
+
};
|
|
57
172
|
/** Detects classical asymmetric crypto in C# (System.Security.Cryptography). */
|
|
58
173
|
export const csharpDetector = {
|
|
59
174
|
id: "csharp-crypto",
|
|
60
|
-
description: "Classical asymmetric crypto
|
|
175
|
+
description: "Classical asymmetric crypto (System.Security.Cryptography) and insecure TLS config in C#/.NET",
|
|
61
176
|
scope: "source",
|
|
62
177
|
language: "csharp",
|
|
63
|
-
rules: [
|
|
178
|
+
rules: [
|
|
179
|
+
RULE_CS_RSA,
|
|
180
|
+
RULE_CS_ECDSA,
|
|
181
|
+
RULE_CS_ECDH,
|
|
182
|
+
RULE_CS_DSA,
|
|
183
|
+
RULE_CS_TLS_CERT,
|
|
184
|
+
RULE_CS_TLS_LEGACY,
|
|
185
|
+
RULE_CS_JWT_ALG,
|
|
186
|
+
RULE_CS_BC_EDDSA,
|
|
187
|
+
RULE_CS_BC_X25519,
|
|
188
|
+
RULE_CS_BC_X448,
|
|
189
|
+
RULE_CS_BC_DH,
|
|
190
|
+
],
|
|
64
191
|
appliesTo: (f) => hasExtension(f, CSHARP_EXTENSIONS),
|
|
65
192
|
detect({ file, content }) {
|
|
66
193
|
const findings = [];
|
|
@@ -70,6 +197,17 @@ export const csharpDetector = {
|
|
|
70
197
|
add(RE_CS_ECDH, RULE_CS_ECDH);
|
|
71
198
|
add(RE_CS_RSA, RULE_CS_RSA);
|
|
72
199
|
add(RE_CS_DSA, RULE_CS_DSA);
|
|
200
|
+
// Insecure TLS configuration (disjoint from the crypto factories above).
|
|
201
|
+
add(RE_CS_TLS_CERT_VALIDATION, RULE_CS_TLS_CERT);
|
|
202
|
+
add(RE_CS_TLS_LEGACY_VERSION, RULE_CS_TLS_LEGACY);
|
|
203
|
+
// Identifier-form JWT/JOSE signature algorithms (Microsoft.IdentityModel).
|
|
204
|
+
add(RE_CS_JWT_ALG, RULE_CS_JWT_ALG);
|
|
205
|
+
// BouncyCastle (Org.BouncyCastle) curve / finite-field DH primitives that
|
|
206
|
+
// System.Security.Cryptography does not expose directly.
|
|
207
|
+
add(RE_CS_BC_EDDSA, RULE_CS_BC_EDDSA);
|
|
208
|
+
add(RE_CS_BC_X25519, RULE_CS_BC_X25519);
|
|
209
|
+
add(RE_CS_BC_X448, RULE_CS_BC_X448);
|
|
210
|
+
add(RE_CS_BC_DH, RULE_CS_BC_DH);
|
|
73
211
|
return findings;
|
|
74
212
|
},
|
|
75
213
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.js","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,SAAS,GACb,uGAAuG,CAAC;AAC1G,MAAM,WAAW,GAAG,uEAAuE,CAAC;AAC5F,MAAM,UAAU,GACd,qGAAqG,CAAC;AACxG,MAAM,SAAS,GAAG,+EAA+E,CAAC;AAElG,MAAM,WAAW,GAAa;IAC5B,EAAE,EAAE,YAAY;IAChB,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,6EAA6E;IAC1F,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,iBAAiB;IACtB,OAAO,EAAE,8EAA8E;CACxF,CAAC;AACF,MAAM,aAAa,GAAa;IAC9B,EAAE,EAAE,cAAc;IAClB,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EAAE,sDAAsD;IACnE,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,OAAO;IAClB,IA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;QACpC,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in C# / .NET\n * (`System.Security.Cryptography`). Same lexical strategy as the other packs.\n * .NET exposes each algorithm through a factory (`RSA.Create()`,\n * `ECDsa.Create()`, `ECDiffieHellman.Create()`) or a concrete CSP/CNG class\n * (`RSACryptoServiceProvider`, `ECDsaCng`, …), all of which are precise signals.\n *\n * HNDL: RSA (keygen/encryption) and (EC)DH key agreement are harvest-now-\n * decrypt-later exposed (hndl:true); ECDSA/DSA signatures are hndl:false but\n * forgeable by a quantum attacker.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { CSHARP_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst RE_CS_RSA =\n /\\bRSA\\.Create\\s*\\(|\\bnew\\s+RSACryptoServiceProvider\\s*\\(|\\bnew\\s+RSACng\\s*\\(|\\bnew\\s+RSAOpenSsl\\s*\\(/g;\nconst RE_CS_ECDSA = /\\bECDsa\\.Create\\s*\\(|\\bnew\\s+ECDsaCng\\s*\\(|\\bnew\\s+ECDsaOpenSsl\\s*\\(/g;\nconst RE_CS_ECDH =\n /\\bECDiffieHellman\\.Create\\s*\\(|\\bnew\\s+ECDiffieHellmanCng\\s*\\(|\\bnew\\s+ECDiffieHellmanOpenSsl\\s*\\(/g;\nconst RE_CS_DSA = /\\bDSA\\.Create\\s*\\(|\\bnew\\s+DSACryptoServiceProvider\\s*\\(|\\bnew\\s+DSACng\\s*\\(/g;\n// Insecure TLS configuration (.NET). Mirrors source.ts's tlsDetector split of a\n// cert-verification-disabled rule (tls-reject-unauthorized) and a legacy-version\n// rule (tls-legacy-version) for the equivalent C# idioms:\n// - DangerousAcceptAnyServerCertificateValidator / a custom\n// ServerCertificateCustomValidationCallback → accepts any cert (MITM).\n// - SslProtocols.Ssl3 / .Tls / .Tls11 → deprecated SSL 3.0 / TLS 1.0 / 1.1.\n// `SslProtocols.Tls` (no suffix) is the legacy TLS 1.0 constant; `Tls12`/`Tls13`\n// are excluded by the trailing \\b (the following digit is a word char).\nconst RE_CS_TLS_CERT_VALIDATION =\n /\\bDangerousAcceptAnyServerCertificateValidator\\b|ServerCertificateCustomValidationCallback\\s*=/g;\nconst RE_CS_TLS_LEGACY_VERSION = /\\bSslProtocols\\.(?:Tls|Tls11|Ssl3)\\b/g;\n// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string\n// alg token (\"RS256\") is caught by the language-agnostic jwt-jose detector, but\n// Microsoft.IdentityModel passes the alg as an IDENTIFIER, not a string literal:\n// SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256.\nconst RE_CS_JWT_ALG = /\\bSecurityAlgorithms\\.(?:Rsa|Ecdsa)Sha(?:256|384|512)\\b/g;\n// BouncyCastle (Org.BouncyCastle) modern-curve and finite-field DH primitives,\n// which System.Security.Cryptography does not expose directly. Each regex is\n// anchored to the distinctive BouncyCastle class names for one family so it\n// can't misfire on unrelated identifiers:\n// - Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters → EdDSA\n// - X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters → X25519\n// - X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters → X448\n// - DHParametersGenerator / DHBasicAgreement / DH(Basic)KeyPairGenerator / DHParameters → DH\n// The trailing \\b keeps each token whole (e.g. Ed25519KeyGenerationParameters,\n// X25519PublicKeyParameters and DHKeyGenerationParameters are NOT matched).\nconst RE_CS_BC_EDDSA = /\\bEd25519(?:KeyPairGenerator|Signer|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X25519 = /\\bX25519(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X448 = /\\bX448(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_DH =\n /\\bDH(?:ParametersGenerator|BasicAgreement|BasicKeyPairGenerator|KeyPairGenerator|Parameters)\\b/g;\n\nconst RULE_CS_RSA: RuleMeta = {\n id: \"csharp-rsa\",\n title: \"C# RSA key/usage\",\n description: \"System.Security.Cryptography RSA.Create / RSACryptoServiceProvider / RSACng\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (.NET) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_CS_ECDSA: RuleMeta = {\n id: \"csharp-ecdsa\",\n title: \"C# ECDSA signature\",\n description: \"System.Security.Cryptography ECDsa.Create / ECDsaCng\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (.NET) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_ECDH: RuleMeta = {\n id: \"csharp-ecdh\",\n title: \"C# ECDH key agreement\",\n description: \"System.Security.Cryptography ECDiffieHellman.Create / ECDiffieHellmanCng\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Elliptic-curve Diffie-Hellman (.NET) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_DSA: RuleMeta = {\n id: \"csharp-dsa\",\n title: \"C# DSA key/signature\",\n description: \"System.Security.Cryptography DSA.Create / DSACryptoServiceProvider\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (.NET) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_CS_TLS_CERT: RuleMeta = {\n id: \"csharp-tls-cert-validation\",\n title: \"C# TLS certificate verification disabled\",\n description:\n \"DangerousAcceptAnyServerCertificateValidator / ServerCertificateCustomValidationCallback override\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"Accepting any server certificate disables TLS certificate verification (MITM risk).\",\n remediation:\n \"Remove the custom validator and verify certificates properly; prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_TLS_LEGACY: RuleMeta = {\n id: \"csharp-tls-legacy-version\",\n title: \"C# legacy TLS/SSL version pinned\",\n description: \"SslProtocols pinned to Ssl3 / TLS 1.0 / TLS 1.1\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message:\n \"SSL 3.0 / TLS 1.0 / TLS 1.1 are deprecated and insecure; require TLS 1.2+ (prefer 1.3).\",\n remediation: \"Use SslProtocols.Tls13 (or Tls12) and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_JWT_ALG: RuleMeta = {\n id: \"csharp-jwt-alg\",\n title: \"C# identifier-form JWT/JOSE algorithm\",\n description: \"Microsoft.IdentityModel SecurityAlgorithms.RsaSha* / EcdsaSha*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A classical JWT/JOSE signature algorithm (.NET, identifier form) is used, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms\",\n};\nconst RULE_CS_BC_EDDSA: RuleMeta = {\n id: \"csharp-bouncycastle-eddsa\",\n title: \"C# Ed25519 signature (BouncyCastle)\",\n description:\n \"Org.BouncyCastle Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical Ed25519 signing (BouncyCastle) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_BC_X25519: RuleMeta = {\n id: \"csharp-bouncycastle-x25519\",\n title: \"C# X25519 key agreement (BouncyCastle)\",\n description:\n \"Org.BouncyCastle X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_X448: RuleMeta = {\n id: \"csharp-bouncycastle-x448\",\n title: \"C# X448 key agreement (BouncyCastle)\",\n description: \"Org.BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X448 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_DH: RuleMeta = {\n id: \"csharp-bouncycastle-dh\",\n title: \"C# finite-field Diffie-Hellman (BouncyCastle)\",\n description:\n \"Org.BouncyCastle DHParametersGenerator / DHBasicAgreement / DHKeyPairGenerator / DHParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\n\n/** Detects classical asymmetric crypto in C# (System.Security.Cryptography). */\nexport const csharpDetector: Detector = {\n id: \"csharp-crypto\",\n description:\n \"Classical asymmetric crypto (System.Security.Cryptography) and insecure TLS config in C#/.NET\",\n scope: \"source\",\n language: \"csharp\",\n rules: [\n RULE_CS_RSA,\n RULE_CS_ECDSA,\n RULE_CS_ECDH,\n RULE_CS_DSA,\n RULE_CS_TLS_CERT,\n RULE_CS_TLS_LEGACY,\n RULE_CS_JWT_ALG,\n RULE_CS_BC_EDDSA,\n RULE_CS_BC_X25519,\n RULE_CS_BC_X448,\n RULE_CS_BC_DH,\n ],\n appliesTo: (f) => hasExtension(f, CSHARP_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n const add = (re: RegExp, rule: RuleMeta) =>\n eachMatch(re, content, (m) =>\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n ),\n );\n // ECDSA / ECDH before RSA/DSA so the specific EC factories win.\n add(RE_CS_ECDSA, RULE_CS_ECDSA);\n add(RE_CS_ECDH, RULE_CS_ECDH);\n add(RE_CS_RSA, RULE_CS_RSA);\n add(RE_CS_DSA, RULE_CS_DSA);\n // Insecure TLS configuration (disjoint from the crypto factories above).\n add(RE_CS_TLS_CERT_VALIDATION, RULE_CS_TLS_CERT);\n add(RE_CS_TLS_LEGACY_VERSION, RULE_CS_TLS_LEGACY);\n // Identifier-form JWT/JOSE signature algorithms (Microsoft.IdentityModel).\n add(RE_CS_JWT_ALG, RULE_CS_JWT_ALG);\n // BouncyCastle (Org.BouncyCastle) curve / finite-field DH primitives that\n // System.Security.Cryptography does not expose directly.\n add(RE_CS_BC_EDDSA, RULE_CS_BC_EDDSA);\n add(RE_CS_BC_X25519, RULE_CS_BC_X25519);\n add(RE_CS_BC_X448, RULE_CS_BC_X448);\n add(RE_CS_BC_DH, RULE_CS_BC_DH);\n return findings;\n },\n};\n"]}
|