You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`get_flags` automatically builds an `EvalContext` from the incoming request headers (`x-user-id`, `x-tenant-id`) and returns a `Flags` instance backed by `app.flags`.
23
+
`get_flags` returns a `Flags` instance backed by `app.flags` with an `EvalContext` that exposes the raw request headers via `ctx.headers`. **It does not infer identity from headers** — `ctx.user_id` and `ctx.tenant_id` are always `None`. Identity must come from an authenticated dependency that *you* wire in (see [EvalContext](#evalcontext)).
24
+
25
+
!!! warning "Why identity isn't lifted from headers (CWE-290)"
26
+
Previous releases (< 0.1.6) read `X-User-Id` / `X-Tenant-Id` request headers straight into `ctx.user_id` / `ctx.tenant_id`. That trusted attacker-controlled input as the targeting identity — any client could claim any user / tenant by setting the header and bypass flag gates on admin previews, beta features, or pricing experiments. 0.1.6 removed that read; the headers are still on `ctx.headers` for non-identity targeting (region, A/B variant, locale).
24
27
25
28
---
26
29
@@ -126,7 +129,31 @@ ctx = EvalContext(
126
129
)
127
130
```
128
131
129
-
`get_flags`auto-populates `user_id` and `tenant_id` from `x-user-id` / `x-tenant-id` request headers. Custom providers can use these fields to implement percentage rollouts, user allowlists, and tenant overrides.
132
+
`get_flags`always returns an `EvalContext` with `user_id=None` / `tenant_id=None` — see the warning in [Quick start](#quick-start). Build a richer context from an authenticated dependency yourself:
133
+
134
+
```python
135
+
from hawkapi import Depends
136
+
from hawkapi.flags import EvalContext, Flags, get_flags
137
+
138
+
async def authed_flags(
139
+
flags: Flags = Depends(get_flags),
140
+
user = Depends(current_user), # your own auth dependency
Custom providers can use these fields to implement percentage rollouts, user allowlists, and tenant overrides — once identity is derived from a trusted source.
0 commit comments