-
Notifications
You must be signed in to change notification settings - Fork 665
feat(lab): CL-02 immutable evidence ledger and projection #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
247d2d3
feat(lab): CL-02 immutable evidence ledger and SQLite projection
Wibias cb94cf0
docs(devlog): record CL-02 draft PR #1333 and implementation tip
Wibias 07bc292
docs(devlog): point CL-02 stack tip at current branch HEAD
Wibias 96ecd65
fix(lab): harden CL-02 evidence ledger per review findings
Wibias cf626d1
test(lab): add CL-02 review regression coverage and update status
Wibias 1251d31
fix(lab): close CL-02 phase-2 independent-review blockers
Wibias 00785fd
fix(lab): reject symlink targets before artifact create
Wibias afc6697
fix(lab): lstat symlink squatters before artifact create
Wibias 40725d6
fix(lab): centralize evidence producer version
Wibias 1eb173d
fix(lab): fail closed when sanitizing evidence
Wibias f7c0a8c
fix(lab): enforce restricted state directories
Wibias 0afa852
fix(lab): validate suite manifest authority
Wibias 527d97f
fix(lab): bound invalidation target lookup
Wibias 4f6f9ab
fix(lab): make purge artifact retention fail closed
Wibias 21906ac
fix(lab): constrain projection enum columns
Wibias 2af46f3
fix(lab): make sensitive purge progress explicit
Wibias a12a555
fix(lab): complete ledger appends across short writes
Wibias 3dddcda
fix(lab): reject POSIX paths before ledger admission
Wibias f3d878a
fix(lab): verify artifact digests by class
Wibias 441b782
fix(lab): persist real conformance evidence metadata
Wibias dca7624
fix(lab): enforce verification contracts and freshness
Wibias 6ed1838
fix(lab): make verdict projection contract-safe
Wibias 0644000
fix(lab): rebuild projection atomically
Wibias 9ba59cd
fix(lab): accept measured runner timestamps
Wibias 1ac3d32
test(lab): cover phase-2 evidence fixes
Wibias daab377
fix(lab): classify artifact filesystem failures
Wibias e5af56a
fix(lab): remove raw ledger production reader
Wibias 02ca5b5
docs(lab): document sensitive purge exception
Wibias eecec3a
refactor(lab): isolate validation error type
Wibias 0c9dc4d
refactor(lab): break validation import cycle
Wibias 1eed4ff
fix(lab): validate claim source event ids
Wibias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /** | ||
| * Deny-by-default sanitization before artifact hashing/writing. | ||
| * Never persists prompts, secrets, paths, account IDs, raw URLs, or provider bodies. | ||
| */ | ||
| import type { ArtifactClass } from "../constants"; | ||
| import { MAX_SANITIZED_STRING_FIELD } from "../constants"; | ||
| import { jcsStringify } from "../digest"; | ||
| import { redactSecretString } from "../../lib/redact"; | ||
|
|
||
| const FORBIDDEN_KEY = /^(?:authorization|proxy-authorization|cookie|set-cookie|api[-_]?key|x-api-key|token|secret|password|email|prompt|messages|content|body|url|hostname|baseUrl|path|account|alias)$/i; | ||
| const SECRETISH = /sk-[a-z0-9]{10,}|Bearer\s+[A-Za-z0-9._\-]+|ghp_[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}/i; | ||
|
Wibias marked this conversation as resolved.
|
||
| const SECRETISH_GLOBAL = /sk-[a-z0-9]{10,}|Bearer\s+[A-Za-z0-9._\-]+|ghp_[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}/gi; | ||
|
|
||
| export function redactForArtifact(artifactClass: ArtifactClass, payload: unknown): unknown { | ||
| if ( | ||
| artifactClass === "fixture" || | ||
| artifactClass === "scenario_manifest" || | ||
| artifactClass === "suite_manifest" || | ||
| artifactClass === "claim_source_manifest" | ||
| ) { | ||
| // Contract artifacts are already synthetic/canonical. Mutating them would | ||
| // invalidate content-addressed digests; reject secret-shaped material instead. | ||
| assertNoSecretMaterial(payload, 0); | ||
| return payload; | ||
| } | ||
| return scrubValue(payload, 0); | ||
| } | ||
|
|
||
| const FORBIDDEN_CONTRACT_KEYS = /^(?:authorization|proxy-authorization|cookie|set-cookie|api[-_]?key|x-api-key|token|secret|password|email|prompt|messages|baseUrl|hostname|account|alias)$/i; | ||
|
|
||
| function assertNoSecretMaterial(value: unknown, depth: number): void { | ||
| if (depth > 8) { | ||
| throw new Error("contract artifact exceeds sanitization inspection depth"); | ||
| } | ||
| if (typeof value === "string") { | ||
| if (SECRETISH.test(value)) { | ||
| throw new Error("contract artifact contains forbidden secret-shaped material"); | ||
| } | ||
| return; | ||
| } | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) assertNoSecretMaterial(item, depth + 1); | ||
| return; | ||
| } | ||
| if (value && typeof value === "object") { | ||
| for (const [key, child] of Object.entries(value as object)) { | ||
| if (FORBIDDEN_CONTRACT_KEYS.test(key)) { | ||
| throw new Error(`contract artifact forbids key ${key}`); | ||
| } | ||
| assertNoSecretMaterial(child, depth + 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function scrubValue(value: unknown, depth: number): unknown { | ||
| if (depth > 8) return "[truncated_depth]"; | ||
| if (value === null || typeof value === "boolean" || typeof value === "number") return value; | ||
| if (typeof value === "string") return scrubString(value); | ||
| if (value instanceof Uint8Array) { | ||
| const text = new TextDecoder().decode(value); | ||
| return new TextEncoder().encode(scrubString(text)); | ||
| } | ||
| if (Array.isArray(value)) { | ||
| if (value.length > 256) return value.slice(0, 256).map((v) => scrubValue(v, depth + 1)); | ||
| return value.map((v) => scrubValue(v, depth + 1)); | ||
| } | ||
| if (typeof value === "object") { | ||
| const out: Record<string, unknown> = {}; | ||
| const keys = Object.keys(value as object).slice(0, 64); | ||
| for (const key of keys) { | ||
| if (FORBIDDEN_KEY.test(key)) { | ||
| out[key] = "[redacted]"; | ||
| continue; | ||
| } | ||
| out[key] = scrubValue((value as Record<string, unknown>)[key], depth + 1); | ||
| } | ||
| return out; | ||
| } | ||
| return "[unsupported]"; | ||
| } | ||
|
|
||
| function scrubString(value: string): string { | ||
| let s = redactSecretString(value); | ||
| s = s.replace(SECRETISH_GLOBAL, "[REDACTED]"); | ||
| // Strip absolute filesystem paths (coarse) | ||
| s = s.replace(/(?:[A-Za-z]:\\|\/(?:home|Users|tmp|var|etc|root|mnt)\/)[^\s"']+/g, "[path]"); | ||
| // Strip URL userinfo / private hosts roughly | ||
| s = s.replace(/https?:\/\/[^\s"']+/gi, (url) => { | ||
| try { | ||
| const u = new URL(url); | ||
| if (u.username || u.password) return "[redacted-url]"; | ||
| if (/^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[0-1])\.)/i.test(u.hostname)) { | ||
| return `${u.protocol}//[private-host]${u.pathname}`; | ||
| } | ||
| return `${u.protocol}//[host]${u.pathname}`; | ||
| } catch { | ||
| return "[redacted-url]"; | ||
| } | ||
| }); | ||
| const bytes = new TextEncoder().encode(s); | ||
| if (bytes.byteLength > MAX_SANITIZED_STRING_FIELD) { | ||
| return new TextDecoder().decode(bytes.slice(0, MAX_SANITIZED_STRING_FIELD)); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| /** Stable privacy boundary for diagnostic text that may be persisted. */ | ||
| export function sanitizeDiagnostic(value: unknown): string { | ||
| return scrubString(value instanceof Error ? value.message : String(value)); | ||
| } | ||
|
|
||
| export function sanitizedJsonBytes(value: unknown): Uint8Array { | ||
| return new TextEncoder().encode(jcsStringify(scrubValue(value, 0))); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Pin the current unaccepted CL-02 revision.
Line 24 uses the
Accepted headcolumn for a status string. Lines 125-138 record the prior accepted SHA but not the SHA for the current CodeRabbit remediation. A draft PR can move, so this document cannot identify the exact revision covered by the stated validation and pending acceptance.Keep
Accepted headas—until independent acceptance. Add aCurrent candidate headentry with the remediation commit SHA. Reference the same SHA in the current validation status.Proposed wording
Also applies to: 123-140
🤖 Prompt for AI Agents