Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/embedjs/src/store/memory-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class MemoryStore implements BaseStore {

async init(): Promise<void> {
this.loaderList = {};
this.loaderCustomValues = {};
this.loaderCustomValues = Object.create(null);
this.conversations = new Map();
this.loaderCustomValuesMap = new Map();
}
Expand Down Expand Up @@ -37,6 +37,9 @@ export class MemoryStore implements BaseStore {
}

async loaderCustomGet<T extends Record<string, unknown>>(key: string): Promise<T> {
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
throw new Error("Invalid key");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent Key Validation Breaks Store Contract

The validation check for dangerous keys (__proto__, constructor, prototype) is only in loaderCustomGet, but not in loaderCustomSet, loaderCustomHas, or loaderCustomDelete. This creates inconsistent behavior where keys can be set and checked but cannot be retrieved, breaking the expected contract of a key-value store. If the intent is to block these keys, the validation belongs in loaderCustomSet where the assignment occurs, not in the getter.

Fix in Cursor Fix in Web

const data = <T & { loaderId: string }>this.loaderCustomValues[key];
delete data.loaderId;
return data;
Expand Down
Loading