@lornatang/dsh-codex-security 0.1.10 → 0.1.12
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 +14 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/constants.js +1 -2
- package/lib/deep-coordinator.js +67 -3
- package/lib/deep-worker.js +4 -1
- package/lib/git.js +0 -21
- package/lib/index.js +0 -1
- package/lib/routes.js +0 -5
- package/lib/service.js +28 -27
- package/lib/store.js +36 -14
- package/lib/target.js +48 -6
- package/lib/tools.js +47 -1
- package/lib/types/constants.d.ts +1 -2
- package/lib/types/deep-coordinator.d.ts +10 -0
- package/lib/types/git.d.ts +0 -3
- package/lib/types/index.d.ts +1 -2
- package/lib/types/routes.d.ts +0 -2
- package/lib/types/service.d.ts +0 -1
- package/lib/types/store.d.ts +5 -1
- package/lib/types/target.d.ts +10 -0
- package/lib/types/util.d.ts +0 -5
- package/lib/util.js +1 -45
- package/package.json +1 -1
- package/references/core-scan.md +1 -1
- package/references/final-report.md +1 -1
- package/references/scan-contract.md +1 -1
- package/schemas/tools/scan-draft.schema.json +0 -766
package/lib/types/routes.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import type { SecurityService } from './service.js';
|
|
3
3
|
import type { PluginContext } from './types.js';
|
|
4
|
-
declare function scanIdFromPath(pathname: string): string | undefined;
|
|
5
4
|
export declare function handleRequest(service: SecurityService, req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
6
5
|
export declare function bindRoutes(ctx: PluginContext, service: SecurityService): () => void;
|
|
7
|
-
export { scanIdFromPath };
|
package/lib/types/service.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export interface SecurityServiceOptions {
|
|
|
12
12
|
export declare class SecurityService {
|
|
13
13
|
readonly store: ScanStore;
|
|
14
14
|
readonly config: Config;
|
|
15
|
-
private readonly ctx;
|
|
16
15
|
private readonly scanLocks;
|
|
17
16
|
private readonly managedInvocations;
|
|
18
17
|
constructor(ctx: PluginContext, options?: SecurityServiceOptions);
|
package/lib/types/store.d.ts
CHANGED
|
@@ -27,11 +27,15 @@ export declare function summarize(record: ScanRecord): ScanSummary;
|
|
|
27
27
|
export declare class ScanStore {
|
|
28
28
|
readonly stateDir: string;
|
|
29
29
|
private queue;
|
|
30
|
+
private indexCache?;
|
|
31
|
+
private indexStamp?;
|
|
30
32
|
constructor(stateDir: string);
|
|
31
33
|
private get indexPath();
|
|
32
34
|
scanDir(record: Pick<ScanRecord, 'repoKey' | 'scanId'>): string;
|
|
33
35
|
init(): Promise<void>;
|
|
34
36
|
private serialize;
|
|
37
|
+
/** Cheap identity of index.json so a changed on-disk index invalidates the cache. */
|
|
38
|
+
private indexFileStamp;
|
|
35
39
|
loadIndex(): Promise<ScanIndex>;
|
|
36
40
|
private rebuildIndex;
|
|
37
41
|
saveIndex(index: ScanIndex): Promise<void>;
|
|
@@ -59,7 +63,7 @@ export declare class ScanStore {
|
|
|
59
63
|
bytes: number;
|
|
60
64
|
truncated: boolean;
|
|
61
65
|
}>;
|
|
62
|
-
listArtifacts(scanId: string): Promise<{
|
|
66
|
+
listArtifacts(scanId: string, knownDir?: string): Promise<{
|
|
63
67
|
path: string;
|
|
64
68
|
bytes: number;
|
|
65
69
|
}[]>;
|
package/lib/types/target.d.ts
CHANGED
|
@@ -35,3 +35,13 @@ export declare function resolveDiff(rootPath: string, options: {
|
|
|
35
35
|
}): Promise<DiffSnapshot>;
|
|
36
36
|
/** Read one source line for anchor derivation without trusting it as instructions. */
|
|
37
37
|
export declare function readEvidenceLine(rootPath: string, path: string, line: number, maxBytes: number): Promise<string | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Read many evidence lines with one hardened open per source file. The old
|
|
40
|
+
* per-line reader repeated the lstat/open/realpath verification and re-read the
|
|
41
|
+
* file prefix for every requested line, so a draft citing several lines of one
|
|
42
|
+
* file paid that cost repeatedly.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readEvidenceLines(rootPath: string, requests: {
|
|
45
|
+
path: string;
|
|
46
|
+
line: number;
|
|
47
|
+
}[], maxBytes: number): Promise<Map<string, string>>;
|
package/lib/types/util.d.ts
CHANGED
|
@@ -3,18 +3,14 @@ export declare function sha256(value: string | Uint8Array): string;
|
|
|
3
3
|
export declare function stableTargetId(rootPath: string): string;
|
|
4
4
|
export declare function nowIso(): string;
|
|
5
5
|
export declare function newId(prefix: string, hexChars?: number): string;
|
|
6
|
-
export declare function shortId(value: string, length?: number): string;
|
|
7
6
|
export declare function ensureDir(path: string): Promise<void>;
|
|
8
7
|
export declare function writeFileAtomic(path: string, data: string | Uint8Array): Promise<void>;
|
|
9
|
-
/** Publish a complete file without ever replacing an existing destination. */
|
|
10
|
-
export declare function writeFileExclusive(path: string, data: string | Uint8Array): Promise<void>;
|
|
11
8
|
/** Resolve symlinked ancestors even when the final path does not yet exist. */
|
|
12
9
|
export declare function canonicalProspectivePath(path: string): Promise<string>;
|
|
13
10
|
export declare function writeJsonAtomic(path: string, value: unknown): Promise<void>;
|
|
14
11
|
export declare function readJson<T>(path: string): Promise<T | undefined>;
|
|
15
12
|
export declare function readText(path: string, limit?: number): Promise<string | undefined>;
|
|
16
13
|
export declare function readFullText(path: string): Promise<string | undefined>;
|
|
17
|
-
export declare function posixRelative(root: string, path: string): string;
|
|
18
14
|
/** Reject absolute paths, drive letters and .. segments; return a normalized posix relative path. */
|
|
19
15
|
export declare function sanitizeRelative(input: string): string;
|
|
20
16
|
export declare function isWithin(parent: string, child: string): boolean;
|
|
@@ -29,7 +25,6 @@ export declare function languageOf(path: string): string;
|
|
|
29
25
|
export declare function slugify(value: string, max?: number): string;
|
|
30
26
|
export declare function compareSeverity(a: string, b: string): number;
|
|
31
27
|
export declare function truncate(value: string, max: number): string;
|
|
32
|
-
export declare function formatBytes(value: number): string;
|
|
33
28
|
export declare function listFiles(root: string, options: {
|
|
34
29
|
maxFiles: number;
|
|
35
30
|
exclude: string[];
|
package/lib/util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdir, open, readFile, readdir, realpath, rename, rm } from 'node:fs/promises';
|
|
3
3
|
import { basename, dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
5
|
export function sha256(value) {
|
|
@@ -15,9 +15,6 @@ export function nowIso() {
|
|
|
15
15
|
export function newId(prefix, hexChars = 24) {
|
|
16
16
|
return prefix + randomBytes(Math.ceil(hexChars / 2)).toString('hex').slice(0, hexChars);
|
|
17
17
|
}
|
|
18
|
-
export function shortId(value, length = 8) {
|
|
19
|
-
return value.slice(0, length);
|
|
20
|
-
}
|
|
21
18
|
export async function ensureDir(path) {
|
|
22
19
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
23
20
|
}
|
|
@@ -53,37 +50,6 @@ export async function writeFileAtomic(path, data) {
|
|
|
53
50
|
throw error;
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
/** Publish a complete file without ever replacing an existing destination. */
|
|
57
|
-
export async function writeFileExclusive(path, data) {
|
|
58
|
-
const tmp = join(dirname(path), '.' + process.pid + '.' + randomBytes(12).toString('hex') + '.tmp');
|
|
59
|
-
const handle = await open(tmp, 'wx', 0o600);
|
|
60
|
-
try {
|
|
61
|
-
try {
|
|
62
|
-
await handle.writeFile(data);
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
await handle.close();
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
await link(tmp, path);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
// Some writable filesystems do not support hard links.
|
|
72
|
-
if (!['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'ENOSYS'].includes(error.code ?? ''))
|
|
73
|
-
throw error;
|
|
74
|
-
const destination = await open(path, 'wx', 0o600);
|
|
75
|
-
try {
|
|
76
|
-
await destination.writeFile(data);
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
await destination.close();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
await rm(tmp, { force: true });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
53
|
/** Resolve symlinked ancestors even when the final path does not yet exist. */
|
|
88
54
|
export async function canonicalProspectivePath(path) {
|
|
89
55
|
let current = resolve(path);
|
|
@@ -146,9 +112,6 @@ export async function readFullText(path) {
|
|
|
146
112
|
throw error;
|
|
147
113
|
}
|
|
148
114
|
}
|
|
149
|
-
export function posixRelative(root, path) {
|
|
150
|
-
return relative(root, path).split(sep).join('/');
|
|
151
|
-
}
|
|
152
115
|
/** Reject absolute paths, drive letters and .. segments; return a normalized posix relative path. */
|
|
153
116
|
export function sanitizeRelative(input) {
|
|
154
117
|
if (typeof input !== 'string' || input.length === 0)
|
|
@@ -373,13 +336,6 @@ export function compareSeverity(a, b) {
|
|
|
373
336
|
export function truncate(value, max) {
|
|
374
337
|
return value.length <= max ? value : value.slice(0, Math.max(0, max - 1)) + '\u2026';
|
|
375
338
|
}
|
|
376
|
-
export function formatBytes(value) {
|
|
377
|
-
if (value < 1024)
|
|
378
|
-
return value + ' B';
|
|
379
|
-
if (value < 1024 * 1024)
|
|
380
|
-
return (value / 1024).toFixed(1) + ' KB';
|
|
381
|
-
return (value / (1024 * 1024)).toFixed(1) + ' MB';
|
|
382
|
-
}
|
|
383
339
|
export async function listFiles(root, options) {
|
|
384
340
|
const files = [];
|
|
385
341
|
const excluded = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lornatang/dsh-codex-security",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Agent-native security review workbench for DeepSeek Harness, modeled on OpenAI codex-security: sealed scans, findings contract, deep-scan orchestration and SARIF/JSON export.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/references/core-scan.md
CHANGED
|
@@ -13,7 +13,7 @@ Include any caller-supplied rendered investigation time allowance unchanged amon
|
|
|
13
13
|
5. Delegate independent packet groups when parallel review is useful, within the caller's worker allowance. Point each worker to its readable copy of [the investigator brief](focused-investigator.md) and send its packets with the same authorized source and security context. For packets you handle in the parent, read the investigator brief and follow its investigation instructions yourself. Choose assignments by complexity and shared code rather than a fixed worker or file count. Supporting code may explain an in-scope finding, but its affected entry point, control, or operation must remain in scope.
|
|
14
14
|
6. Preserve returned candidates and counterevidence through the bound `record_codex_security_scan_draft` tool when available, before combining or validating them. Use `complete: false`, stable `candidateId` values, and `reviewState.deferred` entries with a reason and the original payload under `candidate`. Checkpoint validation decisions: accepted findings retain `provenance.candidateId`; rejections retain the candidate identity, original evidence, and source-backed counterevidence on a `rejected` coverage surface. Record reviewed surfaces, exclusions, and unresolved questions without creating extra receipts or claiming exhaustive coverage. Group observations only when they share the broken control and effective remediation, preserving affected routes, operations, and locations; a shared CWE alone is not a reason to merge.
|
|
15
15
|
7. Follow the caller’s validation handoff if supplied. Otherwise [validate each distinct candidate](validate-scan-findings.md) against the source.
|
|
16
|
-
8. Assemble `scope`, `threatModel`, `findings`, and `reviewState` following `final-report.md
|
|
16
|
+
8. Assemble `scope`, `threatModel`, `findings`, and `reviewState` following `final-report.md`. Follow `finding-detail-fields.md` for rich evidence and narrative fields. Preserve genuine findings, source provenance, supplied assumptions, exclusions, pending work, and uncertainty. Examples under `examples/completed-scan/` illustrate shape, not values to copy.
|
|
17
17
|
|
|
18
18
|
Keep discovery, validation, and attack-path reasoning within this one self-contained audit; do not invoke separate phase skills or add ranking phases, per-file ledgers, separate phase worker pools, or receipt files.
|
|
19
19
|
|
|
@@ -17,7 +17,7 @@ Completion validates existing artifacts; it does not perform missing phases or c
|
|
|
17
17
|
|
|
18
18
|
## Finding Semantics
|
|
19
19
|
|
|
20
|
-
Use `
|
|
20
|
+
Use `finding-detail-fields.md` for rich fields. Supply:
|
|
21
21
|
|
|
22
22
|
- An evidence-supported lowercase vulnerability-family `ruleId`, `taxonomy.category`, known `taxonomy.cwe` values (or `[]`), and genuine `provenance.source`. Use `local_plugin` only for findings this plugin discovered; preserve worker/source provenance and candidate identity.
|
|
23
23
|
- Verified source locations, including the broken control or sink and materially affected entry points or concrete implementations. Preserve independently vulnerable instances. Group observations only when they share the broken control and remediation, not merely a CWE.
|
|
@@ -183,7 +183,7 @@ These fields are optional for compatibility with existing v1 canonical artifacts
|
|
|
183
183
|
|
|
184
184
|
## Schemas
|
|
185
185
|
|
|
186
|
-
New completed findings must match the [
|
|
186
|
+
New completed findings must match the [findings schema](../schemas/findings.schema.json). Finalization rejects legacy field aliases, malformed optional details, and invalid semantic slugs instead of repairing them. Historical sealed reports are validated through an in-memory compatibility adapter; their saved bytes remain unchanged. Stopped-scan recovery still salvages saved evidence.
|
|
187
187
|
|
|
188
188
|
- [Scan manifest schema](../schemas/scan-manifest.schema.json)
|
|
189
189
|
- [Findings schema](../schemas/findings.schema.json)
|