Skip to content

Commit 1d76ca6

Browse files
committed
docs: align API docs with security-hardened public surface + VProtocol certificate
- Update ClusterConfig reference with allowedEnvVars and workerScriptAllowlist - Update HealthCheckConfig reference with failure/success thresholds, allowedSchemes, allowedHosts, method, expectedBody - Fix LOAD_BALANCING.md threshold names and add restrict-targets best practice - Add verification-certificate.json and VERIFICATION.md from VProtocol run Verdict: HumanReviewRecommended (size cap + monoculture ρ)
1 parent 012a530 commit 1d76ca6

5 files changed

Lines changed: 427 additions & 16 deletions

File tree

VERIFICATION.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Verification Certificate
2+
3+
### PR: #7 — security: red-team audit hardening
4+
5+
**Classification:** GeneratedCode
6+
**Generator:** Kimi k1.5-code (Moonshot AI)
7+
**Pipeline diversity:** B=C=D=E=Kimi → **INSUFFICIENT** (monoculture fallback applied)
8+
**η:** 0.804 (signals o=0.95, b=0.90, s=1.00, t=1.00, d=1.00; ρ=0.15)
9+
**Cv/Ci ratio:** null (Ci zero — open-source contribution, human floor used)
10+
**Verification Gap (module):** 0.00 | **(repo):** 0.00
11+
12+
### Axes Summary
13+
14+
| Axis | Status | Key Finding |
15+
| ---------------------------- | ------ | --------------------------------------------------------------------------------------------------------- |
16+
| 2.1 Semantic Correctness || Initial target health preserves explicit `healthy: false`. |
17+
| 2.2 Behavioral Contract Diff || New `ClusterConfig`/`LoadBalancerConfig` fields are optional, no breaking changes. |
18+
| 2.3 Security Surface || Proxy sanitization, trusted client IP, health-check SSRF guards, JWT key/exp enforcement. |
19+
| 2.4 Structural Integrity | ⚠️ | Load balancer module is large; consider future split. |
20+
| 2.5 Behavioral Exploration || Timeout/failure threshold scenarios covered; sandbox unavailable. |
21+
| 2.6 Dependency Integrity || `@types/bun` pinned to safe range. |
22+
| 2.7 Generator Provenance | ⚠️ | `generator_identity` present; `prompt_lineage_manifest` not provided. |
23+
| 2.8 Adversarial Surface || Pre-scan found no injection markers, bidi/zero-width anomalies, or unsafe sinks. |
24+
| 2.9 Documentation Coverage || Public API changes documented in `docs/API_REFERENCE.md`, `docs/CLUSTERING.md`, `docs/LOAD_BALANCING.md`. |
25+
26+
### Verification Debt Contribution
27+
28+
- **ΔDebt:** 0.9 hours
29+
- **Module class:** Active
30+
31+
### Unverified Gaps
32+
33+
- **Mutation testing** (axis 2.1) — no mutation framework available for Bun/TypeScript. Risk: medium.
34+
- **Replay sandbox / fuzz harness** (axis 2.5) — not configured. Risk: medium.
35+
36+
### Attestation
37+
38+
- **Signed by:** Kimi Code CLI (monoculture self-attestation)
39+
- **Certificate file:** `verification-certificate.json`
40+
- **Protocol version:** 5.2.7
41+
42+
### Verdict
43+
44+
- [ ] **Auto-Approve**
45+
- [x] **Human Review Recommended**
46+
- [ ] **Human Review REQUIRED**
47+
- [ ] **Cannot Verify**
48+
49+
**Rationale:** PR size (4,621 LOC) triggers the §0.3 size-cap ceiling at `HumanReviewRecommended`. Monoculture pipeline (ρ = 0.15) also maps to `HumanReviewRecommended`. All axes pass after auto-remediation of documentation gaps; no 🔴 findings remain.

docs/API_REFERENCE.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ interface ClusterConfig {
115115
respawnThresholdTime?: number // Default: 60000ms
116116
shutdownTimeout?: number // Default: 30000ms
117117
exitOnShutdown?: boolean // Default: true
118+
allowedEnvVars?: string[] // Allow-list of env vars forwarded to workers
119+
workerScriptAllowlist?: string[] // Allow-list of worker script paths
118120
}
119121
```
120122

@@ -392,12 +394,17 @@ gateway.addRoute({
392394
```typescript
393395
interface HealthCheckConfig {
394396
enabled: boolean
395-
interval?: number // Default: 30000ms
396-
timeout?: number // Default: 5000ms
397+
interval?: number // Default: 30000ms, clamped to 1000ms–300000ms
398+
timeout?: number // Default: 5000ms, must be less than interval
397399
path?: string // Default: '/health'
400+
method?: 'GET' | 'HEAD' // Default: 'GET'
398401
expectedStatus?: number // Default: 200
399-
unhealthyThreshold?: number // Default: 3
400-
healthyThreshold?: number // Default: 2
402+
expectedBody?: string // Optional body substring required for healthy status
403+
failureThreshold?: number // Default: 3, max 20
404+
successThreshold?: number // Default: 2, max 20
405+
minHealthyTargets?: number // Default: 1
406+
allowedSchemes?: string[] // Default: ['http', 'https']
407+
allowedHosts?: string[] // CIDR or exact hosts allowed for health checks
401408
validator?: (response: Response) => Promise<boolean> | boolean
402409
}
403410
```

docs/CLUSTERING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ interface ClusterConfig {
141141
// Exit master process after shutdown (default: true)
142142
// Set to false for testing or embedded usage
143143
exitOnShutdown: boolean
144+
145+
// Allow-list of environment variable names forwarded to workers.
146+
// If provided, only these variables (plus internal CLUSTER_* vars) are passed.
147+
allowedEnvVars?: string[]
148+
149+
// Allow-list of worker script paths. The worker script must match one of
150+
// these paths to prevent accidental execution of arbitrary files.
151+
workerScriptAllowlist?: string[]
144152
}
145153
```
146154

docs/LOAD_BALANCING.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ gateway.addRoute({
401401
timeout: 5000, // 5 second timeout
402402
path: '/health', // Health check endpoint
403403
expectedStatus: 200, // Expected status code
404-
unhealthyThreshold: 3, // Failures before marking unhealthy
405-
healthyThreshold: 2, // Successes before marking healthy
404+
failureThreshold: 3, // Failures before marking unhealthy
405+
successThreshold: 2, // Successes before marking healthy
406406
},
407407
},
408408
})
@@ -594,7 +594,7 @@ gateway.addRoute({
594594
enabled: true,
595595
interval: 10000,
596596
path: '/health',
597-
unhealthyThreshold: 2, // Fast failover
597+
failureThreshold: 2, // Fast failover
598598
},
599599
},
600600
})
@@ -650,12 +650,29 @@ healthCheck: {
650650
interval: 15000,
651651
timeout: 5000,
652652
path: '/health',
653-
unhealthyThreshold: 3,
654-
healthyThreshold: 2,
653+
failureThreshold: 3,
654+
successThreshold: 2,
655655
}
656656
```
657657

658-
### 2. Use Circuit Breakers for External Services
658+
### 2. Restrict Health Check Targets
659+
660+
For security, limit which schemes and hosts the load balancer may probe.
661+
662+
```typescript
663+
healthCheck: {
664+
enabled: true,
665+
interval: 15000,
666+
timeout: 5000,
667+
path: '/health',
668+
failureThreshold: 3,
669+
successThreshold: 2,
670+
allowedSchemes: ['http', 'https'],
671+
allowedHosts: ['10.0.0.0/8', 'api.internal.example.com'],
672+
}
673+
```
674+
675+
### 3. Use Circuit Breakers for External Services
659676

660677
```typescript
661678
circuitBreaker: {
@@ -666,7 +683,7 @@ circuitBreaker: {
666683
}
667684
```
668685

669-
### 3. Configure Timeouts
686+
### 4. Configure Timeouts
670687

671688
```typescript
672689
gateway.addRoute({
@@ -681,7 +698,7 @@ gateway.addRoute({
681698
})
682699
```
683700

684-
### 4. Monitor Target Health
701+
### 5. Monitor Target Health
685702

686703
```typescript
687704
import { PinoLogger } from 'bungate'
@@ -698,7 +715,7 @@ gateway.on('target-healthy', (target) => {
698715
})
699716
```
700717

701-
### 5. Use Appropriate Strategy
718+
### 6. Use Appropriate Strategy
702719

703720
```typescript
704721
// ❌ DON'T use IP hash for APIs behind NAT
@@ -714,7 +731,7 @@ loadBalancer: {
714731
}
715732
```
716733

717-
### 6. Plan for Capacity
734+
### 7. Plan for Capacity
718735

719736
```typescript
720737
// Configure weights based on actual capacity
@@ -728,7 +745,7 @@ loadBalancer: {
728745
}
729746
```
730747

731-
### 7. Test Failover Scenarios
748+
### 8. Test Failover Scenarios
732749

733750
```bash
734751
# Simulate server failure
@@ -781,7 +798,7 @@ targets: [
781798
healthCheck: {
782799
enabled: true,
783800
timeout: 10000, // Increase from 5000
784-
unhealthyThreshold: 5, // Require more failures
801+
failureThreshold: 5, // Require more failures
785802
}
786803

787804
// 2. Check health endpoint performance

0 commit comments

Comments
 (0)