@feng0531/dsh-code-review 0.29.0 → 0.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/content.mjs +2 -0
- package/src/git-history.mjs +3 -2
- package/src/git.mjs +2 -0
- package/src/project-rules.mjs +2 -0
- package/src/retrieval-scope.mjs +2 -0
- package/src/secret-path.mjs +9 -0
- package/src/svn.mjs +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.29.1
|
|
4
|
+
|
|
5
|
+
- 参考核心selection核实新增凭据路径不可覆盖门禁:.env家族模板例外、.ssh/私钥/包管理凭据纯路径排除。
|
|
6
|
+
- Git改名旧新路径、SVN、历史blob、local context、规则与catalog统一拒绝,不读秘密正文,282测试通过。
|
|
7
|
+
- 继续核心逐文件差距核查;默认复用当前DSH模型不增加独立配置。
|
|
8
|
+
|
|
3
9
|
## 0.29.0
|
|
4
10
|
|
|
5
11
|
- 重建固定源码能力对照任务,区分已读行为/待读核心/功能缺口/安全替代;恢复持续目标96总轮检查点。
|
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
## 当前状态
|
|
6
6
|
|
|
7
|
-
当前代码版本为 0.29.
|
|
7
|
+
当前代码版本为 0.29.1
|
|
8
|
+
|
|
9
|
+
凭据路径硬排除:.env及其后缀(.env.example/.env.sample/.env.template例外)、.ssh目录、SSH私钥及.netrc/_netrc/.npmrc/.pypirc/.dockercfg,大小写无关;显式选择不可绕过,上下文/规则同样拒绝。仅路径策略,不保证普通文件无秘密。
|
|
8
10
|
|
|
9
11
|
检索支持find批准catalog路径字面子串查找,返回来源身份/版本侧/hash;仅导航不证明正文已读,不搜索仓库外路径。当前持续任务见[核心对照任务](CORE-ALIGNMENT-TASKS.md)。
|
|
10
12
|
|
package/package.json
CHANGED
package/src/content.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertNonSecretPath } from './secret-path.mjs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { lstat, realpath, open } from 'node:fs/promises';
|
|
3
4
|
import { createHash } from 'node:crypto';
|
|
@@ -17,6 +18,7 @@ export function decode(bytes) {
|
|
|
17
18
|
}
|
|
18
19
|
export async function readLocal(root, name, { maxFileBytes = 256 * 1024, signal } = {}) {
|
|
19
20
|
relativePath(name);
|
|
21
|
+
assertNonSecretPath(name);
|
|
20
22
|
if (!Number.isSafeInteger(maxFileBytes) || maxFileBytes < 1 || maxFileBytes > 16 * 1024 * 1024) throw new Error('Invalid file size limit');
|
|
21
23
|
signal?.throwIfAborted();
|
|
22
24
|
const canonicalRoot = await realpath(root);
|
package/src/git-history.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSecretPath, assertNonSecretPath } from './secret-path.mjs';
|
|
1
2
|
import {captureProjectRules} from './project-rules.mjs';
|
|
2
3
|
import {contextCandidates} from './context-candidates.mjs';
|
|
3
4
|
import {realpath} from 'node:fs/promises';
|
|
@@ -25,7 +26,7 @@ export async function captureGitHistory(cwd, options={}) {
|
|
|
25
26
|
// Literal, nonrecursive lookups cannot enumerate a supplied directory or wildcard.
|
|
26
27
|
const lookup=async (oid,map,requested)=>{if(!oid)return;const pending=[...new Set(requested)].filter(p=>!map.has(p));for(let i=0;i<pending.length;i++){const paths=pending.slice(i,i+1);paths.forEach(relativePath);const records=utf8(await git(root,['--literal-pathspecs','ls-tree','-z','--full-tree',oid,'--',...paths])).split('\0').filter(Boolean);for(const r of records){const m=/^(\d{6}) (blob|commit|tree) ([a-f0-9]+)\t([\s\S]+)$/.exec(r);if(!m||!paths.includes(m[4]))throw new Error('Invalid historical path lookup');map.set(m[4],{mode:m[1],type:m[2],oid:m[3]});}}};
|
|
27
28
|
if(names.length>maxFiles)throw new Error('Historical change count limit exceeded');if(selectedPaths?.some(p=>!names.includes(p)))throw new Error('Selected path is not a historical change');
|
|
28
|
-
const files=[];for(const name of names){signal?.throwIfAborted();const l=left.get(name),r=right.get(name),item={id:hash(name),path:name,rawStatus:!l?'A':!r?'D':'M',eligibility:'reviewable',properties:[]};files.push(item);if(selectedPaths&&!selectedPaths.includes(name)){item.eligibility='excluded';item.reason='Not explicitly selected';continue;}try{for(const e of [l,r].filter(Boolean))if(e.type!=='blob'||!['100644','100755'].includes(e.mode))throw new Error('Historical link or submodule excluded');const read=async e=>decode(e?await git(root,['cat-file','blob',e.oid],maxFileBytes):Buffer.alloc(0));item.left=await read(l);item.right=await read(r);item.rightExists=!!r;if(l&&r&&item.left.hash===item.right.hash){item.eligibility='excluded';item.reason='Mode-only historical change not analyzed';}}catch(error){signal?.throwIfAborted();item.eligibility='blocked';item.reason=error.message;delete item.left;delete item.right;}if(Buffer.byteLength(JSON.stringify(files))>maxSnapshotBytes)throw new Error('Historical snapshot limit exceeded');}
|
|
29
|
+
const files=[];for(const name of names){signal?.throwIfAborted();const l=left.get(name),r=right.get(name),item={id:hash(name),path:name,rawStatus:!l?'A':!r?'D':'M',eligibility:'reviewable',properties:[]};files.push(item);if(isSecretPath(name)){item.eligibility='excluded';item.reason='Credential path excluded';continue;}if(selectedPaths&&!selectedPaths.includes(name)){item.eligibility='excluded';item.reason='Not explicitly selected';continue;}try{for(const e of [l,r].filter(Boolean))if(e.type!=='blob'||!['100644','100755'].includes(e.mode))throw new Error('Historical link or submodule excluded');const read=async e=>decode(e?await git(root,['cat-file','blob',e.oid],maxFileBytes):Buffer.alloc(0));item.left=await read(l);item.right=await read(r);item.rightExists=!!r;if(l&&r&&item.left.hash===item.right.hash){item.eligibility='excluded';item.reason='Mode-only historical change not analyzed';}}catch(error){signal?.throwIfAborted();item.eligibility='blocked';item.reason=error.message;delete item.left;delete item.right;}if(Buffer.byteLength(JSON.stringify(files))>maxSnapshotBytes)throw new Error('Historical snapshot limit exceeded');}
|
|
29
30
|
const rulePaths=options.rulePaths ?? [];
|
|
30
31
|
const contextPaths=options.contextPaths ?? [], maxContextFiles=options.maxContextFiles ?? 20;
|
|
31
32
|
if(!Array.isArray(contextPaths)||!Number.isSafeInteger(maxContextFiles)||maxContextFiles<1||maxContextFiles>20||contextPaths.length>maxContextFiles)throw new Error('Historical context file limit exceeded');
|
|
@@ -33,7 +34,7 @@ export async function captureGitHistory(cwd, options={}) {
|
|
|
33
34
|
if(!Array.isArray(rulePaths)||rulePaths.length>4||rulePaths.some(p=>contextPaths.includes(p)))throw new Error('Rule paths must be separate from context paths');
|
|
34
35
|
await lookup(target,right,[...contextPaths,...rulePaths]);await lookup(base,left,contextPaths);
|
|
35
36
|
const context=[], regular=e=>e?.type==='blob'&&['100644','100755'].includes(e.mode);
|
|
36
|
-
const captureContext=async name=>{relativePath(name);const changed=files.find(f=>f.path===name);if(changed){if(changed.eligibility!=='reviewable'||changed.rightExists===false)throw new Error('Historical context is excluded blocked or deleted');return {path:name,...changed.right};}const entry=right.get(name);if(!regular(entry))throw new Error('Historical context not a target regular blob');const content=decode(await git(root,['cat-file','blob',entry.oid],maxFileBytes));const previous=left.get(name);return {path:name,...content,revision:target,...(regular(previous)?{oldText:decode(await git(root,['cat-file','blob',previous.oid],maxFileBytes)).text,oldRevision:base}:{})};};
|
|
37
|
+
const captureContext=async name=>{relativePath(name);assertNonSecretPath(name);const changed=files.find(f=>f.path===name);if(changed){if(changed.eligibility!=='reviewable'||changed.rightExists===false)throw new Error('Historical context is excluded blocked or deleted');return {path:name,...changed.right};}const entry=right.get(name);if(!regular(entry))throw new Error('Historical context not a target regular blob');const content=decode(await git(root,['cat-file','blob',entry.oid],maxFileBytes));const previous=left.get(name);return {path:name,...content,revision:target,...(regular(previous)?{oldText:decode(await git(root,['cat-file','blob',previous.oid],maxFileBytes)).text,oldRevision:base}:{})};};
|
|
37
38
|
for(const name of [...new Set(contextPaths)].sort())context.push(await captureContext(name));
|
|
38
39
|
const rules=await captureProjectRules(root,rulePaths,{signal,files,read:async (_root,name,{maxFileBytes:limit})=>{const entry=right.get(name);if(!regular(entry))throw new Error('Historical rule not a target regular blob');return decode(await git(root,['cat-file','blob',entry.oid],limit));}});
|
|
39
40
|
let autoContext;
|
package/src/git.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSecretPath } from './secret-path.mjs';
|
|
1
2
|
import { realpath } from 'node:fs/promises';
|
|
2
3
|
import { run, checked } from './process.mjs';
|
|
3
4
|
import { hash, decode, readLocal, relativePath } from './content.mjs';
|
|
@@ -46,6 +47,7 @@ export async function captureGit(cwd, options = {}) {
|
|
|
46
47
|
signal?.throwIfAborted();
|
|
47
48
|
const item = { ...change, id: hash(change.path), eligibility: 'reviewable', properties: [] };
|
|
48
49
|
files.push(item);
|
|
50
|
+
if (isSecretPath(change.path) || isSecretPath(change.oldPath)) { item.eligibility='excluded'; item.reason='Credential path excluded'; continue; }
|
|
49
51
|
if ((selectedPaths && !selectedPaths.includes(change.path)) || (change.rawStatus === '??' && !selectedPaths?.includes(change.path))) {
|
|
50
52
|
item.eligibility = 'excluded'; item.reason = 'Not explicitly selected'; continue;
|
|
51
53
|
}
|
package/src/project-rules.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertNonSecretPath } from './secret-path.mjs';
|
|
1
2
|
import { readLocal, relativePath } from './content.mjs';
|
|
2
3
|
|
|
3
4
|
// Explicit paths only. This helper neither authorizes sending nor follows includes.
|
|
@@ -6,6 +7,7 @@ export async function captureProjectRules(root, paths, { signal, files = [], rea
|
|
|
6
7
|
const seen = new Set();
|
|
7
8
|
for (const name of paths) {
|
|
8
9
|
relativePath(name);
|
|
10
|
+
assertNonSecretPath(name);
|
|
9
11
|
if (!/[.](md|txt)$/i.test(name)) throw new Error('Rules must be Markdown or text');
|
|
10
12
|
if (seen.has(name)) throw new Error('Duplicate rule path');
|
|
11
13
|
seen.add(name);
|
package/src/retrieval-scope.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertNonSecretPath } from './secret-path.mjs';
|
|
1
2
|
import { createSnapshotReader } from './snapshot-reader.mjs';
|
|
2
3
|
|
|
3
4
|
// Call only after authorization of this exact snapshot; this function grants nothing.
|
|
@@ -6,6 +7,7 @@ export function createRetrievalScope(snapshot, options) {
|
|
|
6
7
|
const entries = [], catalog = [], paths = new Map(), identities = new Set();
|
|
7
8
|
const add = (path, side, text, fileId) => {
|
|
8
9
|
if (typeof text !== 'string') throw new Error('Missing retrieval text');
|
|
10
|
+
assertNonSecretPath(path);
|
|
9
11
|
const id = 's' + (entries.length + 1);
|
|
10
12
|
entries.push({ id, text, path, side });
|
|
11
13
|
catalog.push({ id, path, side, ...(fileId ? { fileId } : {}) });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Pure path policy; never inspect credential contents or infer safe contents.
|
|
2
|
+
export function isSecretPath(value) {
|
|
3
|
+
if(typeof value!=='string')return false;
|
|
4
|
+
const parts=value.replaceAll('\\','/').toLowerCase().split('/'),base=parts.at(-1);
|
|
5
|
+
if(parts.includes('.ssh'))return true;
|
|
6
|
+
if(['id_rsa','id_dsa','id_ecdsa','id_ed25519','.netrc','_netrc','.npmrc','.pypirc','.dockercfg'].includes(base))return true;
|
|
7
|
+
return (base==='.env'||base.startsWith('.env.'))&&!['.env.example','.env.sample','.env.template'].includes(base);
|
|
8
|
+
}
|
|
9
|
+
export function assertNonSecretPath(path){if(isSecretPath(path))throw new Error('Credential path excluded');}
|
package/src/svn.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSecretPath } from './secret-path.mjs';
|
|
1
2
|
import { realpath, lstat } from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -39,6 +40,7 @@ export async function captureSvn(cwd, options = {}) {
|
|
|
39
40
|
const state = entry['wc-status'], status = state['@_item'];
|
|
40
41
|
const item = { id: hash(name), path: name, rawStatus: status, baseRevision: state['@_revision'], eligibility: 'reviewable', properties: [] };
|
|
41
42
|
files.push(item);
|
|
43
|
+
if (isSecretPath(name)) { item.eligibility='excluded'; item.reason='Credential path excluded'; continue; }
|
|
42
44
|
if ((selectedPaths && !selectedPaths.includes(name)) || (status === 'unversioned' && !selectedPaths?.includes(name))) {
|
|
43
45
|
item.eligibility = 'excluded'; item.reason = 'Not explicitly selected'; continue;
|
|
44
46
|
}
|