- Notifications
You must be signed in to change notification settings - Fork 0
chore(readiness): assert query-hash HMAC guard is active (PIA-2)#532
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
06dc4be42be827417470e1c5a10d9710831File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -136,13 +136,44 @@ async function checkFileForServiceRoleExposure() { | ||
| } | ||
| } | ||
| // PIA-2: the query-hash HMAC guard only redacts logged clinical queries if it is | ||
| // actually invoked at boot. Assert the fail-closed call is still wired into the | ||
| // startup path (src/instrumentation.ts) so a refactor can't silently drop it and let | ||
| // production start writing unsalted, dictionary-reversible SHA-256 hashes. The | ||
| // behavioural proof lives in tests/instrumentation.test.ts; this is a check-time | ||
| // signal that the guard is active in every environment, including CI where the | ||
| // secret-presence check below is intentionally quiet. The regex matches the call | ||
| // form (`requireQueryHashSecret(`), not the bare import destructuring. | ||
| async function checkQueryHashGuardWiring() { | ||
| const instrumentationPath = path.join(process.cwd(), "src", "instrumentation.ts"); | ||
| let source: string; | ||
| try { | ||
| source = await readFile(instrumentationPath, "utf8"); | ||
| } catch { | ||
| result.failures.push( | ||
| "Cannot read src/instrumentation.ts to verify the RAG_QUERY_HASH_SECRET boot guard is active.", | ||
| ); | ||
| return; | ||
| } | ||
| if (/\brequireQueryHashSecret\s*\(/.test(source)) { | ||
| result.passes.push( | ||
| "Boot guard invokes requireQueryHashSecret(); the query-hash HMAC fails closed in production (PIA-2).", | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
| } else { | ||
| result.failures.push( | ||
| "src/instrumentation.ts no longer invokes requireQueryHashSecret(); the query-hash HMAC boot guard (PIA-2) is not active.", | ||
| ); | ||
| } | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| async function main() { | ||
| checkNodeRuntime(); | ||
| recordNoAuthProductionCheck(); | ||
| recordDemoModeProductionCheck(); | ||
| recordRawQueryPersistenceProductionCheck(); | ||
| recordAnswerPersistenceProductionCheck(); | ||
| await checkFileForServiceRoleExposure(); | ||
| await checkQueryHashGuardWiring(); | ||
| if (!(await checkRequiredFile(path.join(process.cwd(), "package-lock.json"), "package-lock.json is required"))) { | ||
| // keep going so we can show all diagnostics | ||
| @@ -198,9 +229,21 @@ async function main() { | ||
| } | ||
| } | ||
| const productionLike = process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production"; | ||
| if (productionLike && !envModule.env.RAG_QUERY_HASH_SECRET) { | ||
| result.failures.push("RAG_QUERY_HASH_SECRET is required in a production-like environment."); | ||
| // Exercise the real boot guard so this check tracks its behaviour instead of | ||
| // re-encoding the env rule (mirrors requireServerEnv/requireOpenAIEnv above). A | ||
| // present secret passes in any environment; a missing one fails closed only in a | ||
| // production-like environment (dev/CI keep the legacy digest for stored-row joins). | ||
| try { | ||
| envModule.requireQueryHashSecret(); | ||
| result.passes.push( | ||
| "RAG_QUERY_HASH_SECRET is set; logged clinical-query hashes are keyed HMAC pseudonyms (PIA-2).", | ||
| ); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| const productionLike = process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production"; | ||
| if (productionLike) { | ||
| result.failures.push(`Query-hash secret issue: ${message}`); | ||
| } | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| if (placeholderLooksLikeExample(envModule.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY ?? "")) { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.