Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🥅 chore: Block DB Model APIs That Bypass Isolation (#15663)

Danny Avila4fdab5ef4d1d
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 43d141b1f5..02a2e5d3ab 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -22,6 +22,24 @@ const compat = new FlatCompat({
allConfig: js.configs.all,
});
+const tenantModelRestrictions = [
+ {
+ selector: "CallExpression[callee.property.name='bulkSave']",
+ message:
+ 'Avoid Model.bulkSave() — it derives writes and delegates to bulkWrite() after running save hooks, but without query middleware to scope the generated write filters. Use create()/insertMany() or tenantSafeBulkWrite() instead.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='watch']",
+ message:
+ "Avoid Model.watch() — a change stream opens outside query middleware, so the tenant isolation plugin cannot scope it and it emits every tenant's events. A change stream requires a justified inline exemption documenting its system context and explicit tenantId $match guard.",
+ },
+ {
+ selector: "CallExpression[callee.property.name='estimatedDocumentCount']",
+ message:
+ 'Avoid Model.estimatedDocumentCount() — it reads collection metadata and takes no filter, so it always returns the count across every tenant. Use countDocuments() for a tenant-scoped count.',
+ },
+];
+
export default [
{
ignores: [
@@ -374,7 +392,15 @@ export default [
},
},
{
- // **Data-schemas — ban raw bulkWrite/collection.* in production code**
+ files: ['packages/data-schemas/**/*.ts', 'packages/api/**/*.{ts,js}', 'api/**/*.{ts,js}'],
+ ignores: ['**/*.spec.{ts,js}', '**/*.test.{ts,js}'],
+ rules: {
+ 'no-restricted-syntax': ['error', ...tenantModelRestrictions],
+ },
+ },
+ {
+ // **Data-schemas — ban model APIs that bypass tenant isolation in production code**
+ // Raw driver calls bypass the plugin; bulkSave also bypasses query filter scoping.
// Tests and the tenantSafeBulkWrite wrapper itself are excluded.
files: ['./packages/data-schemas/**/*.ts'],
ignores: ['**/*.spec.ts', '**/*.test.ts', '**/utils/tenantBulkWrite.ts'],
@@ -391,6 +417,7 @@ export default [
message:
'Avoid Model.collection.* — raw driver calls bypass all Mongoose middleware including tenant isolation. Use Mongoose model methods or tenantSafeBulkWrite() instead.',
},
+ ...tenantModelRestrictions,
],
},
},
diff --git a/packages/data-schemas/src/models/plugins/mongoMeili.ts b/packages/data-schemas/src/models/plugins/mongoMeili.ts
index f835f28a92..a5c307ea6e 100644
--- a/packages/data-schemas/src/models/plugins/mongoMeili.ts
+++ b/packages/data-schemas/src/models/plugins/mongoMeili.ts
@@ -478,6 +478,7 @@ const createMeiliMongooseModel = ({
);
// Get approximate total count for raw estimation, the sync should not overcome this number
+ // eslint-disable-next-line no-restricted-syntax -- a collection-wide estimate is the quantity wanted here: it bounds a full-index sync and only feeds a progress log, so a tenant-scoped count would be wrong, not just unnecessary.
const approxTotalCount = await this.estimatedDocumentCount();
logger.info(
`[syncWithMeili] Approximate total number of all ${collectionName}: ${approxTotalCount}`,