fix(invariants): enforce runtime relationships

This commit is contained in:
Tianyi Cui
2026-07-20 23:16:08 +08:00
parent 023cde5d82
commit e92b34bd7e
22 changed files with 398 additions and 75 deletions
@@ -1,27 +0,0 @@
/** Structural redactor surface sampled by the telemetry invariant. */
export interface TelemetryRedactionBoundary {
/** Redact credential material in free-form telemetry content. */
redactText(value: string): string
}
/**
* Validate the security-critical telemetry redaction boundary.
* @param redactor - candidate content redactor.
* @param placeholder - expected replacement for a secret value.
* @param packageName - ordinary package metadata that must survive redaction.
* @returns the violated contract, or `undefined` when redaction is safe and idempotent.
*/
export function telemetryRedactionViolation(
redactor: TelemetryRedactionBoundary,
placeholder: string,
packageName: string,
): string | undefined {
const secret = 'sk-abcdefghij1234567890'
const redacted = redactor.redactText(`apiKey: ${secret}\nname: ${packageName}\n`)
return !redacted.includes(secret)
&& redacted.includes(`apiKey: ${placeholder}`)
&& redacted.includes(`name: ${packageName}`)
&& redactor.redactText(redacted) === redacted
? undefined
: 'telemetry redaction must remove credential values, preserve package metadata, and remain idempotent'
}