tapir JS client: send the pac4j CSRF token on every request, and set the session cookie Secure flag behind a path callbackBase #72
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
iterative-works/support#72
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
MEDECA (medeca-modul-poptavky, MEDECA-552) protects its server-rendered routes with pac4j CSRF (
csrfTokenmatcher +csrfCheckauthorizer). The token is rendered into<meta name="csrf-token">and htmx sends it as thepac4jCsrfTokenheader. The JSON/file API (/api,/zadatel/api) has no CSRF check yet, because the ScalaJS clients built from this library cannot send the token.Facts (v0.1.26):
tapir/shared/.../LiveClientEndpointFactory.scala:31is the single place every tapir client request is built; it already addsX-Requested-With: XMLHttpRequest.tapir/js/.../CustomTapirPlatformSpecific.scala:14-23builds theFetchZioBackend(clientLayer).files/adapters/rest/js/.../LiveFileStore.scalauploads through the same factory.Content-Type, so a cross-sitetext/plainform reaches a JSON endpoint without a CORS preflight. OnlySameSite=Laxonpac4jSessionIdstops it today.server/http/.../pac4j/Pac4jConfigFactory.scala:30-38sets the session cookiesecure = callbackBase.startsWith("https://"). Applications that configurecallbackBaseas a path (MEDECA:/oauth2) never get theSecureflag.Proposal
meta[name="csrf-token"], name configurable) at request time and send it as a configurable header (defaultpac4jCsrfToken) on every non-GET request built byLiveClientEndpointFactory(or by a backend wrapper installed byclientLayer). No token in the page -> no header.Secureflag configurable (or derive it from the externally visible base URL) instead of inferring it fromcallbackBase.Interim in MEDECA
MEDECA-552 wraps the sttp backend in the application (a
DelegateSttpBackendthat adds the header) and usesLiveClientEndpointFactory.layerwith it. Once this issue ships, that wrapper is removed.