…c#257230)
- Create a new best-effort ESLint rule that checks if `http<method>`
calls are used dangerously: direct path injection
- Adds a new `buildPath` utility that can be used with server-side
routes `/api/myapi/{id}` to safely build and encode path parameters
(**bonus**: server-side path `const`s can be reused by the client
directly, no need to build these separately by hand)
- Updates existing usages
Will flag usages of `http` like:
```ts
core.http.delete(`/api/myapi/${id}`, {...});
```
With a message to use `buildPath` or `encodeURIComponent` in order to
safely encode parameters.
Not strictly needed in this PR, this utility allows for using server
side paths like `/api/myapi/{id}` in a parameterised fashion like:
```ts
import { buildPath } from '@kbn/core-http-browser';
buildPath('/api/dashboard/{id}' /* same as { path: ... } server side */, { id })
// => /api/dashboard/encoded-id
```
Happy to exclude this utility if it simplifies things.
(Made with cursor y'all)
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>
(cherry picked from commit 2d72284)
Summary
Backport #257230 to
8.19.Resolved branch-specific conflicts while keeping the older
8.19dashboard and lens implementations intact.Validation
Could not run
node scripts/check_changes.tsor Jest in the temporary backport repo because dependencies are not bootstrapped there.(Made with cursor y'all)