1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/error
Nuno Góis 0d3dee0e96
fix: validate patched data with schema (#7616)
https://linear.app/unleash/issue/2-2453/validate-patched-data-against-schema

This adds schema validation to patched data, fixing potential issues of
patching data to an invalid state.

This can be easily reproduced by patching a strategy constraints to be
an object (invalid), instead of an array (valid):

```sh
curl -X 'PATCH' \
  'http://localhost:4242/api/admin/projects/default/features/test/environments/development/strategies/8cb3fec6-c40a-45f7-8be0-138c5aaa5263' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "path": "/constraints",
    "op": "replace",
    "from": "/constraints",
    "value": {}
  }
]'
```

Unleash will accept this because there's no validation that the patched
data actually looks like a proper strategy, and we'll start seeing
Unleash errors due to the invalid state.

This PR adapts some of our existing logic in the way we handle
validation errors to support any dynamic object. This way we can perform
schema validation with any object and still get the benefits of our
existing validation error handling.

This PR also takes the liberty to expose the full instancePath as
propertyName, instead of only the path's last section. We believe this
has more upsides than downsides, especially now that we support the
validation of any type of object.


![image](https://github.com/user-attachments/assets/f6503261-f6b5-4e1d-9ec3-66547d0d061f)
2024-07-18 13:26:50 +01:00
..
archivedfeature-error.ts fix: return 400 when enabling env of archived toggle (#6049) 2024-01-26 16:02:17 +02:00
bad-data-error.ts fix: validate patched data with schema (#7616) 2024-07-18 13:26:50 +01:00
content-type-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
db-error.ts
disabled-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
exceeds-limit-error.test.ts chore: send prometheus metrics when someone tries to exceed resource limits (#7617) 2024-07-18 13:35:45 +02:00
exceeds-limit-error.ts chore: send prometheus metrics when someone tries to exceed resource limits (#7617) 2024-07-18 13:35:45 +02:00
feature-has-tag-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
forbidden-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
from-legacy-error.ts chore: Bump biome and configure husky (#6589) 2024-03-18 13:58:05 +01:00
incompatible-project-error.ts chore!: [v6] remove error.description in error messages (#7157) 2024-05-27 11:26:19 +02:00
index.ts fix: export NotFoundError and ISegmentService in internals.ts (#4997) 2023-10-11 14:31:45 +03:00
invalid-operation-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
invalid-token-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
minimum-one-environment-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
name-exists-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
not-implemented-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
notfound-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
operation-denied-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
owasp-validation-error.ts chore: Bump biome and configure husky (#6589) 2024-03-18 13:58:05 +01:00
password-mismatch.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
password-previously-used.ts feat: Disallow repeating last 5 passwords. (#7552) 2024-07-09 16:18:35 +02:00
password-undefined.ts chore!: [v6] remove error.description in error messages (#7157) 2024-05-27 11:26:19 +02:00
pattern-error.ts chore: Bump biome and configure husky (#6589) 2024-03-18 13:58:05 +01:00
permission-error.ts chore: Bump biome and configure husky (#6589) 2024-03-18 13:58:05 +01:00
project-without-owner-error.ts chore!: [v6] remove error.description in error messages (#7157) 2024-05-27 11:26:19 +02:00
rate-limit-error.ts feat: Disallow repeating last 5 passwords. (#7552) 2024-07-09 16:18:35 +02:00
role-in-use-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
unauthorized-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00
unleash-error.test.ts fix: validate patched data with schema (#7616) 2024-07-18 13:26:50 +01:00
unleash-error.ts feat: Disallow repeating last 5 passwords. (#7552) 2024-07-09 16:18:35 +02:00
used-token-error.ts refactor: move status codes into classes (#4200) 2023-07-11 09:20:11 +02:00