shreemaan-abhishek opened a new pull request, #13637:
URL: https://github.com/apache/apisix/pull/13637
### Description
The `request_llm_model` / `llm_model` Prometheus labels are derived from
client-supplied model names. Because there is no length bound, an attacker who
can influence the model name in a request can emit arbitrarily long label
values, inflating time-series cardinality and exhausting the
`prometheus-metrics` shared dict (a metrics-cardinality DoS).
This PR bounds the exposure:
1. **Model-name truncation.** All `request_llm_model` / `llm_model` label
call sites in `exporter.lua` now go through a `model_to_label()` helper that:
- truncates string values to **128 bytes**;
- coerces numbers to string and truncates them too;
- maps any non-scalar value (table/function/boolean) to a fixed
`<non-scalar>` sentinel so pointer-based strings never enter the label index.
The full values remain untouched in `ctx.var.request_llm_model` /
`ctx.var.llm_model`; only the metrics path is capped.
2. **Docs.** Documented that operators who do not need per-model breakdowns
can list `request_llm_model` / `llm_model` under `disabled_labels` (already
supported) to collapse them to a single empty-valued series, complementing the
128-byte cap.
### Tests
Added cases to `t/plugin/prometheus-ai-proxy.t`:
- a chat request with a 200-byte model name asserts the `request_llm_model`
label is truncated to exactly 128 bytes (and not 129);
- `disabled_labels` on the LLM metrics collapses two distinct client models
into one empty-valued series.
The `model_to_label()` truncation/sentinel logic was also verified directly
(short string unchanged, 200-char capped to 128, exact-128 unchanged, number
coerced, table/function/boolean mapped to `<non-scalar>`).
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added corresponding test cases
- [x] I have updated the documentation
- [x] `luacheck` passes on the changed Lua file
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]