dsh-standards 1.6.4 → 1.6.6

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.
@@ -875,15 +875,15 @@ export function apply(ctx: Context) {
875
875
 
876
876
  ### C-16 动态执行
877
877
 
878
- > **判定**:**blocking**(仅 `--scope security`)。动态执行默认不可审计;本项没有"声明后放行"的例外,命中即 FAIL。
878
+ > **判定**:**blocking**(仅 `--scope security`)。动态执行默认不可审计;本项没有"声明后放行"的例外,非 vendor 命中即 FAIL;1.6.6 起 vendor 文件内的 `eval`/`new Function` 仅降为 WARN(不是 PASS,可用 `--strict-vendor` 恢复 FAIL)。
879
879
 
880
880
  **要求(祈使句)**:服务端入口闭包不得使用 `eval`、`new Function`(空参探针除外)、`vm.runIn*`/`vm.Script`/`vm.createContext`、`module._compile`、`process.binding`;不得直接 `require`/`import` `child_process` 绕过 `ctx.subprocess`。
881
881
 
882
- **判定方式**:L0 静态(DSC-16)。只扫服务端入口及其**本地相对 import 闭包**;`lib/client.js`/浏览器 bundle 不扫(避免把打包器探针当插件行为);`new Function("")` / `new Function()` 空参探针豁免。1.6.1 对裸 `child_process` 只 WARN;1.6.2 起对静态可判为下载后执行/解码执行的危险命令升级 FAIL。
882
+ **判定方式**:L0 静态(DSC-16)。只扫服务端入口及其**本地相对 import 闭包**;`lib/client.js`/浏览器 bundle 不扫(避免把打包器探针当插件行为);`new Function("")` / `new Function()` 空参探针豁免。1.6.1 对裸 `child_process` 只 WARN;1.6.2 起对静态可判为下载后执行/解码执行的危险命令升级 FAIL;1.6.6 起 vendor/第三方文件内的 `eval`/`new Function` 降为 WARN(detail 记 `C-16.1` + `vendor: true` + 理由),默认可用 `--strict-vendor`(别名 `--no-vendor-exempt`)恢复 FAIL。
883
883
 
884
884
  | 子项 | 检查 | 结果 |
885
885
  |---|---|---|
886
- | C-16.1 | 闭包内 `eval`、`new Function(非空)`、`module._compile`、`process.binding`;1.6.2 起含静态可判的危险子进程命令(下载后执行/解码执行) | 命中 → FAIL |
886
+ | C-16.1 | 闭包内 `eval`、`new Function(非空)`、`module._compile`、`process.binding`;1.6.2 起含静态可判的危险子进程命令(下载后执行/解码执行);1.6.6 起 vendor 文件内的 `eval`/`new Function` 单独降级 | 非 vendor → FAIL;vendor → WARN(`vendor: true`;`--strict-vendor` 恢复 FAIL) |
887
887
  | C-16.2 | 闭包内 `vm.runIn*`、`vm.Script`、`vm.createContext` | 命中 → FAIL |
888
888
  | C-16.3 | 闭包内 `require('child_process')` / `import('node:child_process')` 等裸子进程入口;空参 `new Function("")`/`lib/client.js` 豁免 | 裸入口 → WARN(1.6.1 危险子进程命令也只 WARN;1.6.2 起改判 C-16.1 FAIL);空参/client → 不计负 |
889
889
  | C-16.4 | 字符串拼接 `import()`、`Function(atob(...))`、运行时从远程取代码;package import/解析失败 | 静态不可判 → `not-run`/`partial`,不冒充 PASS |
@@ -893,12 +893,14 @@ export function apply(ctx: Context) {
893
893
  | 值 | 条件 |
894
894
  |---|---|
895
895
  | PASS | C-16.1/C-16.2/C-16.3 均无命中;C-16.4 的 package import/unresolved 只写 `coverage: partial`,不改 PASS |
896
- | WARN | 仅 C-16.3 命中(裸 `child_process`) |
897
- | FAIL | C-16.1 或 C-16.2 任一命中 |
896
+ | WARN | 仅 C-16.3 命中(裸 `child_process`);或仅 vendor 文件内的 C-16.1 命中(不进入 `security.blocking`;`--strict-vendor` 下仍 FAIL) |
897
+ | FAIL | 非 vendor 文件的 C-16.1 或 C-16.2 任一命中;或任意文件的 base64 混淆执行(vendor 也不豁免) |
898
898
  | NA | 没有可扫描的源文件;或 `dsh.kind` 非 plugin/bundle |
899
899
 
900
900
  **误报与抑制**:打包进 bundle 的 ajv 会用 `new Function("")` 探 `allowsEval`(`dsh-budget/lib/client.js`、`dsh-library/lib/index.js`),空参豁免;浏览器 bundle 不扫。Babel/TS 解析失败记 `ERROR`/`not-run`,不判 PASS;AST 只认真实调用,不把 `typeof eval` 当执行。
901
901
 
902
+ **vendor/第三方源码(1.6.6,`DSC-16` 专用)**:只有 `eval()` / `new Function()` 可降级,且文件须满足下列之一:路径含 `node_modules/`、`vendor/`、`third_party/`、`deps/`;有打包器 `//#region node_modules/...` 区间(按命中行所在区间判定库名);有 `schemastery`/`ajv`/`lodash` 库指纹或库形文件名;或同目录(`src/` 外)有上述强证据。`package.json` 的 `dependencies`/`devDependencies` 含该库只作佐证,**单独不足以豁免**(防止以声明依赖换取 `eval` 放行)。`vm.*`、`module._compile`、`process.binding`、危险子进程命令、base64+eval 一律不豁免;降级结果为 WARN(永不 PASS),`--strict-vendor` 恢复 FAIL。该识别是启发式、可伪造,不构成"第三方代码安全"的证明。
903
+
902
904
  **与 DSC 的对应**:`DSC-16`。扩展 `C-11.2` 触发表:C-11.2 只认 `ctx.*`、裸 `fetch` 等文本,不认 `eval`/`vm`/node 内置模块;C-10.4 只覆盖 import 期 fs/子进程,不覆盖 eval。动态执行没有声明放行(checker 不读取 `code:dynamic` 之类的字段)。
903
905
 
904
906
  **边界说明**:动态执行的判定高度依赖静态形态;`globalThis['ev'+'al']`、`require('vm')`、WebAssembly、远程代码加载都可绕过。PASS 不是"没有动态执行",只是"本次闭包内没有可见形态"。
@@ -911,7 +913,7 @@ export function apply(ctx: Context) {
911
913
 
912
914
  **要求(祈使句)**:不得直接读取 `~/.ssh`、`id_rsa`、`~/.aws`、`.npmrc`、`.netrc`、`.pypi`、`tokens*`、`$DSH_HOME`/`~/.dsh` 下的 credentials 文件或 `credentials-local` 内部实现;凭据必须经 `ctx.credentials.resolve()` / `credentialRef()` 读取;不得为外发而枚举 `process.env`。
913
915
 
914
- **判定方式**:L0 静态(DSC-17)。对**读/列 API** 的实参回溯:`readFile*`、`openSync`、`readJson`、`createReadStream`、`readdir*`;字符串字面量、正则字面量(如 `/^\.?credentials/`)、`path.join` 常量折叠、模板静态段、同函数赋值链可判;`os.homedir()` / `process.env.HOME|USERPROFILE|DSH_HOME|XDG_CONFIG_HOME` 派生路径按同函数污点近似(派生路径 + 同函数出站可 FAIL)。`Object.keys(process.env)` 单独记一条 WARN。
916
+ **判定方式**:L0 静态(DSC-17)。对**读/列 API** 的实参回溯:`readFile*`、`openSync`、`readJson`、`createReadStream`、`readdir*`;字符串字面量、正则字面量(如 `/^\.?credentials/`)、`path.join` 常量折叠、模板静态段、同函数赋值链可判;`os.homedir()` / `process.env.HOME|USERPROFILE|DSH_HOME|XDG_CONFIG_HOME` 派生路径按同函数污点近似(派生路径 + 同函数出站可 FAIL)。`Object.keys(process.env)` 单独枚举不作判定(PASS);只有与同闭包出站组合才记 WARN。
915
917
 
916
918
  | 子项 | 检查 | 结果 |
917
919
  |---|---|---|
@@ -0,0 +1,16 @@
1
+ // A bundle that inlines a declared dependency the way esbuild/rolldown does.
2
+ // The schemastery parser compiles a *declared callback string*, not a payload.
3
+ //#region node_modules/.pnpm/@deepseek-ai+schemastery@3.19.0/node_modules/@deepseek-ai/schemastery/lib/index.js
4
+ const kSchema = Symbol.for("schemastery")
5
+
6
+ export function apply(schema) {
7
+ if (typeof schema.callback === "string") {
8
+ schema.callback = new Function("return " + schema.callback)()
9
+ }
10
+ return { schema, kSchema }
11
+ }
12
+ //#endregion
13
+
14
+ export function register(ctx) {
15
+ ctx?.plugin?.(apply)
16
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@dsh-fixtures/sec16-vendor-bundle",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@deepseek-ai/schemastery": "~3.19.0"
12
+ },
13
+ "engines": {
14
+ "dsh": ">=0.2.2-alpha.2 <0.3.0"
15
+ },
16
+ "dsh": {
17
+ "manifestVersion": 1,
18
+ "kind": "plugin",
19
+ "capabilities": [],
20
+ "labels": []
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ // A declared schemastery dependency is NOT enough: this file carries no vendor
2
+ // marker or library fingerprint, so its own new Function() must stay FAIL.
3
+ export function apply() {
4
+ return new Function('return 1 + 1')()
5
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@dsh-fixtures/sec16-vendor-decoy",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@deepseek-ai/schemastery": "~3.19.0"
12
+ },
13
+ "engines": {
14
+ "dsh": ">=0.2.2-alpha.2 <0.3.0"
15
+ },
16
+ "dsh": {
17
+ "manifestVersion": 1,
18
+ "kind": "plugin",
19
+ "capabilities": [],
20
+ "labels": []
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ export { compile } from './vendor/schemastery.mjs'
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@dsh-fixtures/sec16-vendor-path",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./index.mjs",
7
+ "exports": {
8
+ ".": "./index.mjs"
9
+ },
10
+ "engines": {
11
+ "dsh": ">=0.2.2-alpha.2 <0.3.0"
12
+ },
13
+ "dsh": {
14
+ "manifestVersion": 1,
15
+ "kind": "plugin",
16
+ "capabilities": [],
17
+ "labels": []
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ // Vendored verbatim (a generic parser, not the plugin's own dynamic execution).
2
+ export function compile(source) {
3
+ return new Function('return ' + source)()
4
+ }
@@ -49,6 +49,9 @@ Options:
49
49
  --max-files <n> source scan file budget (default: 400)
50
50
  --max-bytes <n> source scan byte budget (default: 2000000)
51
51
  --no-exec skip L1-L3 entirely (reported as not-run/NA, never PASS)
52
+ --strict-vendor DSC-16: do not downgrade eval/new Function in vendored/third-party
53
+ files to WARN (alias: --no-vendor-exempt); the default keeps the
54
+ historical FAIL for first-party code and exempts vendored files only
52
55
  --static-only M1 mode: listing profile, only C-1/C-2/C-3/C-11/C-12/C-13; C-4..C-9 are out of scope
53
56
  --treat-as-plugin run L1-L3 on a bundle's server entry (lib/index.js, index.js, lib/public-entry.js, src/index.ts)
54
57
  --entry-runtime require|server-entry entry scope: require full G0-G3 (default) or accept server-entry proxy (not bundle)
@@ -90,6 +93,7 @@ function parseArgs(argv) {
90
93
  maxFiles: 400,
91
94
  maxBytes: 2_000_000,
92
95
  noExec: false,
96
+ strictVendor: false,
93
97
  staticOnly: false,
94
98
  treatAsPlugin: false,
95
99
  entryRuntime: 'require',
@@ -143,6 +147,8 @@ function parseArgs(argv) {
143
147
  case '--max-bytes': options.maxBytes = Number(value()); break
144
148
  case '--out': options.out = value(); break
145
149
  case '--no-exec': options.noExec = true; break
150
+ case '--strict-vendor': options.strictVendor = true; break
151
+ case '--no-vendor-exempt': options.strictVendor = true; break
146
152
  case '--static-only': options.staticOnly = true; break
147
153
  case '--treat-as-plugin': options.treatAsPlugin = true; break
148
154
  case '--entry-runtime': options.entryRuntime = value(); break
@@ -605,7 +611,7 @@ export async function main(argv = process.argv.slice(2)) {
605
611
  ]
606
612
  const declarationAdjusted = declarationChecks.map(item => (item.result === 'WARN' && ['DSC-11', 'DSC-13'].includes(item.id) ? { ...item, advisory: true } : item))
607
613
  const advisoryChecks = [checkImportTimeAdvisory(sources, entry?.relative, scan)]
608
- const securityChecks = runSecurityChecks({ dir, manifest, sources, entry, kind })
614
+ const securityChecks = runSecurityChecks({ dir, manifest, sources, entry, kind, strictVendor: options.strictVendor })
609
615
 
610
616
  if (options.scope === 'entry' && options.entryRuntime === 'server-entry' && kind !== 'plugin') options.treatAsPlugin = true
611
617
  let runtimeKind = kind
@@ -548,6 +548,158 @@ function functionConstructorExempt(node, ancestors) {
548
548
  return allowsEvalContext(ancestors)
549
549
  }
550
550
 
551
+ // --- vendor-aware C-16.1 exemption -----------------------------------------
552
+ //
553
+ // A package may legitimately ship third-party code verbatim: a `vendor/` tree, a
554
+ // node_modules tree kept in the tarball, or a bundler inlined library (the
555
+ // `//#region node_modules/...` markers esbuild/rolldown emit). A schema/utility
556
+ // library such as `@deepseek-ai/schemastery` uses `new Function("return " + src)`
557
+ // to compile a *declared callback* into a function; that is a library parser,
558
+ // not a malicious payload, and hard-failing every package that bundles it would
559
+ // punish exactly the packages that declare their dependencies honestly.
560
+ //
561
+ // The exemption is deliberately narrow. Only `eval()` / `new Function()` sites
562
+ // are affected (never vm, module._compile, process.binding, dangerous
563
+ // subprocess commands, or base64-obfuscated code), the file must look vendored,
564
+ // the result is WARN (never PASS), and `--strict-vendor` restores FAIL.
565
+ const VENDOR_DIRECTORY = /(?:^|\/)((?:node_modules|vendor|vendored|third[-_]?party|thirdparty|deps))(?:\/|$)/i
566
+ const VENDOR_LIBRARY_NAMES = new Set(['@deepseek-ai/schemastery', 'schemastery', 'ajv', 'lodash'])
567
+ const VENDOR_LIBRARY_SIGNATURES = [
568
+ { name: '@deepseek-ai/schemastery', pattern: /Symbol\.for\(\s*['"]schemastery['"]\s*\)|__schemastery_(?:index|refs)__/ },
569
+ { name: 'ajv', pattern: /\bAjv\.prototype\b|\bclass\s+Ajv\b|\bfunction\s+Ajv\b|\bajv@\d+\.\d+\.\d+/ },
570
+ { name: 'lodash', pattern: /__lodash_hash_undefined__|\bLodashWrapper\b|\blodash@\d+\.\d+\.\d+/ },
571
+ ]
572
+ const BUNDLED_VENDOR_REGION = /^[ \t]*(?:\/\/|\/\*)(?=[^\n]*(?:#region|\bregion\b|\.pnpm[\\/]))[^\n]*?\bnode_modules[\\/](?:\.pnpm[\\/])?((?:@[^/\s+]+[+/])?[^@/\s'"`]+)/i
573
+ const BUNDLED_VENDOR_END = /^[ \t]*(?:\/\/|\/\*)\s*#?endregion\b/i
574
+ const VENDORED_BASENAME = /^(?:schemastery|ajv|lodash)(?:[.-]|$)/i
575
+ const VENDOR_EXEMPT_WHAT = new Set(['eval()', 'new Function()'])
576
+
577
+ /** `@deepseek-ai+schemastery` (the `.pnpm` form) -> `@deepseek-ai/schemastery`. */
578
+ function normalizeVendorPackage(token) {
579
+ if (!token) return null
580
+ const value = String(token).replace(/\\/g, '/')
581
+ if (value.startsWith('@') && !value.includes('/')) return value.replace('+', '/')
582
+ return value
583
+ }
584
+
585
+ function declaredVendorLibraries(manifest) {
586
+ const declared = new Set()
587
+ // devDependencies count: a bundle inlines a library that is only needed at
588
+ // build time, so that is exactly where a bundled dependency is declared.
589
+ for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
590
+ const block = manifest?.[field]
591
+ if (!block || typeof block !== 'object') continue
592
+ for (const name of Object.keys(block)) if (VENDOR_LIBRARY_NAMES.has(name)) declared.add(name)
593
+ }
594
+ return declared
595
+ }
596
+
597
+ /**
598
+ * Line ranges of bundler-emitted `node_modules` regions. One bundle often inlines
599
+ * several libraries (the composer bundle starts with cosmokit, then schemastery),
600
+ * so the evidence for a finding is the region that contains its line, not the
601
+ * first region in the file.
602
+ */
603
+ function bundlerRegionsOf(text) {
604
+ const lines = String(text).split('\n')
605
+ const regions = []
606
+ const open = []
607
+ for (let index = 0; index < lines.length; index += 1) {
608
+ const startMatch = BUNDLED_VENDOR_REGION.exec(lines[index])
609
+ if (startMatch) {
610
+ const library = normalizeVendorPackage(startMatch[1])
611
+ if (library) open.push({ start: index + 1, library })
612
+ continue
613
+ }
614
+ if (BUNDLED_VENDOR_END.test(lines[index]) && open.length > 0) {
615
+ regions.push({ ...open.pop(), end: index + 1 })
616
+ }
617
+ }
618
+ for (const region of open) regions.push({ ...region, end: lines.length })
619
+ return regions
620
+ }
621
+
622
+ /** The region/evidence that applies to one finding line. */
623
+ function vendorEvidenceAt(evidence, line) {
624
+ if (!evidence?.regions) return evidence
625
+ const region = evidence.regions.find(item => line >= item.start && line <= item.end)
626
+ if (!region) return { ...evidence, regions: undefined }
627
+ return {
628
+ kind: evidence.kind,
629
+ library: region.library,
630
+ declared: region.declared,
631
+ reason: `bundled node_modules region for ${region.library}${region.declared ? ' (declared dependency)' : ''}`,
632
+ }
633
+ }
634
+
635
+ /** Own-file vendor evidence, or null. `library` is used only for reporting. */
636
+ function vendorEvidenceOf(relative, text, declared) {
637
+ const normalized = normalizeRelative(relative)
638
+ const pathMatch = VENDOR_DIRECTORY.exec(normalized)
639
+ if (pathMatch) {
640
+ return { kind: 'path', library: 'vendored-path', reason: `vendored path (${pathMatch[0]})` }
641
+ }
642
+ const regions = bundlerRegionsOf(text).map(region => ({ ...region, declared: declared.has(region.library) }))
643
+ if (regions.length > 0) {
644
+ const first = regions[0]
645
+ return {
646
+ kind: 'bundle',
647
+ library: first.library,
648
+ declared: first.declared,
649
+ regions,
650
+ reason: `bundled node_modules region for ${first.library}${first.declared ? ' (declared dependency)' : ''}`,
651
+ }
652
+ }
653
+ for (const signature of VENDOR_LIBRARY_SIGNATURES) {
654
+ if (signature.pattern.test(text)) {
655
+ return { kind: 'library', library: signature.name, declared: declared.has(signature.name), reason: `library fingerprint for ${signature.name}` }
656
+ }
657
+ }
658
+ const basename = path.posix.basename(normalized)
659
+ if (VENDORED_BASENAME.test(basename)) {
660
+ return { kind: 'filename', library: basename.toLowerCase(), reason: `library-shaped file name (${basename})` }
661
+ }
662
+ return null
663
+ }
664
+
665
+ /**
666
+ * Map of normalized relative path -> vendor evidence for every scanned server
667
+ * source. A file outside `src/` also inherits a sibling's strong evidence in the
668
+ * same directory (bundled libraries are often split across chunks); a bare
669
+ * fingerprint is inherited only when the package declares that dependency.
670
+ */
671
+ function vendorFilesFor(sources, manifest) {
672
+ const declared = declaredVendorLibraries(manifest)
673
+ const own = new Map()
674
+ const byDirectory = new Map()
675
+ for (const source of serverSources(sources)) {
676
+ const normalized = normalizeRelative(source.relative)
677
+ const evidence = vendorEvidenceOf(normalized, source.text, declared)
678
+ if (!evidence) continue
679
+ own.set(normalized, evidence)
680
+ const directory = path.posix.dirname(normalized)
681
+ if (!byDirectory.has(directory)) byDirectory.set(directory, [])
682
+ byDirectory.get(directory).push({ file: normalized, evidence })
683
+ }
684
+ const result = new Map(own)
685
+ for (const source of serverSources(sources)) {
686
+ const normalized = normalizeRelative(source.relative)
687
+ if (result.has(normalized)) continue
688
+ if (/(?:^|\/)src(?:\/|$)/.test(normalized)) continue
689
+ const directory = path.posix.dirname(normalized)
690
+ if (directory === '.') continue
691
+ const sibling = (byDirectory.get(directory) ?? []).find(item => item.file !== normalized)
692
+ if (!sibling) continue
693
+ if (sibling.evidence.kind === 'library' && !declared.has(sibling.evidence.library)) continue
694
+ result.set(normalized, {
695
+ kind: 'directory',
696
+ library: sibling.evidence.library,
697
+ reason: `${sibling.evidence.reason} in the same directory (${sibling.file})`,
698
+ })
699
+ }
700
+ return result
701
+ }
702
+
551
703
  /** exec/execSync/spawn/... called directly or through a one-level alias. */
552
704
  function commandExecApiOf(callee, bindings) {
553
705
  if (!callee) return null
@@ -592,7 +744,8 @@ function dangerousCommandLabels(text) {
592
744
  return labels
593
745
  }
594
746
 
595
- export function checkDynamicExecution(manifest, sources, entry, kind = null) {
747
+ export function checkDynamicExecution(manifest, sources, entry, kind = null, options = {}) {
748
+ const strictVendor = options.strictVendor === true
596
749
  if (kind === 'client') {
597
750
  return check({
598
751
  id: 'DSC-16', clause: 'C-16', layer: 'L0', result: 'NA', coverage: 'not-run', advisory: false,
@@ -622,9 +775,11 @@ export function checkDynamicExecution(manifest, sources, entry, kind = null) {
622
775
  const dynamic = []
623
776
  const subprocess = []
624
777
  const fileFacts = new Map()
778
+ const vendorFiles = vendorFilesFor(sources, manifest)
625
779
  for (const relative of closure.visited) {
626
780
  const parsed = parseModule(closure.byRelative.get(relative))
627
781
  if (parsed.error) continue
782
+ const vendor = vendorFiles.get(relative) ?? null
628
783
  let facts = fileFacts.get(relative)
629
784
  if (!facts) {
630
785
  facts = { base64Line: null, evalLike: false }
@@ -649,12 +804,16 @@ export function checkDynamicExecution(manifest, sources, entry, kind = null) {
649
804
  }
650
805
  if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'eval') {
651
806
  facts.evalLike = true
652
- dynamic.push({ file: relative, line: lineOf(node), what: 'eval()', item: 'C-16.1' })
807
+ const line = lineOf(node)
808
+ dynamic.push({ file: relative, line, what: 'eval()', item: 'C-16.1', vendor: vendor ? vendorEvidenceAt(vendor, line) : null })
653
809
  return
654
810
  }
655
811
  if (isFunctionConstructor(node)) {
656
812
  facts.evalLike = true
657
- if (!functionConstructorExempt(node, ancestors)) dynamic.push({ file: relative, line: lineOf(node), what: 'new Function()', item: 'C-16.1' })
813
+ if (!functionConstructorExempt(node, ancestors)) {
814
+ const line = lineOf(node)
815
+ dynamic.push({ file: relative, line, what: 'new Function()', item: 'C-16.1', vendor: vendor ? vendorEvidenceAt(vendor, line) : null })
816
+ }
658
817
  return
659
818
  }
660
819
  if (node.type === 'CallExpression') {
@@ -693,17 +852,35 @@ export function checkDynamicExecution(manifest, sources, entry, kind = null) {
693
852
  obfuscated.push({ file, line: facts.base64Line, what: 'base64-decoded payload in the same file as eval/new Function' })
694
853
  }
695
854
  }
696
- const dynamicEvidence = dynamic.slice(0, 5).map(item => `${item.file}:${item.line}`)
855
+ // Vendor-aware downgrade: only eval()/new Function() in a vendored file, and
856
+ // only when --strict-vendor was not requested. Obfuscated, vm, _compile,
857
+ // process.binding and dangerous subprocess findings are never exempt.
858
+ const vendorExempt = strictVendor
859
+ ? []
860
+ : dynamic.filter(item => item.vendor && item.item === 'C-16.1' && VENDOR_EXEMPT_WHAT.has(item.what))
861
+ const blockingDynamic = dynamic.filter(item => !vendorExempt.includes(item))
862
+ const dynamicEvidence = blockingDynamic.slice(0, 5).map(item => `${item.file}:${item.line}`)
697
863
  const obfuscatedEvidence = obfuscated.slice(0, 5).map(item => `${item.file}:${item.line}`)
864
+ const vendorEvidence = vendorExempt.slice(0, 5).map(item => `${item.file}:${item.line}`)
698
865
  const subprocessEvidence = subprocess.slice(0, 5).map(item => `${item.file}:${item.line}`)
699
- for (const item of dynamic.slice(0, 8)) {
700
- details.push(detail(item.item, 'FAIL', `dynamic execution (code:dynamic): ${item.what} at ${item.file}:${item.line}`, [`${item.file}:${item.line}`]))
866
+ for (const item of blockingDynamic.slice(0, 8)) {
867
+ const vendorNote = item.vendor ? ` [vendor: ${item.vendor.reason}; ${strictVendor ? '--strict-vendor keeps FAIL' : 'not exempt'}]` : ''
868
+ const row = detail(item.item, 'FAIL', `dynamic execution (code:dynamic): ${item.what} at ${item.file}:${item.line}${vendorNote}`, [`${item.file}:${item.line}`])
869
+ if (item.vendor) row.vendor = true
870
+ details.push(row)
871
+ }
872
+ for (const item of vendorExempt.slice(0, 8)) {
873
+ const row = detail('C-16.1', 'WARN', `dynamic execution (code:dynamic): ${item.what} at ${item.file}:${item.line} [vendor: ${item.vendor.reason}; vendor-exempt → WARN, rerun with --strict-vendor to enforce FAIL]`, [`${item.file}:${item.line}`])
874
+ row.vendor = true
875
+ details.push(row)
701
876
  }
702
877
  for (const item of obfuscated.slice(0, 4)) {
703
- details.push(detail('C-16.1', 'FAIL', `dynamic execution (code:obfuscated): ${item.what} at ${item.file}:${item.line}`, [`${item.file}:${item.line}`]))
878
+ const vendorNote = vendorFiles.has(item.file) ? ` [vendor: ${vendorFiles.get(item.file).reason}; obfuscated code is never exempt]` : ''
879
+ details.push(detail('C-16.1', 'FAIL', `dynamic execution (code:obfuscated): ${item.what} at ${item.file}:${item.line}${vendorNote}`, [`${item.file}:${item.line}`]))
704
880
  }
705
881
  for (const item of subprocess.slice(0, 8)) {
706
- details.push(detail('C-16.3', 'WARN', `subprocess capability observed: ${item.what} at ${item.file}:${item.line}`, [`${item.file}:${item.line}`]))
882
+ const vendorNote = vendorFiles.has(item.file) ? ` [vendor: ${vendorFiles.get(item.file).reason}; subprocess findings are never exempt]` : ''
883
+ details.push(detail('C-16.3', 'WARN', `subprocess capability observed: ${item.what} at ${item.file}:${item.line}${vendorNote}`, [`${item.file}:${item.line}`]))
707
884
  }
708
885
  if (closure.packageImports.length > 0) {
709
886
  details.push(detail('C-16.4', 'NA', `not-run: ${closure.packageImports.length} package import(s) are outside the local closure (for example ${closure.packageImports[0].specifier})`, [`${closure.packageImports[0].file}:${closure.packageImports[0].line}`]))
@@ -712,19 +889,24 @@ export function checkDynamicExecution(manifest, sources, entry, kind = null) {
712
889
  details.push(detail('C-16.4', 'ERROR', `not-run: AST parse failed in ${error.file}:${error.line} (${error.message})`, [`${error.file}:${error.line}`]))
713
890
  }
714
891
  const coverage = closure.parseErrors.length > 0 || closure.packageImports.length > 0 || closure.unresolved.length > 0 ? 'partial' : 'full'
892
+ const vendorLibraries = [...new Set(vendorExempt.map(item => item.vendor.library))].join(', ')
715
893
  let result
716
894
  let reason = ''
717
- if (dynamic.length > 0 || obfuscated.length > 0) {
895
+ if (blockingDynamic.length > 0 || obfuscated.length > 0) {
718
896
  result = 'FAIL'
719
- reason = `${dynamic.length} dynamic-execution site(s) in the server entry closure (code:dynamic)`
897
+ reason = `${blockingDynamic.length} dynamic-execution site(s) in the server entry closure (code:dynamic)`
898
+ if (vendorExempt.length > 0) reason += `; ${vendorExempt.length} additional vendor-exempt site(s)`
720
899
  if (obfuscated.length > 0) reason += `; ${obfuscated.length} base64-obfuscated execution clue(s)`
721
900
  if (closure.parseErrors.length > 0) reason += `; ${closure.parseErrors.length} file(s) could not be parsed`
722
901
  } else if (closure.parseErrors.length > 0) {
723
902
  result = 'ERROR'
724
903
  reason = `AST parse failed in ${closure.parseErrors.length} closure file(s); DSC-16 not-run`
725
- } else if (subprocess.length > 0) {
904
+ } else if (vendorExempt.length > 0 || subprocess.length > 0) {
726
905
  result = 'WARN'
727
- reason = `${subprocess.length} subprocess site(s) in the server entry closure`
906
+ const parts = []
907
+ if (vendorExempt.length > 0) parts.push(`${vendorExempt.length} vendor-exempt dynamic-execution site(s) (vendor: ${vendorLibraries}; rerun with --strict-vendor to enforce FAIL)`)
908
+ if (subprocess.length > 0) parts.push(`${subprocess.length} subprocess site(s)`)
909
+ reason = `${parts.join('; ')} in the server entry closure`
728
910
  } else {
729
911
  result = 'PASS'
730
912
  }
@@ -737,7 +919,11 @@ export function checkDynamicExecution(manifest, sources, entry, kind = null) {
737
919
  coverage: result === 'ERROR' ? 'not-run' : coverage,
738
920
  reason,
739
921
  details,
740
- evidence: dynamicEvidence.length > 0 ? dynamicEvidence : obfuscatedEvidence.length > 0 ? obfuscatedEvidence : subprocessEvidence.length > 0 ? subprocessEvidence : [...closure.visited].slice(0, 3),
922
+ evidence: dynamicEvidence.length > 0
923
+ ? dynamicEvidence
924
+ : obfuscatedEvidence.length > 0
925
+ ? obfuscatedEvidence
926
+ : vendorEvidence.length > 0 ? vendorEvidence : subprocessEvidence.length > 0 ? subprocessEvidence : [...closure.visited].slice(0, 3),
741
927
  })
742
928
  }
743
929
 
@@ -1584,7 +1770,7 @@ function unavailable(reason) {
1584
1770
  }
1585
1771
 
1586
1772
  /** Run all eight security checks. Never throws: a failure becomes not-run rows. */
1587
- export function runSecurityChecks({ dir, manifest, sources = [], entry = null, kind = null } = {}) {
1773
+ export function runSecurityChecks({ dir, manifest, sources = [], entry = null, kind = null, strictVendor = false } = {}) {
1588
1774
  if (!manifest) return unavailable('manifest unavailable')
1589
1775
  const checks = []
1590
1776
  const run = (id, factory) => {
@@ -1605,7 +1791,7 @@ export function runSecurityChecks({ dir, manifest, sources = [], entry = null, k
1605
1791
  }
1606
1792
  }
1607
1793
  run('DSC-15', () => checkLifecycleScripts(manifest, dir))
1608
- run('DSC-16', () => checkDynamicExecution(manifest, sources, entry, kind))
1794
+ run('DSC-16', () => checkDynamicExecution(manifest, sources, entry, kind, { strictVendor }))
1609
1795
  run('DSC-17', () => checkSensitiveFileReads(manifest, sources))
1610
1796
  run('DSC-18', () => checkEgressEndpoints(manifest, sources))
1611
1797
  run('DSC-19', () => checkOpaqueArtifacts(dir, sources))
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 1.6.6 — 2026-11-07
2
+
3
+ ### Fixed
4
+
5
+ - DSC-16 vendor-aware:`vendor/`、`node_modules/`、`third_party/`、`deps/` 路径,打包器 `//#region node_modules/...` 区间(按命中行判定库名),`schemastery`/`ajv`/`lodash` 库指纹/库形文件名,或同目录(`src/` 外)强证据,现在把 `eval`/`new Function` 降为 WARN(detail 记 `C-16.1` + `vendor: true`),不再进入 `security.blocking`。
6
+ - 新增 `--strict-vendor`(别名 `--no-vendor-exempt`)恢复 FAIL;默认行为对非 vendor 代码零变化。`vm.*`、`module._compile`、`process.binding`、危险子进程、base64+eval 永不豁免;`package.json` 依赖仅作佐证。
7
+ - `dsh-composer-history@0.8.16`(`lib/index.js:295` 内联 schemastery)由 fail/exit 1 → warn/exit 0;`--strict-vendor` 仍 fail/exit 1。
8
+ - conformance schema 的 `details[]` 新增加性 `vendor` 字段;31 号文 C-16、`CHANGELOG-RULES.md` 同步。
9
+
10
+ ### Verified
11
+
12
+ - `npm test` 301/301;新增 3 个 fixture(bundle / vendor 路径 / 仅声明依赖的诱饵)与 2 个测试。
13
+
14
+ ## 1.6.5 — 2026-11-07
15
+
16
+ - 31 号文 C-17 环境变量枚举的判定句与实现对齐(单独 PASS,同闭包出站才 WARN)。
17
+
1
18
  ## 1.6.4 — 2026-11-07
2
19
 
3
20
  ### Fixed
package/docs/coverage.md CHANGED
@@ -57,7 +57,7 @@ dsh-standards check <package-dir> \
57
57
  | 项 | security scope 判定 | 触发 |
58
58
  |---|---|---|
59
59
  | `DSC-15` 生命周期脚本 | **blocking**(可 FAIL) | 安装期 `curl\|sh`、`base64 -d`、`node -e`、`sh -c`、`powershell -enc`、引用缺失脚本、写 `$HOME`/`/etc` |
60
- | `DSC-16` 动态执行 | **blocking**(可 FAIL) | `eval`/`new Function(非空)`/`vm`/`module._compile`/`process.binding` → FAIL;裸 `child_process` → WARN;静态危险子进程命令 1.6.2 起 FAIL |
60
+ | `DSC-16` 动态执行 | **blocking**(可 FAIL) | `eval`/`new Function(非空)`/`vm`/`module._compile`/`process.binding` → FAIL;裸 `child_process` → WARN;静态危险子进程命令 1.6.2 起 FAIL;1.6.6 起 vendor/第三方文件内的 `eval`/`new Function` → WARN(`--strict-vendor` 恢复 FAIL) |
61
61
  | `DSC-17` 敏感文件 | **blocking**(可 FAIL) | 直接读 `~/.ssh`、`$DSH_HOME` credentials、`id_rsa`、`.aws`、`.npmrc`、`.netrc` 等;`.env` 只 WARN |
62
62
  | `DSC-18` 外联端点 | **advisory**(永不 FAIL) | 非 https、userinfo、公网裸 IP、webhook/paste/ngrok/onion、未披露端点 |
63
63
  | `DSC-19` 混淆/二进制 | **advisory** | 二进制 sha256、超长单行、大块 base64、高熵;只登记不判恶 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-standards",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "DSH plugin standards and conformance checks: ENTRY/FLOW checks plus BOOST guidance. Non-official; no certification or ranking.",
5
5
  "type": "module",
6
6
  "main": "40-checker/src/index.mjs",
@@ -107,7 +107,7 @@
107
107
  | 计入 `total` | **默认否**:`checks[]` 仍是 14,`security` 块单独存在、不计入 `coverage`。**security 是**:`checks[]` 22,`coverage.total=22`、`coverage.mandatory=4`。 |
108
108
  | 默认 `security.scope` | `"advisory"`。8 项照常评估,但任何 `FAIL` 封顶为 `WARN`,不改 `conclusion`/exit;`security.status` 可为 `pass`/`warn`/`incomplete`(`FAIL` 被封顶成 `WARN` 后不会出现 `fail`)。 |
109
109
  | `security.status=pass` | 仅当 **8 项全部** `PASS` 且每项 `coverage=full`(即 `blocking`/`warn`/`advisory`/`partial`/`notRun` 全空)。任一 `WARN`(含 advisory)、`partial`、`NA`/`ERROR`/`not-run` 或缺失项都**不得**记 `pass`;`pass` 只覆盖这 8 项的静态/元数据证据,不是覆盖完整或安全证明。C-21 的传递依赖元数据缺失只记 check 级 `coverage: partial`,因此也不等同 PASS。 |
110
- | `security.status=fail` | **仅 security scope**:`DSC-15`/`DSC-16`/`DSC-17` 任一 FAIL;优先于 `warn`/`incomplete`。`DSC-21` 永不 FAIL;默认 advisory 模式 FAIL 封顶 WARN,不会出现 `fail`。 |
110
+ | `security.status=fail` | **仅 security scope**:`DSC-15`/`DSC-16`/`DSC-17` 任一 FAIL;优先于 `warn`/`incomplete`。`DSC-21` 永不 FAIL;默认 advisory 模式 FAIL 封顶 WARN,不会出现 `fail`。1.6.6 起 `DSC-16` 的 vendor 豁免项记 `WARN`(detail `vendor: true`),不算 FAIL、不进 `security.blocking`;`--strict-vendor` 下恢复为 FAIL。 |
111
111
  | `security.status=warn` | 无 blocking FAIL、无 `NA`/`ERROR`/完整 `not-run`,但存在任一 `WARN`(含 `DSC-21` 或 15/16/17 的 WARN、18/19/20/22 的 advisory WARN)或 `coverage=partial`。 |
112
112
  | `security.status=incomplete` | 8 项中任一结果为 `NA`/`ERROR`/`not-run`,或 8 项有缺失(未产出 `PASS`/`WARN`/`FAIL`);先于 `warn` 判定,但已有 blocking FAIL 时仍是 `fail`。 |
113
113
  | `security.partial[]` | 1.6.x 起为对象数组 `{ "id": "DSC-16", "reason": "..." }`:收 `checks[].coverage === "partial"` 的 security 项,`reason` 取该检查行(或失败 detail)的理由;**不并入** `security.notRun[]`(`notRun` 只收 `NA`/`ERROR`/完整 `not-run`),但**会阻止 `security.status=pass`**。顶层 `coverage.partial` / `buckets.partial` 在 security scope 下统计 `checks[]` 全部 22 项(含这 8 项)。 |
@@ -185,7 +185,7 @@
185
185
  "advisory": false,
186
186
  "docs": "31-DS-C条款.md#c-16-动态执行",
187
187
  "parent": null,
188
- "note": "security scope only; eval/Function/vm/_compile/process.binding can FAIL; bare child_process is WARN"
188
+ "note": "security scope only; eval/Function/vm/_compile/process.binding can FAIL; bare child_process is WARN; 1.6.6 vendor eval/Function is WARN (--strict-vendor restores FAIL)"
189
189
  },
190
190
  {
191
191
  "dsc": "DSC-17",
@@ -513,7 +513,7 @@
513
513
  "C-16.1": {
514
514
  "title": "eval / new Function 属于 code:dynamic",
515
515
  "why": "它们绕过静态审阅,常与解码/混淆载荷组合出现。",
516
- "fix": "不要用 eval/new Function;把需要的行为写成静态函数。空参 new Function(\"\") 探针不判定。",
516
+ "fix": "不要用 eval/new Function;把需要的行为写成静态函数。空参 new Function(\"\") 探针不判定。vendor/第三方文件内的命中只判 WARN,可用 --strict-vendor 复核。",
517
517
  "docs": "docs/security.md#4-files-subprocesses-and-dynamic-execution-dsc-15-dsc-16-dsc-17-dsc-19",
518
518
  "severityHint": "fail"
519
519
  },
@@ -406,6 +406,10 @@
406
406
  "type": "string"
407
407
  },
408
408
  "description": "Optional evidence references; the detail() helper emits [], but a few manually built details (for example the G4 detail) omit the key in 1.3.0."
409
+ },
410
+ "vendor": {
411
+ "type": "boolean",
412
+ "description": "Additive (1.6.6): true when the finding was classified as vendored/third-party code (DSC-16 C-16.1). A vendor finding is WARN by default and FAIL under --strict-vendor."
409
413
  }
410
414
  }
411
415
  },