1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/services
Thomas Heartman f5fb7b66d1
Fix: validate that the project is correct when getting feature by project (#2344)
## What

This PR fixes a bug where fetching a feature toggle via the
`/api/admin/projects/:projectId/features/:featureName` endpoint doesn't
validate that the feature belongs to the provided project. The same
thing applies to the archive functionality. This has also been fixed.

In doing so, it also adds corresponding tests to check for edge cases,
updates the 403 error response we use to provide clearer steps for the
user, and adds more error responses to the OpenAPI documentation.

## Why

As mentioned in #2337, it's unexpected that the provided project
shouldn't matter at all, and after discussions internally, it was also
discovered that this was never intended to be the case.

## Discussion points

It might be worth rethinking this for Unleash v5. Why does the features
API need the projects part at all when features are unique across the
entire instance? Would it be worth reverting to a simpler feature API
later or would that introduce issues with regards to how different
projects can have different active environments and so on?

### Further improvements

I have _not_ provided schemas for the error responses for the endpoints
at this time. I considered it, but because it would introduce new schema
code, more tests, etc, I decided to leave it for later. There's a
thorough OpenAPI walkthrough coming up, so I think it makes sense to do
it as part of that work instead. I am happy to be challenged on this,
however, and will implement it if you think it's better.

### Why 403 when the project is wrong?

We could also have used the 404 status code for when the feature exists
but doesn't belong to this project, but this would require more (and
more complex) code. We also already use 403 for cases like this for
post, patch, and put. Finally, the [HTTP spec's section on the 403
status code](https://httpwg.org/specs/rfc9110.html#status.403) says the
following (emphasis mine):

> The 403 (Forbidden) status code indicates that the server
**_understood the request but refuses to fulfill it_**. A server that
wishes to make public why the request has been forbidden can describe
that reason in the response content (if any).
>
> If authentication credentials were provided in the request, the server
considers them insufficient to grant access. The client SHOULD NOT
automatically repeat the request with the same credentials. The client
MAY repeat the request with new or different credentials. However, **_a
request might be forbidden for reasons unrelated to the credentials_**.

As such, I think using 403 makes sense in this case.

---

Closes #2337.
2022-11-08 13:34:01 +01:00
..
client-metrics fix: generate all hour buckets if missing (#2319) 2022-11-04 09:30:02 +01:00
access-service.test.ts chore: type improvements (#1941) 2022-08-19 10:28:53 +02:00
access-service.ts Add some extra fields for profile (#2119) 2022-09-30 14:36:45 +03:00
addon-schema.ts feat: support filtering on project and environment fields for events (#1801) 2022-07-12 12:13:25 +00:00
addon-service-test-simple-addon.ts feat: add OpenAPI validation to a few endpoints (#1409) 2022-04-25 14:17:59 +02:00
addon-service.test.ts fix: addon filtering supports wildcards 2022-07-12 15:53:57 +02:00
addon-service.ts fix: addon filtering supports wildcards 2022-07-12 15:53:57 +02:00
api-token-service.test.ts Refactor: rename frontend api key (#1935) 2022-08-18 08:20:51 +00:00
api-token-service.ts feat: add method for migrating proxies without environment validation (#2056) 2022-09-12 13:22:23 +00:00
client-spec-service.test.ts refactor: avoid inlining segments for supported clients (#1640) 2022-06-02 14:07:46 +02:00
client-spec-service.ts refactor: avoid inlining segments for supported clients (#1640) 2022-06-02 14:07:46 +02:00
context-schema.ts feat: add context value descriptions (#1496) 2022-04-19 08:40:07 +02:00
context-service.ts openapi: improve validation testing (#2058) 2022-09-23 15:02:09 +02:00
edge-service.ts Create endpoint that validates tokens for edge (#2039) 2022-09-01 13:26:26 +00:00
email-service.test.ts Hyperlink Injection in People Invitation Emails (#2307) 2022-11-01 10:38:33 +02:00
email-service.ts Hyperlink Injection in People Invitation Emails (#2307) 2022-11-01 10:38:33 +02:00
environment-service.ts feat: enabled environments override now also moves projects and toggles to new environments 2022-03-11 15:52:13 +02:00
event-service.ts feat: add count to event list (#2036) 2022-09-02 08:35:31 +02:00
feature-tag-service.ts feat: clean up events (#1089) 2021-11-12 13:15:51 +01:00
feature-toggle-service.ts Fix: validate that the project is correct when getting feature by project (#2344) 2022-11-08 13:34:01 +01:00
feature-type-service.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
group-service.ts UX additions to groups SSO syncing (#2200) 2022-10-20 10:47:19 +03:00
health-service.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
index.ts Feat/stats service (#2211) 2022-10-25 13:10:27 +02:00
instance-stats-service.ts Feat/stats service (#2211) 2022-10-25 13:10:27 +02:00
openapi-service.ts openapi: improve validation testing (#2058) 2022-09-23 15:02:09 +02:00
pat-service.ts fix: limit total of PATs a user can have (#2301) 2022-11-02 08:11:35 +00:00
playground-service.ts feat(#1873/playground): Return detailed information on feature toggle evaluation (#1839) 2022-08-04 15:41:52 +02:00
project-health-service.ts Wrong number on the project page regarding members in that project (#1917) 2022-08-17 09:05:41 +00:00
project-schema.ts fix: convert schemas to typescript 2021-09-14 20:36:40 +02:00
project-service.ts Backend for profile page (#2114) 2022-09-29 16:27:54 +03:00
proxy-service.ts Fix/frontendapi synchronization (#2100) 2022-09-28 14:23:41 +02:00
public-signup-token-service.ts Hard cap expiry date of public signup token (#2308) 2022-11-01 11:38:18 +02:00
reset-token-service.ts Fix/bcryptjs (#1239) 2022-01-06 20:43:57 +01:00
segment-schema.ts feat: add segments (#1426) 2022-03-29 14:59:14 +02:00
segment-service.ts fixed segments not being copied (#2105) 2022-10-10 15:32:34 +03:00
session-service.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
setting-service.ts feat: add CORS instance settings (#1957) 2022-08-26 09:09:48 +02:00
state-schema.ts feat: add segments (#1426) 2022-03-29 14:59:14 +02:00
state-service-export-v1.json Wip/environments (#880) 2021-07-07 10:46:50 +02:00
state-service.test.ts task: remove displayName from environments (#988) 2021-09-29 10:23:43 +02:00
state-service.ts Import of feature still showing env on feature, when environment is disabled on project (#2209) 2022-10-19 15:05:07 +03:00
state-util.ts fix: update mime library method signature to 2.X (#1078) 2021-11-02 23:43:16 +01:00
strategy-schema.ts fix: Controller wraps handler with try/catch (#909) 2021-08-13 10:36:19 +02:00
strategy-service.ts openapi: improve validation testing (#2058) 2022-09-23 15:02:09 +02:00
tag-schema.test.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
tag-schema.ts fix: Controller wraps handler with try/catch (#909) 2021-08-13 10:36:19 +02:00
tag-service.ts openapi: improve validation testing (#2058) 2022-09-23 15:02:09 +02:00
tag-type-schema.test.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
tag-type-schema.ts fix: import schema needs to understand :global: env 2021-08-26 22:42:06 +02:00
tag-type-service.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
user-feedback-service.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
user-service.test.ts Fix: prevent password reset email flooding (#2076) 2022-09-28 10:24:43 +02:00
user-service.ts Personal access token middleware (#2069) 2022-09-28 16:53:56 +03:00
user-splash-service.ts refactor: add schemas to user admin controller (#1692) 2022-06-22 14:55:43 +02:00
version-service.test.ts fix: attempt to unflake version service tests (#2008) 2022-08-31 08:06:25 +02:00
version-service.ts fix: attempt to unflake version service tests (#2008) 2022-08-31 08:06:25 +02:00