Case study 01 · Banking · Open Banking / PSD2

Open Banking identity platform (FAPI 2.0 + DPoP)

A bank's consent-based account access for third-party apps, with sender-constrained tokens, strong customer authentication and immediate consent revocation. 27 automated attack tests.

27end-to-end attack tests
21threats modelled (STRIDE)
4architecture decision records

The problem

Under PSD2, banks must let licensed third parties (budgeting apps, lenders) read customer account data, but only with the customer’s explicit consent, only for the accounts they choose, and with security strong enough for financial data. The weak points in most implementations are bearer tokens that work for anyone who steals them, consent that is checked once and then forgotten, and security settings that depend on each client being configured correctly.

Approach

I built the identity and consent layer of a fictional bank (Meridian Bank) and a fictional third-party app (Budgetly), then attacked it with automated tests.

flowchart LR
    tpp["Budgetly (TPP)"] -- "PAR, token: private_key_jwt + DPoP" --> kc["Keycloak<br/>FAPI 2.0 policy<br/>SCA + consent SPI"]
    tpp -- "create / revoke consent" --> cs["Consent service"]
    tpp -- "GET accounts (DPoP)" --> api["Accounts API"]
    kc -- "authorise consent" --> cs
    api -- "live consent check" --> cs
  • FAPI 2.0 by policy, not by convention. A Keycloak client policy applies the FAPI 2.0 profile (PAR, PKCE, private_key_jwt, PS256, DPoP) whenever a client requests the accounts scope. A misconfigured client cannot reach customer data.
  • Sender-constrained tokens. Every access token is bound to the app’s DPoP key. The resource server checks the proof’s method, URL, freshness, token hash and single use.
  • Consent inside the login. A custom Keycloak authenticator (Java SPI) runs after password + OTP. It shows exactly what the app asked for, lets the customer pick accounts, and records the decision. The consent ID travels in the token.
  • Consent checked on every call. The API looks up the consent live, so revocation works immediately even though the token is still valid.

Key decisions

Decision Why
DPoP rather than mTLS Works through any gateway or CDN and adds per-request replay protection
Consent step inside Keycloak One journey for SCA and consent; no second app or session to secure
Live consent check at the API Revocation must not wait for token expiry
Policy triggered by scope Security follows the data, not the client’s settings

What testing revealed

  • Keycloak 26.4 enforces DPoP binding of the authorization code at the authorization endpoint, not at PAR. The control works, but one step later than expected. Documented and covered by a test.
  • Refresh tokens survive consent revocation (the resulting access tokens are refused). Recorded as a known gap, with the production fix.

Results

27 end-to-end tests drive the real login, OTP and consent pages, then attack the system: stolen token with the attacker’s key, Bearer downgrade, replayed proof, proof reused on another URL, forged signature, form tampering, consent reuse, cross-customer access. Each test maps to a threat in the STRIDE model, and each control is mapped to FAPI 2.0, PSD2 RTS, DORA, GDPR and ISO 27001.

← All case studies