Repository navigation
Replies: 1 comment
|
Fixed in 3.2.0 release. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description
After upgrading to Skoruba 3.1.0, logout fails when the Admin UI is hosted under a subpath, for example:
https://identity.example.com/admin/web/
Clicking Logout navigates to /admin/web/account/logout and displays a JSON error instead of completing logout:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.4",
"title": "Invalid CSRF token",
"status": 403,
"detail": "The required antiforgery cookie "__Host-SkorubaBFF-CSRF" is not present."
}
Investigation
The frontend successfully calls POST /admin/web/csrf/gettoken and receives a request verification token. However, the response sets the antiforgery cookie with these attributes:
__Host-SkorubaBFF-CSRF=; path=/admin/web; secure; samesite=strict; httponly
Cookies with the __Host- prefix require Secure, Path=/, and no Domain attribute. Consequently, the browser rejects this cookie, and the subsequent logout request has a form token but no corresponding antiforgery cookie.
Suspected Cause
In StartupService.AddAntiForgeryProtection, the cookie name is configured as __Host-SkorubaBFF-CSRF, but its path is not explicitly configured. When the application runs under a subpath, the resulting cookie path appears to follow that subpath.
The response was observed behind a reverse proxy, so proxy cookie-path rewriting should also be ruled out.
Suggested Fix
Explicitly configure the cookie path:
services.AddAntiforgery(o =>
{
o.Cookie.Name = "__Host-SkorubaBFF-CSRF";
o.Cookie.Path = "/"; <------- Add this line
o.Cookie.HttpOnly = true;
o.Cookie.SecurePolicy = CookieSecurePolicy.Always;
o.Cookie.SameSite = SameSiteMode.Strict;
});
This preserves the __Host- protections without changing the application's base path or disabling CSRF validation.
Would this be the intended configuration for deployments under a subpath? A regression test covering antiforgery cookie attributes with a non-root PathBase would also help prevent this issue.
All reactions