mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
The idempotency cache refuses to persist a body carrying a HealthLog token or an AI provider key. The notification test routes are about to refuse echoing such text too, so the pattern moves to src/lib/secret-shape.ts instead of being written a second time. Behaviour of the cache is unchanged.
22 lines
964 B
TypeScript
22 lines
964 B
TypeScript
/**
|
|
* One definition of "this text carries a credential HealthLog or a common
|
|
* AI provider mints", shared by every surface that refuses to store or echo
|
|
* such text.
|
|
*
|
|
* `hlk_` access tokens, `hlr_` refresh tokens, `hls_` clinician share-link
|
|
* tokens, `hlv_` registration invite tokens, `hle_` elevation tokens;
|
|
* `sk-…` / `sk-ant-…` OpenAI and Anthropic keys, in the full token form
|
|
* only: a bare `sk-` substring ("task-id", "risk-management") is not a key,
|
|
* and matching it would refuse benign text.
|
|
*
|
|
* It is a shape test, not a secret detector. A credential without one of
|
|
* these prefixes (a relay's own app token, a password) passes, so a caller
|
|
* that knows the secrets in play must also refuse text containing them.
|
|
*/
|
|
const SECRET_SHAPED =
|
|
/(?:\b(?:hlk_|hlr_|hls_|hlv_|hle_)[A-Za-z0-9_-]+|\bsk-(?:ant-)?[A-Za-z0-9_-]{8,})/;
|
|
|
|
export function looksSecretShaped(text: string): boolean {
|
|
return SECRET_SHAPED.test(text);
|
|
}
|