1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01: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
db fix: limit total of PATs a user can have (#2301) 2022-11-02 08:11:35 +00:00
error
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
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
app.ts Feat/enterprise stores (#2289) 2022-10-31 10:35:59 +01:00
create-config.test.ts
create-config.ts fix: merge order for UI config 2022-11-04 14:43:12 +01:00
default-custom-auth-deny-all.ts
event-hook.test.ts
event-hook.ts
logger.test.ts
logger.ts
metric-events.ts
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
server-impl.ts fix: re export knex (#2300) 2022-10-31 10:49:12 +01:00