# Endpoints protected by numeric validation

Starting vulnerability: **Insufficient Input Validation**. A client could send a negative number, or any value outside the field's domain, and the API accepted it.

An invalid value gets **422** with `{ "success": false, "msg": "..." }` and is neither saved nor used in queries. Negative values that belong to the domain are still accepted and are listed in the Rule column.

## Rating (reported endpoint)

| Method | Endpoint | Field | Rule |
| --- | --- | --- | --- |
| PATCH | `/:projectid/requests/:requestid/rating` | `rating` | integer from 1 to 5 |
| PATCH | `/:projectid/requests/:requestid/rating` | `rating_message` | string, if present |
| PATCH | `/:projectid/requests/:requestid` | `rating` | integer from 1 to 5 |

The `Request.rating` model rejects the same values on write too, through Mongoose validators (`min: 1`, `max: 5`, integer).

## Requests and messages

| Method | Endpoint | Field | Rule |
| --- | --- | --- | --- |
| POST | `/:projectid/requests` | message `status` | one of `-100, 0, 100, 150, 200, 250, 300`. `-100` is a failed send |
| PATCH | `/:projectid/requests/:requestid` | `status` | one of `50, 100, 150, 200, 300, 1000` |
| GET | `/:projectid/requests` | `limit`, `page` | `limit` integer ≥ 1; above 100 the default 40 is used. `page` integer ≥ 0 |
| GET | `/:projectid/requests` | `status` | `all` or a comma-separated list of request codes |
| GET | `/:projectid/requests` | `direction` | `-1` or `1` |
| GET | `/:projectid/requests/csv` | `page`, `status`, `direction` | same rules as the list |
| GET | `/:projectid/requests/me` | `limit`, `page`, `status`, `direction` | `limit` as above; `status` a single request code or `all`; `direction` `-1` or `1` |
| POST | `/:projectid/requests/:request_id/messages` | `status` | one of `-100, 0, 100, 150, 200, 250, 300` |
| GET | `/:projectid/messages` | `limit`, `page` | `limit` integer ≥ 1; above 50 the default 10 is used. `page` integer ≥ 0 |
| POST | `/:projectid/campaigns` | `status` | one of `-100, 0, 100, 150, 200, 250, 300` |
| POST | `/:projectid/campaigns/direct` | `status` | one of `-100, 0, 100, 150, 200, 250, 300` |
| POST | `/:projectid/campaigns/directDEPRECATED?` | `status` | one of `-100, 0, 100, 150, 200, 250, 300` |

## Project, departments, leads, properties

| Method | Endpoint | Field | Rule |
| --- | --- | --- | --- |
| PUT | `/projects/:projectid` | `versions` | integer from 0 to 99999999 |
| PUT | `/projects/:projectid` | `settings.max_agent_assigned_chat` | `-1` (no limit) or integer from 0 to 100000. Applies both to the dotted field and inside the `settings` object |
| PUT | `/projects/:projectid` | `settings.reassignment_delay` | integer from 0 to 315360000 |
| PUT | `/projects/:projectid` | `settings.email.config.port` | integer from 1 to 65535 |
| PATCH | `/projects/:projectid` | the same four fields | the same rules as PUT |
| PUT | `/:projectid/project_users` | `max_assigned_chat` | `-1` or integer from 0 to 100000 |
| PUT | `/:projectid/project_users` | `number_assigned_requests` | integer from 0 to 1000000 |
| PUT | `/:projectid/project_users/:project_userid` | `max_assigned_chat`, `number_assigned_requests` | the same rules |
| POST | `/:projectid/departments` | `status` | one of `-1, 0, 1`. `-1` is a hidden department |
| PUT | `/:projectid/departments/:departmentid` | `status` | one of `-1, 0, 1` |
| PATCH | `/:projectid/departments/:departmentid` | `status` | one of `-1, 0, 1` |
| PUT | `/:projectid/leads/:leadid` | `status` | one of `50, 100, 1000` |
| GET | `/:projectid/leads` | `limit`, `page`, `status`, `direction` | `limit` from 1 to 1000; `page` ≥ 0; `status` a lead code; `direction` `-1` or `1` |
| GET | `/:projectid/leads/csv` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1` |
| PUT | `/:projectid/properties/:propertyid` | `status` | one of `100, 1000` |
| GET | `/:projectid/properties` | `limit`, `page`, `status`, `direction` | `limit` from 1 to 1000; `page` ≥ 0; `status` `100` or `1000`; `direction` `-1` or `1` |

## Knowledge base, FAQ, files, logs

| Method | Endpoint | Field | Rule |
| --- | --- | --- | --- |
| GET | `/:projectid/kb` | `limit`, `page`, `status`, `direction` | `limit` from 1 to 1000; `page` ≥ 0; `status` integer from `-1` to 10000; `direction` `-1` or `1` |
| GET | `/:projectid/kb/namespace/export/:id` | `status` | integer from `-1` to 10000 |
| POST | `/:projectid/kb` | `scrape_type` | one of `0, 1, 2, 4` |
| POST | `/:projectid/kb/multi` | `scrape_type` | one of `0, 1, 2, 4` |
| POST | `/:projectid/kb/sitemap/import` | `scrape_type` | one of `0, 1, 2, 4` |
| POST | `/:projectid/kb/namespace/import/:id` | `contents[].scrape_type` | one of `0, 1, 2, 4` |
| GET | `/:projectid/kb/unanswered/:namespace` | `limit`, `page`, `direction` | `limit` from 1 to 100; `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/kb/answered/:namespace` | `limit`, `page`, `direction` | `limit` from 1 to 100; `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/faq` | `limit`, `page` | `limit` from 1 to 10000; `page` ≥ 0 |
| GET | `/:projectid/intents` | `limit`, `page` | same route as `/faq` |
| POST | `/:projectid/files/assets` | `expiration` | seconds, integer from 1 to 315360000. If missing, the file does not expire |
| POST | `/logs/whatsapp` | `status_code` | integer from 0 to 999, required |
| POST | `/:projectid/logs/whatsapp` | `status_code` | integer from 0 to 999, required |

## Lists, sorting and activities

| Method | Endpoint | Field | Rule |
| --- | --- | --- | --- |
| GET | `/:projectid/roles` | `limit`, `page`, `direction` | `limit` from 1 to 1000; `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/segments` | `limit`, `page`, `direction` | `limit` from 1 to 1000; `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/tags` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/subscriptions/history` | `page` | integer ≥ 0 |
| GET | `/:projectid/canned` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/events` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1` |
| GET | `/:projectid/activities` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1`. The `limit` of this list was already capped |
| GET | `/:projectid/activities/csv` | `page`, `direction` | `page` ≥ 0; `direction` `-1` or `1` |

## Already safe, not changed

These lists already discarded negative `page` and `limit` values, bringing them back into range:

- `GET /:projectid/agent-prompts`
- `GET /:projectid/modules/ai-generations/agents/:id_faq_kb/revisions`
