@iyowei/rim 0.0.0-stage → 0.0.1-stage
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 +1 -0
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/README.zh-CN.md +75 -0
- package/dist/baseline.d.ts +47 -0
- package/dist/bridge-command.d.ts +25 -0
- package/dist/bridge.d.ts +18 -0
- package/dist/cdp.d.ts +41 -0
- package/dist/chrome.d.ts +51 -0
- package/dist/config-validate-sections.d.ts +18 -0
- package/dist/config-validate.d.ts +4 -0
- package/dist/config.d.ts +27 -0
- package/dist/doctor.d.ts +15 -0
- package/dist/errors.d.ts +10 -0
- package/dist/gate-pipeline.d.ts +34 -0
- package/dist/gate.d.ts +3 -0
- package/dist/html-report.d.ts +14 -0
- package/dist/html-scan.d.ts +32 -0
- package/dist/http-gate.d.ts +11 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +10234 -0
- package/dist/lighthouse-extract.d.ts +20 -0
- package/dist/lighthouse-gate.d.ts +35 -0
- package/dist/locale.d.ts +14 -0
- package/dist/manifest.json +8 -0
- package/dist/probe-h2h3.d.ts +39 -0
- package/dist/probe-load-adapters.d.ts +38 -0
- package/dist/probe-load-builtin.d.ts +16 -0
- package/dist/probe-load-h2.d.ts +41 -0
- package/dist/probe-load.d.ts +28 -0
- package/dist/probe-perf.d.ts +36 -0
- package/dist/probe-proto-checks.d.ts +58 -0
- package/dist/probe-proto-helpers.d.ts +77 -0
- package/dist/probe-proto.d.ts +55 -0
- package/dist/probe-quality-adapters.d.ts +42 -0
- package/dist/probe-quality-axe.d.ts +57 -0
- package/dist/probe-quality-link-eval.d.ts +46 -0
- package/dist/probe-quality-links.d.ts +23 -0
- package/dist/probe-quality.d.ts +53 -0
- package/dist/probe-sec-csp.d.ts +21 -0
- package/dist/probe-sec-testssl.d.ts +22 -0
- package/dist/probe-sec-tls-eval.d.ts +34 -0
- package/dist/probe-sec-tls.d.ts +18 -0
- package/dist/probe-sec.d.ts +42 -0
- package/dist/runtime.d.ts +45 -0
- package/dist/security-ip.d.ts +42 -0
- package/dist/security.d.ts +43 -0
- package/dist/smoke-gate.d.ts +14 -0
- package/dist/static-server.d.ts +19 -0
- package/dist/types-config.d.ts +339 -0
- package/dist/types.d.ts +352 -0
- package/dist/verdict-lighthouse.d.ts +14 -0
- package/dist/verdict.d.ts +21 -0
- package/dist/waivers.d.ts +10 -0
- package/package.json +66 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { type LinkCheckRecord } from './probe-quality-links.js';
|
|
3
|
+
import type { BuiltinAxeAuditResult, ChromeSession, ProbeResult, QualityProbeConfig, SmokeGateConfig, SmokeGateResult, WaiverRule } from './types.js';
|
|
4
|
+
export { type LinkCheckRecord };
|
|
5
|
+
export interface QualityProbeOutput {
|
|
6
|
+
readonly probe: ProbeResult;
|
|
7
|
+
readonly smoke: SmokeGateResult;
|
|
8
|
+
}
|
|
9
|
+
/** 运行统一 `quality` 探针 (内置 CDP 冒烟 + 死链/外链/锚点 + 随包 `axe-core` + 可选外部覆盖) */
|
|
10
|
+
export declare function runQualityProbe(options: {
|
|
11
|
+
readonly targetUrl: string;
|
|
12
|
+
readonly allowLoopback: boolean;
|
|
13
|
+
readonly html?: string;
|
|
14
|
+
readonly linkHeaders?: readonly string[];
|
|
15
|
+
readonly chromePath: string | null;
|
|
16
|
+
readonly smokeConfig?: SmokeGateConfig;
|
|
17
|
+
readonly qualityConfig?: QualityProbeConfig;
|
|
18
|
+
readonly runSmoke?: boolean;
|
|
19
|
+
readonly checkExternalLinks?: boolean;
|
|
20
|
+
readonly checkAxe?: boolean;
|
|
21
|
+
readonly runOptionalAdapters?: boolean;
|
|
22
|
+
readonly waivers?: readonly WaiverRule[];
|
|
23
|
+
readonly cwd: string;
|
|
24
|
+
readonly timeoutMs: number;
|
|
25
|
+
readonly locale: RimLocale;
|
|
26
|
+
readonly signal?: AbortSignal;
|
|
27
|
+
readonly fetchFn?: typeof fetch;
|
|
28
|
+
readonly launchChromeFn?: (input: {
|
|
29
|
+
chromePath: string;
|
|
30
|
+
coldGpu: boolean;
|
|
31
|
+
timeoutMs: number;
|
|
32
|
+
locale: RimLocale;
|
|
33
|
+
extraFlags?: readonly string[];
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}) => Promise<ChromeSession>;
|
|
36
|
+
readonly runSmokeFn?: (input: {
|
|
37
|
+
targetUrl: string;
|
|
38
|
+
chromePath: string;
|
|
39
|
+
config: SmokeGateConfig;
|
|
40
|
+
cwd?: string;
|
|
41
|
+
timeoutMs: number;
|
|
42
|
+
locale: RimLocale;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}) => Promise<SmokeGateResult>;
|
|
45
|
+
readonly axeRunner?: (input: {
|
|
46
|
+
targetUrl: string;
|
|
47
|
+
axeTags?: readonly string[];
|
|
48
|
+
timeoutMs: number;
|
|
49
|
+
locale: RimLocale;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}) => Promise<BuiltinAxeAuditResult>;
|
|
52
|
+
readonly resolveAdapterBin?: (names: readonly string[]) => string | null;
|
|
53
|
+
}): Promise<QualityProbeOutput>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sec` 探针 CSP3 零正则解析与策略审计子模块 (`probe-sec-csp.ts`)。
|
|
3
|
+
* - 支持单策略与 RFC/CSP3 逗号分隔多策略交集语义 (兼容 CDN + 源站下发多条 CSP 头);
|
|
4
|
+
* - 同名指令首条生效, 独立校验 `script-src` 与 `script-src-elem` 防止互相掩盖 `'unsafe-inline'`;
|
|
5
|
+
* - 无 `script-src` 且无 `default-src` 时发出告警而非假绿。
|
|
6
|
+
*/
|
|
7
|
+
import { type RimLocale } from './locale.js';
|
|
8
|
+
import type { ProbeFinding } from './types.js';
|
|
9
|
+
export interface ParsedCsp {
|
|
10
|
+
readonly raw: string;
|
|
11
|
+
readonly directives: Readonly<Record<string, readonly string[]>>;
|
|
12
|
+
}
|
|
13
|
+
/** 严格按 CSP3 规范解析多条逗号分隔策略 (单策略零额外切分快路径) */
|
|
14
|
+
export declare function parseCspList(rawHeader: string): ParsedCsp[];
|
|
15
|
+
/** 严格按 CSP3 规范解析策略串 (同名指令首条生效, 零正则扫描快路径) */
|
|
16
|
+
export declare function parseCsp(rawHeader: string): ParsedCsp;
|
|
17
|
+
/** 审计单份或多份逗号分隔响应头中的 CSP3 规则 (严格遵循多策略交集语义) */
|
|
18
|
+
export declare function auditCspHeader(rawCsp: string | undefined, locale: RimLocale, required: boolean): {
|
|
19
|
+
parsed: ParsedCsp | null;
|
|
20
|
+
findings: ProbeFinding[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { ProbeFinding } from './types.js';
|
|
3
|
+
export interface TestsslSummary {
|
|
4
|
+
readonly status: 'PASS' | 'WARN' | 'FAIL' | 'SKIP';
|
|
5
|
+
readonly binPath?: string;
|
|
6
|
+
readonly tls12?: boolean;
|
|
7
|
+
readonly tls13?: boolean;
|
|
8
|
+
readonly earlyData?: string;
|
|
9
|
+
readonly certDaysRemaining?: number | null;
|
|
10
|
+
readonly vulnerableItems?: readonly string[];
|
|
11
|
+
readonly reason?: string;
|
|
12
|
+
}
|
|
13
|
+
/** 将外部 `testssl.sh` 审计摘要转换为统一 `ProbeFinding` 条目 */
|
|
14
|
+
export declare function appendTestsslFindings(testssl: TestsslSummary, locale: RimLocale, findings: ProbeFinding[]): void;
|
|
15
|
+
/** 若本机绝对 PATH 存在 `testssl.sh`, 则对 HTTPS 目标运行深度 TLS 审计, 否则优雅 SKIP */
|
|
16
|
+
export declare function runOptionalTestssl(options: {
|
|
17
|
+
readonly targetUrl: string;
|
|
18
|
+
readonly timeoutMs: number;
|
|
19
|
+
readonly locale: RimLocale;
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
readonly resolveAdapterBin?: (names: readonly string[]) => string | null;
|
|
22
|
+
}): Promise<TestsslSummary>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置 TLS 体检纯函数裁定与证书摘要提取模块 (`probe-sec-tls-eval.ts`)。
|
|
3
|
+
* 覆盖弱加密套件判定、弱公钥长度判定、协议矩阵错误分类、证书链防循环解析与 ProbeFinding 构造。
|
|
4
|
+
*/
|
|
5
|
+
import type { DetailedPeerCertificate } from 'node:tls';
|
|
6
|
+
import { type RimLocale } from './locale.js';
|
|
7
|
+
import type { BuiltinTlsAuditResult, ProbeFinding, TlsCertSummary, TlsProtocolProbeState } from './types.js';
|
|
8
|
+
/** 判断协商的 TLS 加密套件是否属于已知弱算法 (纯函数) */
|
|
9
|
+
export declare function isWeakTlsCipher(cipherName: string | null | undefined): boolean;
|
|
10
|
+
/** 判断证书公钥算法与长度是否低于安全底线 (RSA < 2048 或 EC < 224, 纯函数) */
|
|
11
|
+
export declare function isWeakTlsKey(keyType: 'RSA' | 'EC' | null, keyBits: number | null): boolean;
|
|
12
|
+
/** 区分协议探测失败原因是客户端 OpenSSL 禁用、服务端显式拒收还是网络异常 (纯函数) */
|
|
13
|
+
export declare function classifyTlsProbeError(err: unknown): 'rejected' | 'client-unsupported' | 'error';
|
|
14
|
+
/** 从 Node/Bun `getPeerCertificate(true)` 提取证书有效期、公钥强度与无环证书链长度 */
|
|
15
|
+
export declare function summarizePeerCert(rawCert: DetailedPeerCertificate | Record<string, never>, authorized: boolean, authorizationError: string | null, nowMs: number): TlsCertSummary | undefined;
|
|
16
|
+
/** 根据 TLS 协议矩阵、证书状态与加密强度纯函数裁定 PASS/WARN/FAIL */
|
|
17
|
+
export declare function evaluateTlsAuditResult(input: {
|
|
18
|
+
readonly tls13: TlsProtocolProbeState;
|
|
19
|
+
readonly tls12: TlsProtocolProbeState;
|
|
20
|
+
readonly tls11: TlsProtocolProbeState;
|
|
21
|
+
readonly tls10: TlsProtocolProbeState;
|
|
22
|
+
readonly negotiatedCipher?: string | null;
|
|
23
|
+
readonly cert?: TlsCertSummary;
|
|
24
|
+
readonly minCertDays?: number;
|
|
25
|
+
readonly locale?: RimLocale;
|
|
26
|
+
}): {
|
|
27
|
+
readonly status: 'PASS' | 'WARN' | 'FAIL';
|
|
28
|
+
readonly weakCipher: boolean;
|
|
29
|
+
readonly weakKey: boolean;
|
|
30
|
+
readonly vulnerableItems: readonly string[];
|
|
31
|
+
readonly warnings: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
/** 将内置 TLS 审计结果映射为可豁免的颗粒度 `ProbeFinding[]` */
|
|
34
|
+
export declare function appendBuiltinTlsFindings(tls: BuiltinTlsAuditResult, locale: RimLocale, findings: ProbeFinding[]): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { appendBuiltinTlsFindings, classifyTlsProbeError, evaluateTlsAuditResult, isWeakTlsCipher, isWeakTlsKey } from './probe-sec-tls-eval.js';
|
|
3
|
+
import type { BuiltinTlsAuditResult, TlsCertSummary, TlsProtocolProbeState } from './types.js';
|
|
4
|
+
export { type BuiltinTlsAuditResult, type TlsCertSummary, type TlsProtocolProbeState, appendBuiltinTlsFindings, classifyTlsProbeError, evaluateTlsAuditResult, isWeakTlsCipher, isWeakTlsKey, };
|
|
5
|
+
/** 执行内置零外依原生 `node:tls` 深度 TLS 体检 (SSRF IP 钉选 + 协议矩阵 + 证书链与有效期) */
|
|
6
|
+
export declare function runBuiltinTlsAudit(options: {
|
|
7
|
+
readonly targetUrl: string;
|
|
8
|
+
readonly allowLoopback: boolean;
|
|
9
|
+
readonly minCertDays?: number;
|
|
10
|
+
readonly ca?: string | Buffer;
|
|
11
|
+
readonly timeoutMs: number;
|
|
12
|
+
readonly locale: RimLocale;
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
14
|
+
readonly lookupFn?: (hostname: string) => Promise<ReadonlyArray<{
|
|
15
|
+
readonly address: string;
|
|
16
|
+
readonly family: number;
|
|
17
|
+
}>>;
|
|
18
|
+
}): Promise<BuiltinTlsAuditResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sec` 安全响应头、CSP3 深度解析、指纹泄漏与可选 `testssl.sh` TLS 体检统一探针 (`probe-sec.ts`)。
|
|
3
|
+
*/
|
|
4
|
+
import { type RimLocale } from './locale.js';
|
|
5
|
+
import { type ParsedCsp, auditCspHeader, parseCsp, parseCspList } from './probe-sec-csp.js';
|
|
6
|
+
import type { BuiltinTlsAuditResult, HttpGateConfig, ProbeFinding, ProbeResult, SecProbeConfig, WaiverRule } from './types.js';
|
|
7
|
+
export { type ParsedCsp, auditCspHeader, parseCsp, parseCspList };
|
|
8
|
+
/** 纯函数: 基于已采集的响应头执行全套内建安全头、CSP3 与指纹头审计 */
|
|
9
|
+
export declare function auditSecurityHeaders(options: {
|
|
10
|
+
readonly targetUrl: string;
|
|
11
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
12
|
+
readonly httpConfig?: HttpGateConfig;
|
|
13
|
+
readonly secConfig?: SecProbeConfig;
|
|
14
|
+
readonly locale: RimLocale;
|
|
15
|
+
}): {
|
|
16
|
+
readonly findings: ProbeFinding[];
|
|
17
|
+
readonly csp: ParsedCsp | null;
|
|
18
|
+
readonly leakedFingerprints: readonly string[];
|
|
19
|
+
};
|
|
20
|
+
/** 运行统一 `sec` 探针 (零外依安全头/CSP3 + 内置 `node:tls` 体检 + 可选外部 `testssl.sh`) */
|
|
21
|
+
export declare function runSecProbe(options: {
|
|
22
|
+
readonly targetUrl: string;
|
|
23
|
+
readonly allowLoopback?: boolean;
|
|
24
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
25
|
+
readonly httpConfig?: HttpGateConfig;
|
|
26
|
+
readonly secConfig?: SecProbeConfig;
|
|
27
|
+
readonly waivers?: readonly WaiverRule[];
|
|
28
|
+
readonly runTls?: boolean;
|
|
29
|
+
readonly runTestssl?: boolean;
|
|
30
|
+
readonly timeoutMs: number;
|
|
31
|
+
readonly locale: RimLocale;
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
readonly resolveAdapterBin?: (names: readonly string[]) => string | null;
|
|
34
|
+
readonly tlsAuditFn?: (input: {
|
|
35
|
+
targetUrl: string;
|
|
36
|
+
allowLoopback: boolean;
|
|
37
|
+
minCertDays?: number;
|
|
38
|
+
timeoutMs: number;
|
|
39
|
+
locale: RimLocale;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}) => Promise<BuiltinTlsAuditResult>;
|
|
42
|
+
}): Promise<ProbeResult>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { RimRuntimeInfo } from './types.js';
|
|
3
|
+
/** 判断当前是否运行在 Bun 下 */
|
|
4
|
+
export declare function isBunRuntime(): boolean;
|
|
5
|
+
/** 构造基于文件路径的零拷贝响应 (Bun 下走 Bun.file, Node 下返回 null 交由 readFile 回退) */
|
|
6
|
+
export declare function createBunFileResponse(filePath: string, headers: Record<string, string>): Response | null;
|
|
7
|
+
/** 读取当前运行时元数据 */
|
|
8
|
+
export declare function getRuntimeInfo(): RimRuntimeInfo;
|
|
9
|
+
/** 支持 AbortSignal 的异步睡眠 (Bun 优先走 Bun.sleep, Node 回退 setTimeout) */
|
|
10
|
+
export declare function sleepMs(ms: number, signal?: AbortSignal): Promise<void>;
|
|
11
|
+
/** 等待异步操作完成或超时到达 (Promise 提前落定时立刻 clearTimeout 防定时器滞留) */
|
|
12
|
+
export declare function waitWithTimeout(promise: Promise<unknown>, timeoutMs: number): Promise<boolean>;
|
|
13
|
+
/** 写入 UTF-8 文本文件 (自动建父目录; Bun 优先走 Bun.write, Node 回退 writeFile) */
|
|
14
|
+
export declare function writeTextFile(filePath: string, content: string): Promise<void>;
|
|
15
|
+
/** 探测本机空闲 TCP 端口 (Bun 优先走 Bun.serve 零长尾快路径, Node 回退 node:net) */
|
|
16
|
+
export declare function allocateFreePort(): Promise<number>;
|
|
17
|
+
export interface LocalFetchServer {
|
|
18
|
+
readonly port: number;
|
|
19
|
+
readonly url: string;
|
|
20
|
+
readonly stop: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 启动 Web Fetch 处理函数本地 HTTP 服务 (仅绑定 127.0.0.1 随机空闲端口):
|
|
24
|
+
* - Bun 下直调 `Bun.serve` (零拷贝原生实现);
|
|
25
|
+
* - Node 下平滑回退 `node:http` + Web Request/Response 桥接。
|
|
26
|
+
*/
|
|
27
|
+
export declare function startFetchServer(fetchHandler: (req: Request) => Response | Promise<Response>, hostname?: string): Promise<LocalFetchServer>;
|
|
28
|
+
/** 按指定目标平台语义判断路径是否为绝对路径 (解耦宿主机 process.platform) */
|
|
29
|
+
export declare function isPlatformAbsolutePath(filePath: string, platform?: NodeJS.Platform): boolean;
|
|
30
|
+
/** 校验规范化后的目标路径严格位于根目录内 (放行 `..foo` 类合法文件名, 拦截 `..` 越界与跨盘符) */
|
|
31
|
+
export declare function isPathWithinRoot(realRoot: string, realCandidate: string): boolean;
|
|
32
|
+
/** 将用户/配置提供的相对路径安全解析至指定 origin 内 (严拒协议前缀与 `//host` 跨源逃逸) */
|
|
33
|
+
export declare function resolveSameOriginUrl(origin: string, rawPath: string, locale?: RimLocale, fieldLabel?: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* 仅从绝对 PATH 目录解析可执行文件绝对路径 (严禁搜索 cwd 或相对路径, 防 win32/POSIX 劫持)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveAbsoluteFromPath(names: readonly string[], options?: {
|
|
38
|
+
platform?: NodeJS.Platform;
|
|
39
|
+
env?: NodeJS.ProcessEnv;
|
|
40
|
+
fileProbe?: (candidate: string) => boolean;
|
|
41
|
+
}): string | null;
|
|
42
|
+
/** 校验目标 URL 仅限 http / https, 防止 file: / javascript: / data: 等危险协议 */
|
|
43
|
+
export declare function assertSafeHttpUrl(rawUrl: string, locale?: RimLocale): URL;
|
|
44
|
+
/** 校验用户提供的显式绝对文件路径是否存在 */
|
|
45
|
+
export declare function isExistingFile(filePath: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
/** 剔除可劫持子进程加载器的危险环境变量 (BUN_OPTIONS / NODE_OPTIONS / LD_PRELOAD / DYLD_* / npm_config_*) */
|
|
3
|
+
export declare function buildSanitizedChildEnv(baseEnv?: NodeJS.ProcessEnv, extra?: Readonly<Record<string, string>>): Record<string, string>;
|
|
4
|
+
export type IpClass = 'public' | 'benchmark' | 'loopback' | 'private' | 'link-local' | 'cgnat' | 'reserved' | 'invalid';
|
|
5
|
+
/** 精确分类 IPv4 / IPv6 地址 (含 IPv4-mapped IPv6、NAT64 64:ff9b::/96、6to4、Teredo、CGNAT 与云元数据) */
|
|
6
|
+
export declare function classifyIpAddress(rawIp: string): IpClass;
|
|
7
|
+
export declare function isLoopbackIp(ip: string): boolean;
|
|
8
|
+
export declare function isPrivateOrReservedIp(ip: string): boolean;
|
|
9
|
+
export interface ResolvedHostPin {
|
|
10
|
+
readonly hostname: string;
|
|
11
|
+
readonly address: string;
|
|
12
|
+
readonly family: 4 | 6;
|
|
13
|
+
readonly isLoopback: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** 解析主机名并执行 SSRF 策略校验 (返回钉选 IP 用于防 DNS Rebinding TOCTOU) */
|
|
16
|
+
export declare function resolveAndPinHost(options: {
|
|
17
|
+
readonly hostname: string;
|
|
18
|
+
readonly allowLoopback: boolean;
|
|
19
|
+
readonly locale?: RimLocale;
|
|
20
|
+
readonly lookupFn?: (hostname: string) => Promise<ReadonlyArray<{
|
|
21
|
+
readonly address: string;
|
|
22
|
+
readonly family: number;
|
|
23
|
+
}>>;
|
|
24
|
+
}): Promise<ResolvedHostPin>;
|
|
25
|
+
/** 按真实 DNS 解析结果判定目标 URL 是否全部指向本机回环地址 (用于 `--allow-load` 安全护栏) */
|
|
26
|
+
export declare function isLoopbackTarget(rawUrl: string, lookupFn?: (hostname: string) => Promise<ReadonlyArray<{
|
|
27
|
+
readonly address: string;
|
|
28
|
+
readonly family: number;
|
|
29
|
+
}>>): Promise<boolean>;
|
|
30
|
+
/** LIFO 清理栈与收尾期冻结守卫 (防收尾期竞态再派生子进程) */
|
|
31
|
+
export declare class LifecycleGuard {
|
|
32
|
+
private readonly stack;
|
|
33
|
+
private shuttingDown;
|
|
34
|
+
isShuttingDown(): boolean;
|
|
35
|
+
assertNotShuttingDown(locale?: RimLocale): void;
|
|
36
|
+
register(cleanup: () => Promise<void> | void): () => void;
|
|
37
|
+
cleanupAll(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/** 将 URL 或主机名转换为跨平台安全的目录名 Slug (兼容 Windows 保留设备名、防路径穿越与碰撞) */
|
|
40
|
+
export declare function toSafeHostSlug(hostOrUrl: string): string;
|
|
41
|
+
/** 严格转义 HTML 特殊字符防 XSS (纯安全字符串零替换快路径) */
|
|
42
|
+
export declare function escapeHtml(input: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
export { type IpClass, LifecycleGuard, type ResolvedHostPin, buildSanitizedChildEnv, classifyIpAddress, escapeHtml, isLoopbackIp, isLoopbackTarget, isPrivateOrReservedIp, resolveAndPinHost, toSafeHostSlug, } from './security-ip.js';
|
|
3
|
+
/** 解压响应体硬上限 (4 MiB, 防 zip-bomb 内存耗尽) */
|
|
4
|
+
export declare const MAX_DECOMPRESSED_BODY_BYTES: number;
|
|
5
|
+
/** 单次 HTTP 探测接收线缆字节硬上限 (4 MiB) */
|
|
6
|
+
export declare const MAX_WIRE_BODY_BYTES: number;
|
|
7
|
+
/** 手动重定向最大跳数 */
|
|
8
|
+
export declare const MAX_REDIRECT_HOPS = 5;
|
|
9
|
+
export interface PinnedHttpResponse {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly finalUrl: string;
|
|
12
|
+
readonly redirectChain: readonly string[];
|
|
13
|
+
readonly status: number;
|
|
14
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
15
|
+
readonly linkHeaders: readonly string[];
|
|
16
|
+
readonly wireBytes: number;
|
|
17
|
+
readonly contentEncoding: string | null;
|
|
18
|
+
readonly ttfbMs: number;
|
|
19
|
+
readonly rawBody: Buffer;
|
|
20
|
+
}
|
|
21
|
+
/** 解压 HTTP 响应体 (带严格 4 MiB 解压上限防 zip-bomb OOM) */
|
|
22
|
+
export declare function decompressBodySafe(rawBody: Buffer, contentEncoding: string | null, maxBytes?: number): Buffer;
|
|
23
|
+
/**
|
|
24
|
+
* 带 SSRF 防护、DNS IP 钉选、逐跳手动重定向校验与精确线缆字节统计的 HTTP 客户端。
|
|
25
|
+
*/
|
|
26
|
+
export declare function ssrfHttpRequest(options: {
|
|
27
|
+
readonly url: string;
|
|
28
|
+
readonly method?: 'GET' | 'HEAD';
|
|
29
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
30
|
+
readonly allowLoopback: boolean;
|
|
31
|
+
readonly followRedirects?: boolean;
|
|
32
|
+
readonly maxRedirects?: number;
|
|
33
|
+
readonly timeoutMs?: number;
|
|
34
|
+
readonly readBody?: boolean;
|
|
35
|
+
readonly maxWireBytes?: number;
|
|
36
|
+
readonly locale?: RimLocale;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
readonly fetchFn?: typeof fetch;
|
|
39
|
+
readonly lookupFn?: (hostname: string) => Promise<ReadonlyArray<{
|
|
40
|
+
readonly address: string;
|
|
41
|
+
readonly family: number;
|
|
42
|
+
}>>;
|
|
43
|
+
}): Promise<PinnedHttpResponse>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CdpClient } from './cdp.js';
|
|
2
|
+
import { type RimLocale } from './locale.js';
|
|
3
|
+
import type { SmokeGateConfig, SmokeGateResult } from './types.js';
|
|
4
|
+
/** 执行内置 Chrome CDP 冒烟与声明式 E2E 步骤 (或外部命令桥接) */
|
|
5
|
+
export declare function runSmokeGate(options: {
|
|
6
|
+
targetUrl: string;
|
|
7
|
+
chromePath: string;
|
|
8
|
+
config: SmokeGateConfig;
|
|
9
|
+
cwd?: string;
|
|
10
|
+
timeoutMs: number;
|
|
11
|
+
locale: RimLocale;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
afterSmokeHook?: (cdp: CdpClient) => Promise<void>;
|
|
14
|
+
}): Promise<SmokeGateResult>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { RunningTarget } from './types.js';
|
|
3
|
+
/** 零 URL 对象分配快速提取 pathname (兼容完整 URL 与相对路径) */
|
|
4
|
+
export declare function extractPathname(rawUrl: string): string;
|
|
5
|
+
/** 解析 Accept-Encoding 编码协商 (常规无权重无通配走预编译 Yarr JIT 零分配快路径, 含 q/* 走完整权重解析) */
|
|
6
|
+
export declare function acceptsEncoding(header: string | null | undefined, encoding: 'br' | 'gzip'): boolean;
|
|
7
|
+
/** 规范化可选 basePath (如 '/bridge/' -> '/bridge', '/' -> '') */
|
|
8
|
+
export declare function normalizeBasePath(raw?: string): string;
|
|
9
|
+
/** 规范化静态请求路径并拦截控制字符、目录穿越与非法编码 */
|
|
10
|
+
export declare function normalizeStaticPath(rawPathname: string, basePath?: string): string | null;
|
|
11
|
+
export interface StaticSiteServerOptions {
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
readonly basePath?: string;
|
|
14
|
+
readonly spaFallback?: boolean;
|
|
15
|
+
readonly entryPath?: string;
|
|
16
|
+
readonly locale?: RimLocale;
|
|
17
|
+
}
|
|
18
|
+
/** 创建默认高性能预压缩静态站点服务桥接 (仅监听 127.0.0.1 随机空闲端口) */
|
|
19
|
+
export declare function createStaticSiteServer(options: StaticSiteServerOptions): Promise<RunningTarget>;
|