Skip to content

[Bug] dashboard-api: AI query builder accepts prompt with no max-length constraint, allowing unbounded token consumption on every AI request #247

@anshul23102

Description

@anshul23102

Bug Summary

The queryBuilder controller in apps/dashboard-api/src/controllers/ai.controller.js validates that prompt is a non-empty string, but applies no upper-bound constraint on its length:

const safePrompt = prompt.trim();

if (!safeCollectionName || !safePrompt) {
    throw new AppError(400, "Collection name and prompt are required");
}

// safePrompt is forwarded to the Python AI service with no length cap
const result = await forwardToPythonService('/query-builder', {
    prompt: safePrompt,
    schema: schemaFields,
    ...
});

An authenticated developer can submit a prompt containing hundreds of thousands of characters. This payload is forwarded directly to the underlying LLM service via forwardToPythonService. Each token in the prompt consumes quota from the project's or platform's AI allocation. A single oversized prompt can exhaust a plan's monthly AI credits in one request.

Steps to Reproduce

  1. Log in as a developer with any plan.
  2. POST to /api/projects/:id/ai/query-builder with { "collectionName": "items", "prompt": "<100,000 character string>" }.
  3. Observe the full prompt is forwarded to the AI service and the response returns successfully.

Expected Behavior

safePrompt should be capped at a practical maximum length (for example, 2000 characters). Requests exceeding the limit should be rejected with HTTP 400 before any AI service call is made.

Actual Behavior

Prompts of arbitrary length are accepted and forwarded to the AI service, consuming unbounded token quota per request.

Affected File

apps/dashboard-api/src/controllers/ai.controller.js, queryBuilder function.


@geturbackend I would like to work on this issue. Could you please assign/ it to me? Contributing under NSoC '26.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions