feat(namespace): write-door forgery refusal (user metadata keys may never start 'system.') + refusal messages name both spellings in every branch (the non-colliding case marks system.<f> honestly as NOT valid) — cross-engine message pin alignment
This commit is contained in:
parent
8e962dabda
commit
48a6130a50
3 changed files with 30 additions and 3 deletions
|
|
@ -518,7 +518,28 @@ export function validateFindParams(params: FindParams): void {
|
|||
/**
|
||||
* Validate add parameters
|
||||
*/
|
||||
|
||||
/**
|
||||
* The namespace cannot be forged: a USER metadata key literally spelled
|
||||
* 'system.<anything>' would collide with the engine's explicit address
|
||||
* namespace at read time — refuse it at the write door, loudly, with the
|
||||
* fix in the message (sealed 2026-08-03).
|
||||
*/
|
||||
function rejectForgedSystemKeys(metadata: Record<string, unknown> | undefined, site: string): void {
|
||||
if (!metadata) return
|
||||
for (const key of Object.keys(metadata)) {
|
||||
if (key.startsWith('system.')) {
|
||||
throw new Error(
|
||||
`${site}: metadata key '${key}' is not allowed — the 'system.' prefix is the ` +
|
||||
`engine's explicit address namespace and cannot be used as a user field name. ` +
|
||||
`Rename the field (e.g. '${key.slice('system.'.length)}').`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function validateAddParams(params: AddParams): void {
|
||||
rejectForgedSystemKeys(params.metadata as Record<string, unknown> | undefined, 'add()')
|
||||
// Universal truth: must have data or vector
|
||||
if (!params.data && !params.vector) {
|
||||
throw new Error(
|
||||
|
|
@ -559,6 +580,7 @@ export function validateAddParams(params: AddParams): void {
|
|||
* Validate update parameters
|
||||
*/
|
||||
export function validateUpdateParams(params: UpdateParams): void {
|
||||
rejectForgedSystemKeys(params.metadata as Record<string, unknown> | undefined, 'update()')
|
||||
// Universal truth: must have an ID
|
||||
if (!params.id) {
|
||||
throw new Error('id is required for update')
|
||||
|
|
|
|||
Reference in a new issue