BFF proxied API responses can plant session cookies, and sign-in reuses the planted server-side session
Description
Impact
Two issues in Duende.BFF combine so that a malicious or compromised remote API that the BFF proxies can take over the session of the next user who signs in on the same browser. The attacker then acts as that user at the BFF, and calls every API behind the BFF with the user's tokens, until the user signs out or the session expires.
- Proxied API responses can set and clear the BFF's cookies. This applies to every proxy mechanism:
MapRemoteBffApiEndpoint, per-frontend remote APIs (WithRemoteApis, 4.x) and YARP routes. On its own, a proxied API can sign the user out, or sign the user in to the attacker's account so that what the user enters goes to the attacker. - With server-side sessions, sign-in reuses an existing session. Anyone who can set the BFF session cookie in a user's browser before sign-in can use the user's session afterwards. Besides issue 1, the cookie can be set from another host on the same site when the session cookie name has no
__Host-prefix (path-based frontends in 4.x use a__Secure-name), or through GHSA-6gxg-chg2-rm9v.
You are not affected by issue 1 if the BFF doesn't proxy remote APIs, and not by issue 2 if it doesn't use server-side sessions. Versions fixed for GHSA-vvg7-p7jw-8qr3 are still affected by this advisory.
Are you affected?
You are affected by issue 1 if your BFF runs a vulnerable version and proxies at least one remote API, for example:
app.MapRemoteBffApiEndpoint("/api/orders", new Uri("https://orders.example.com"));builder.Services.AddBff()
.AddYarpConfig(routes, clusters);new BffFrontend(BffFrontendName.Parse("app"))
.WithRemoteApis(new RemoteApi("/api", new Uri("https://api.example.com")));The risk is highest when the BFF proxies an API that another team or a third party operates, or several APIs with different levels of trust.
You are affected by issue 2, and therefore by the session takeover, if your BFF also uses server-side sessions:
builder.Services.AddBff()
.AddServerSideSessions();After you upgrade:
- The BFF removes
Set-CookieandClear-Site-Datafrom proxied API responses. If you rely on cookies set by a proxied API, for example load balancer affinity cookies, you can turn this off withBffOptions.RemoveCookieHeadersFromProxiedResponses = false. Only do this if you trust every API that the BFF proxies, because it brings back issue 1. - A user who signs in on a browser that still carries another user's session ends up signed out, and has to sign in a second time.
- If you replaced
IServerTicketStorewith your own implementation, upgrading doesn't fix issue 2. Change itsRenewAsyncso that it only updates a session that still exists and belongs to the same user: when the session under the key belongs to another user, remove it instead of giving it to the new user, and when the session no longer exists, don't recreate it.
Workarounds
If you can't upgrade right away, do the following:
- Remove the headers from proxied responses. Add a response transform to every proxied route that removes
Set-CookieandClear-Site-Datafrom the upstream response. For YARP configuration routes, useResponseHeaderRemovefor both headers withWhen: Always; forMapRemoteBffApiEndpoint, pass a custom transform builder. This also removes the session cookie that the BFF writes when it renews the user's access token during a proxied call. Without server-side sessions, the browser then keeps a session cookie with the old tokens, and if your identity provider issues one-time-use refresh tokens, the next renewal fails and the user has to sign in again. With server-side sessions, only the cookie's sliding expiration is affected. - Turn off server-side sessions if you can do without them until you upgrade. This prevents the session takeover (issue 2), but not issue 1 on its own.
- Use a
__Host-session cookie name where you choose the name yourself, so other hosts of the same site can't set it. This doesn't stop a proxied API from setting the cookie.
Credits
Found by Duende Software during an internal security review.
Affected versions
- Duende.BFFFrom 4.3.0 · fixed in 4.3.4
- Duende.BFFFrom 4.2.0-preview.1 · fixed in 4.2.2
- Duende.BFFFrom 4.1.0 · fixed in 4.1.4
- Duende.BFFFrom 4.0.0-preview1 · fixed in 4.0.5
- Duende.BFFFrom 3.1.0-preview.1 · fixed in 3.1.3
- Duende.BFFFrom 3.0.0-preview.1 · fixed in 3.0.2
- Duende.BFFFrom 2.3.0 · fixed in 2.3.2
- Duende.BFFfixed in 2.2.2
- Duende.BFF.YarpFrom 4.3.0 · fixed in 4.3.4
- Duende.BFF.YarpFrom 4.2.0-preview.1 · fixed in 4.2.2
- Duende.BFF.YarpFrom 4.1.0 · fixed in 4.1.4
- Duende.BFF.YarpFrom 4.0.0-preview1 · fixed in 4.0.5
- Duende.BFF.YarpFrom 3.1.0-preview.1 · fixed in 3.1.3
- Duende.BFF.YarpFrom 3.0.0-preview.1 · fixed in 3.0.2
- Duende.BFF.YarpFrom 2.3.0 · fixed in 2.3.2
- Duende.BFF.Yarpfixed in 2.2.2