1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib
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
..
__snapshots__ fix: generate all hour buckets if missing (#2319) 2022-11-04 09:30:02 +01:00
addons fix: slack back link url to point to the feature page (#2128) 2022-10-05 11:30:51 +02:00
db fix: limit total of PATs a user can have (#2301) 2022-11-02 08:11:35 +00:00
error fix: changeRole to assign roles without existing members 2022-03-03 14:33:32 +01:00
middleware refactor: remove PAT experimental flag (#2299) 2022-10-31 09:38:30 +00:00
openapi OpenAPI(feat): add new 'Segments' tag (#2241) 2022-10-27 10:40:32 +02:00
proxy Fix/embedded proxy memory leak (#2345) 2022-11-08 12:35:53 +01:00
routes Fix: validate that the project is correct when getting feature by project (#2344) 2022-11-08 13:34:01 +01:00
schema Feat/add alias to api tokens (#1931) 2022-08-19 10:48:33 +02:00
services Fix: validate that the project is correct when getting feature by project (#2344) 2022-11-08 13:34:01 +01:00
types fix: generate all hour buckets if missing (#2319) 2022-11-04 09:30:02 +01:00
util fix: generate all hour buckets if missing (#2319) 2022-11-04 09:30:02 +01:00
app.test.ts feat: add support for cdnPrefix for static assets (#1191) 2022-01-06 10:31:00 +01:00
app.ts Feat/enterprise stores (#2289) 2022-10-31 10:35:59 +01:00
create-config.test.ts feat: add CORS instance settings (#1957) 2022-08-26 09:09:48 +02:00
create-config.ts fix: merge order for UI config 2022-11-04 14:43:12 +01:00
default-custom-auth-deny-all.ts fix: default custom auth hook now denies all requests to api endpoints (#811) 2021-04-29 15:18:58 +02:00
event-hook.test.ts fix: convert event-hook.test.js to typescript 2021-09-14 19:34:35 +02:00
event-hook.ts fix: Stores as typescript and with interfaces. (#902) 2021-08-12 15:04:37 +02:00
logger.test.ts fix: convert more tests to typescript 2021-09-14 20:30:37 +02:00
logger.ts feat: add option for LOG_LEVEL (#803) 2021-04-23 15:31:12 +02:00
metric-events.ts fix: refactor event types 2021-04-29 10:21:29 +02:00
metrics.test.ts Feat/stats service (#2211) 2022-10-25 13:10:27 +02:00
metrics.ts Feat/stats service (#2211) 2022-10-25 13:10:27 +02:00
server-impl.test.ts fix: Do not call store function in constructor 2022-09-15 09:48:14 +02:00
server-impl.ts fix: re export knex (#2300) 2022-10-31 10:49:12 +01:00