Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0) while keeping both sides' features in every conflicted file: - EventRouter dispatch extracted from runReview.ts (7.1), with the runtime environment block preserved on the review-start comment - Unified command ack messages (6.3) combined with the collapsed runtime environment block and bot signature on /recheck replies - Status banner and collapsible unposted findings in review bodies (6.1) - Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13); webhook knowledge cache now lives under tempRootDirectory() - Production hardening for merge races, timeouts, webhook ops; atomic temp-file rename for R2 cache restores kept from upstream - Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED, read-only command guidance, repository knowledge injection, runtime environment block on webhook chat replies - Sanitization/secret redaction centralization, error-aware retry, duplicate merge prevention, in-process webhook retries, /metrics - Infra: eslint/prettier gates with CI verify workflow, docs archives typecheck, eslint, prettier format:check, and 164 tests all pass.
title, impact, impactDescription, tags
| title | impact | impactDescription | tags |
|---|---|---|---|
| Validate at System Boundaries | CRITICAL | Validating deep in business logic allows corrupt data to propagate; validating at boundaries catches issues before they spread | parse, boundaries, architecture, defense-in-depth |
Validate at System Boundaries
Validate external data immediately when it enters your system—at API endpoints, form handlers, message queue consumers, and configuration loaders. Validating deep in business logic allows corrupt data to propagate and makes debugging harder.
Incorrect (validating deep in business logic):
import { z } from "zod";
// No validation at API boundary
export async function POST(req: NextRequest) {
const body = await req.json();
// Raw unknown data passed through
return await processOrder(body);
}
async function processOrder(data: unknown) {
// Data passed around unvalidated
const items = await calculateTotals(data);
return await chargeCustomer(data, items);
}
async function calculateTotals(data: unknown) {
// Finally validating way too late
const order = orderSchema.parse(data); // Throws here, far from entry point
// ...
}
// Hard to trace where bad data came from
Correct (validating at boundary):
import { z } from "zod";
const orderSchema = z.object({
customerId: z.string().uuid(),
items: z
.array(
z.object({
productId: z.string(),
quantity: z.number().int().positive()
})
)
.min(1),
shippingAddress: z.object({
street: z.string(),
city: z.string(),
country: z.string()
})
});
type Order = z.infer<typeof orderSchema>;
// Validate immediately at boundary
export async function POST(req: NextRequest) {
const body = await req.json();
const result = orderSchema.safeParse(body);
if (!result.success) {
return NextResponse.json(
{ error: "Invalid order", issues: result.error.issues },
{ status: 400 }
);
}
// Now data is validated and typed
return await processOrder(result.data);
}
// Business logic receives typed, validated data
async function processOrder(order: Order) {
// order is guaranteed to match schema
const items = await calculateTotals(order);
return await chargeCustomer(order, items);
}
async function calculateTotals(order: Order) {
// No validation needed - type guarantees shape
return order.items.map((item) => ({
...item,
total: item.quantity * getPrice(item.productId)
}));
}
Boundaries to validate:
// API endpoints
export async function POST(req: NextRequest) {
const data = await req.json();
const validated = requestSchema.safeParse(data);
// ...
}
// Message queue consumers
async function handleMessage(rawMessage: string) {
const data = JSON.parse(rawMessage);
const validated = messageSchema.safeParse(data);
// ...
}
// Configuration loading
const config = configSchema.parse(JSON.parse(process.env.CONFIG!));
// External API responses
const response = await fetch("/api/users");
const data = await response.json();
const users = usersResponseSchema.parse(data);
When NOT to use this pattern:
- Internal function calls with already-validated data
- Performance-critical hot paths (validate once, trust afterward)