<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Piotr Honik on Medium]]></title>
        <description><![CDATA[Stories by Piotr Honik on Medium]]></description>
        <link>https://medium.com/@piotr.honik?source=rss-18166cdd9aac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*71aEfvPa6PzCJAQx</url>
            <title>Stories by Piotr Honik on Medium</title>
            <link>https://medium.com/@piotr.honik?source=rss-18166cdd9aac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:16:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piotr.honik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stolen OAuth tokens: what DPoP fixes, and what it doesn’t]]></title>
            <link>https://medium.com/@piotr.honik/stolen-oauth-tokens-what-dpop-fixes-and-what-it-doesnt-644779d53b6e?source=rss-18166cdd9aac------2</link>
            <guid isPermaLink="false">https://medium.com/p/644779d53b6e</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[dpop]]></category>
            <dc:creator><![CDATA[Piotr Honik]]></dc:creator>
            <pubDate>Fri, 23 Oct 2026 08:54:43 GMT</pubDate>
            <atom:updated>2026-10-23T08:54:43.761Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Where DPoP is now the default, where it falls short, and how to choose.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mPfcxV8wpRGacZpFGksEw.png" /></figure><h3>The short version</h3><ul><li>A bearer token works for whoever holds it, which is why stolen tokens keep being used.</li><li>DPoP (Demonstrating Proof of Possession) ties a token to a private key, so a thief needs both. That helps most when the key is kept somewhere other than the token.</li><li>It does not help against a thief inside the client, a stolen session cookie, or a request changed on the way. Where the key lives is the real decision.</li></ul><p>In August 2025, attackers got into the cloud CRM accounts of many companies. <a href="https://cloud.google.com/blog/topics/threat-intelligence/data-theft-salesforce-instances-via-salesloft-drift">Google’s threat intelligence group reported</a> that they did it with OAuth tokens tied to a third-party chat tool those companies had connected to their accounts. The attackers did not need passwords. They used keys that were already valid.</p><p><a href="https://trust.salesloft.com/?uid=Drift%2FSalesforce+Security+Notification">The chat tool’s vendor later said</a>, with help from an outside incident-response firm, that the attackers had reached its own cloud and taken the tokens there, after starting in its GitHub account. The tokens were revoked on 20 August, after at least ten days of use.</p><p>This is not a one-off. In 2022, <a href="https://github.blog/2022-04-15-security-alert-stolen-oauth-user-tokens/">GitHub reported</a> that stolen OAuth tokens from two integrators were used to download private repositories from dozens of organizations. Same shape: a token leaves the place it was meant to stay, and whoever holds it gets in.</p><p>In February 2023 I <a href="https://medium.com/@piotr.honik/protect-your-oauth-2-0-tokens-against-replay-attacks-fb72f37954d0">wrote about DPoP</a> while it was still a draft. Since then it has become <a href="https://www.rfc-editor.org/rfc/rfc9449.html">RFC 9449</a>. <a href="https://www.rfc-editor.org/rfc/rfc9700.html">RFC 9700</a> now asks servers to sender-constrain access tokens (tie them to the client’s key), and wallets and Bluesky require DPoP. This article is for architects: instead of walking through the protocol, I ask whether DPoP is the right control for a system, and where it stops helping. Where I go beyond what the specs say, I say so in the sentence, and fast-moving status is dated as of October 2026.</p><h3>Meet attacker A5</h3><p>The OAuth security guidance (<a href="https://www.rfc-editor.org/rfc/rfc9700.html">RFC 9700</a>) has a name for this thief: attacker A5, someone who has got hold of an access token. A5 does not need to break the login, because a bearer token is like cash: whoever holds it can spend it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6qTxECoDZE-7_gAGNUMfA.png" /><figcaption>Figure 1. The same stolen token, with and without DPoP. It only helps if the key is kept somewhere other than the token.</figcaption></figure><p>With DPoP, the token is tied to a private key, so A5 needs the key too. If it lives somewhere else, the stolen token is just text. What DPoP cannot stop is a stolen session cookie, as in <a href="https://sec.okta.com/articles/2023/11/unauthorized-access-oktas-support-case-management-system-root-cause/">a 2023 breach at an identity provider’s support system</a>, or a client that can sign for itself. DPoP protects the token. It does not protect the client.</p><h3>Four controls, four different questions</h3><p>Four controls come up whenever people talk about stolen tokens, and they are not rivals. DPoP and mutual TLS (mTLS) ask “who is holding this token?” Audience restriction asks “where can this token be used?” A backend for frontend (BFF), a server-side helper that keeps tokens away from the browser, asks “where do the tokens live?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkzTEXDn9ZHs0d6c5Rz_Cg.png" /><figcaption>Figure 2. Where each control sits between the client and the API</figcaption></figure><ul><li>They stack. <a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-2.2.1">RFC 9700 asks for both</a>: sender-constrained tokens (DPoP or mTLS), and tokens limited to one API or a small set (§2.3).</li><li>mTLS lets one token work across several APIs, but <a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-1">RFC 9449</a> says poor browser support rules it out for single-page apps.</li><li>In my view, audience restriction would not have stopped either of the thefts described at the start, because the tokens were used at the API they were made for. I think DPoP or mTLS would have helped only if the keys were not stolen along with the tokens (see <a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-4.10.1">RFC 9700 §4.10.1</a>).</li><li>For browser apps, the <a href="https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-26.txt">browser-apps draft</a> (version 26 from December 2025, the latest I found, and still a draft) strongly recommends a BFF for business, sensitive and personal-data apps.</li></ul><h3>Three places where DPoP is already the default</h3><p>DPoP started as a draft that nobody had to use. Today three ecosystems expect it, for different reasons.</p><p><strong>Banks and open data: FAPI 2.0.</strong> The <a href="https://openid.net/specs/fapi-security-profile-2_0-final.html">Financial-grade API (FAPI) 2.0 Security Profile</a>, final since February 2025, requires sender-constrained tokens using mTLS or DPoP (<a href="https://openid.net/specs/fapi-security-profile-2_0-final.html#section-5.3.2.1">§5.3.2.1</a>), but covers confidential clients only (<a href="https://openid.net/specs/fapi-security-profile-2_0-final.html#section-5.1.1">§5.1.1</a>).</p><p><strong>Digital wallets: HAIP.</strong> The <a href="https://openid.net/specs/openid4vc-high-assurance-interoperability-profile-1_0-final.html">High Assurance Interoperability Profile</a> (HAIP) became final on 24 December 2025 and requires wallets and issuers to support DPoP for credential issuance (§4).</p><p><strong>Bluesky: the AT Protocol.</strong> The <a href="https://atproto.com/specs/oauth">AT Protocol (atproto) OAuth profile</a> makes DPoP mandatory for every client type, with mandatory server nonces, and browser apps are allowed. It makes the opposite bet to FAPI: DPoP for everyone, with short-lived tokens.</p><p>Starting smaller is possible. <a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-5">RFC 9449</a> lets a server issue plain bearer access tokens and still bind the refresh token to the client’s key.</p><p>Product support varies. As of October 2026, <a href="https://www.keycloak.org/docs/26.4.1/release_notes">Keycloak</a> has supported DPoP fully since version 26.4, and <a href="https://developer.okta.com/docs/release-notes/2023/">Okta</a> made it generally available in March 2023, six months before the RFC. <a href="https://auth0.com/docs/secure/sender-constraining/demonstrating-proof-of-possession-dpop">Auth0</a> lists it as Early Access, and I could not find DPoP documentation for <a href="https://learn.microsoft.com/entra/msal/dotnet/advanced/proof-of-possession-tokens">Microsoft Entra ID</a>.</p><h3>Four things DPoP does not fix</h3><p>DPoP answers one question well: can a thief use a stolen token? Four cases sit outside that question.</p><p><strong>1. A thief inside the client.</strong> <a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-11.4">RFC 9449</a> says that once an attacker can run code in the client, it can no longer promise DPoP’s protection. A key that cannot be exported cannot be copied, but the attacker can still ask it to sign new proofs while the client is online.</p><p><strong>2. The silent second login.</strong> In a browser app, attacker code can open a hidden frame and run a fresh sign-in with the user’s existing session, then tie the new tokens to its own key. The <a href="https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-26.txt">browser-apps draft</a> (§5.1.3) says DPoP does not help here, and its answer is a BFF, where the attacker cannot redeem the code (§6.1.4.2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLdptDEvDtyVYyWjlk-AhQ.png" /><figcaption>Figure 3. The silent second login: new tokens, bound to the attacker’s own key.</figcaption></figure><p><strong>3. Changes to the request.</strong> A DPoP proof covers the HTTP method and URL and nothing else, so <a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-11.7">RFC 9449</a> leaves the body and headers to TLS. The <a href="https://openid.net/specs/fapi-security-profile-2_0-final.html#section-6.2">FAPI profile</a> gives a payment as the example: someone holding a proof might change the amount or the account. It suggests reducing that risk with short-lived nonces, a check that each proof’s unique ID (jti) is used only once, or signed requests, and it names mTLS as an alternative to DPoP.</p><p><strong>4. Secrets that are not OAuth tokens.</strong> In a 2023 breach at an identity provider, <a href="https://sec.okta.com/articles/2023/11/unauthorized-access-oktas-support-case-management-system-root-cause/">session tokens inside support files</a> were replayed, and DPoP does not bind a browser session. One affected customer’s <a href="https://blog.cloudflare.com/thanksgiving-2023-security-incident">later breach</a> used credentials that had not been rotated. Binding tokens to keys does not help with a credential nobody knows is still alive.</p><p>So DPoP guards the token, not the place around it.</p><h3>Three decisions to consider</h3><p>Rolling out DPoP means settling how replayed proofs are handled, where proofs get checked, and what happens at APIs that still accept plain bearer tokens.</p><p><strong>1. How is proof replay stopped?</strong> You can combine three tools:</p><ul><li>A short time window (<a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-11.1">RFC 9449</a> says servers must accept a proof only briefly).</li><li>Tracking each proof’s jti (strong, but hard when servers share no state).</li><li>Server nonces, which also stop proofs made in advance (§11.2).</li></ul><p>I would consider using a short window plus nonces, and adding jti tracking where sharing state between servers is not an issue.</p><p><strong>2. Where are proofs checked?</strong> Either at the API or at a gateway in front of it, and a gateway means the services behind it have to trust it. Introspection (asking the authorization server about a token) does not check the proof; it only returns the hash of the key the token is bound to, so the API or gateway still has to do the check itself (<a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-6.2">RFC 9449 §6.2</a>). Behind a TLS-terminating proxy, the server may see a different URL from the one the proof names (<a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-4.3">§4.3</a>), and it can reject valid proofs unless it rebuilds the public URL, which is what Auth0’s <a href="https://github.com/auth0/go-jwt-middleware/pull/363">Go middleware</a> supports with trusted proxies.</p><p><strong>3. What does an API that accepts Bearer do with a DPoP-bound token?</strong> It depends on whether the API knows about DPoP. If it supports both schemes, it must reject a DPoP-bound token sent as Bearer (<a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-7.2">RFC 9449 §7.2</a>). If it has never heard of DPoP, it will probably accept the token as a plain bearer token, which defeats the purpose of enabling DPoP for that API.</p><h3>Where the key lives</h3><p>How well DPoP protects a token depends on where its private key lives. <a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-4.10.1">RFC 9700</a> says that if an attacker gets both the token and the key, the protection is gone, while a key held in a security module still protects the token when the client is offline. I would decide where the key lives before choosing DPoP.</p><ul><li>In a browser app, the key can be non-exportable (<a href="https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-26.txt">browser-apps draft</a>, §6.3.4.2.2). That keeps tokens from being copied out, but not from code running in the page (see “Four things DPoP does not fix”).</li><li>On mobile, Apple’s Secure Enclave (<a href="https://developer.apple.com/tutorials/data/documentation/security/protecting-keys-with-the-secure-enclave.md">P-256 keys only</a>) and the <a href="https://developer.android.com/privacy-and-security/keystore">Android Keystore</a> keep the key out of the app’s reach.</li><li>On a server, the key belongs in a hardware security module or a cloud key service (<a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-4.10.1">RFC 9700 §4.10.1</a>). I would not keep it next to the tokens it protects, as the 2025 case at the start of this article suggests.</li></ul><p>A key change is cheap or expensive depending on the refresh token. A public client’s refresh token is tied to its key (<a href="https://www.rfc-editor.org/rfc/rfc9449.html#section-5">RFC 9449 §5</a>), so I expect a lost key to mean signing in again. A confidential client’s refresh token is not tied to its key, so a new key can probably pick up where the old one stopped.</p><h3>Agents and MCP: a work in progress</h3><p>AI agents are the same thief problem on a bigger scale: one agent may hold tokens for many services and run unwatched. The Model Context Protocol (MCP), which many agents use to reach tools, is where this is being worked out. Everything in this section is as of October 2026 and may well have moved since.</p><p><strong>What MCP asks for today.</strong> MCP already asks clients to name the server they want a token for (<a href="https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/security-considerations">resource indicators</a>), servers to <a href="https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization">check the audience</a>, access tokens to be short-lived, and public clients to rotate refresh tokens. That is audience restriction, short lifetimes and rotation, but not sender-constraint.</p><p><strong>What is proposed.</strong> <a href="https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1932">SEP-1932</a> is a proposal for a DPoP profile for MCP, planned as an optional extension. It was opened on 5 December 2025 and, as of October 2026, is still marked Draft with changes requested.</p><p><strong>Can it be built today?</strong> Not evenly. The Python SDK’s <a href="https://github.com/modelcontextprotocol/python-sdk/releases/tag/v2.0.0">v2.0.0 release notes</a> say client DPoP is not implemented yet, and a <a href="https://workos.com/blog/mcp-sdk-dpop-and-scope-challenges">vendor blog</a> says the TypeScript SDK added client helpers in 2.1.0, which I could not confirm.</p><p><strong>What I would do in the meantime:</strong> start from what MCP already requires, keep tokens out of logs and caches, and treat the agent’s key like a server key (see “Where the key lives”). So for agents today, DPoP looks like something to watch, not something to design around.</p><h3>My checklist for a design review</h3><p>Three questions come before any product choice: where could a token be stolen from, who will hold the key, and what kind of client is it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77EKHp2jdIN-snNsSXGtsg.png" /><figcaption>Figure 4. A starting point for choosing a control, based on the checklist below.</figcaption></figure><p><strong>I lean towards DPoP</strong> if the clients are public, such as mobile apps, if proxies break mTLS, or if the ecosystem already expects it, and if the key can be kept apart from the tokens.</p><p><strong>I would go with mTLS</strong> if the clients are servers, I control TLS end to end, and one token has to work across several APIs (<a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-4.10.2">RFC 9700 §4.10.2</a>). For browser apps it is hard to recommend.</p><p><strong>I would consider a BFF</strong> for browser apps that handle business, sensitive or personal data, since DPoP alone does not stop the silent second login (see “Four things DPoP does not fix”).</p><p><strong>Irrespective of the control, these also matter:</strong> one API per token and short lifetimes (<a href="https://www.rfc-editor.org/rfc/rfc9700.html#section-2.3">RFC 9700 §2.3</a>); the key kept apart from the tokens; a list of every long-lived credential, rotated after an incident; and a plan for a lost key.</p><p><strong>One case the flow does not cover.</strong> If a vendor holds tokens for my users, as in the 2025 case at the start of this article, I would look at DPoP or mTLS, keys kept apart from the tokens, short-lived tokens and one API per token.</p><h3>DPoP today</h3><p>Three years ago, DPoP was an IETF draft. Today it is a published standard, and wallets and Bluesky already expect it. It does not cover a thief inside the client, a stolen session cookie or a changed request, and for those I would look at other controls.</p><p>Before choosing a control, I would want three answers: which thief I am worried about, where the key will live, and whether audience restriction, short-lived tokens and a rotation plan are in place whatever else I choose.</p><p>In the 2025 case at the start of this article, whoever held the stolen tokens could use them. With a DPoP-bound token and the key kept somewhere else, I think that could have gone differently, because the thieves would have needed the key as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=644779d53b6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protect your OAuth 2.0 tokens against replay attacks]]></title>
            <link>https://medium.com/@piotr.honik/protect-your-oauth-2-0-tokens-against-replay-attacks-fb72f37954d0?source=rss-18166cdd9aac------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb72f37954d0</guid>
            <category><![CDATA[web-application-security]]></category>
            <category><![CDATA[token-replay-prevention]]></category>
            <category><![CDATA[dpop]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Piotr Honik]]></dc:creator>
            <pubDate>Mon, 27 Feb 2023 21:25:47 GMT</pubDate>
            <atom:updated>2023-02-27T21:25:47.534Z</atom:updated>
            <content:encoded><![CDATA[<p>Secure implementation of the authorization process in a single-page application (SPA) is inherently difficult, owing mainly to the fact that its logic resides and is run entirely inside a web browser. One of the biggest challenges is, invariably, protecting access and refresh tokens stored in browser storage. A common attack scenario on SPAs is to execute malicious code in the context of such an application, i.e., perform an XSS attack to steal one of or both of the tokens. Since those tokens are bearer tokens, once they are stolen, nothing stops an attacker from using them, thus impersonating the legitimate user.</p><h4>What is DPoP?</h4><p>To quote the IETF draft <a href="https://datatracker.ietf.org/doc/html/draft-ietf-oauth-dpop">OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)</a>, it is:</p><blockquote>a mechanism for sender-constraining OAuth2.0 tokens via a proof-of-possession mechanism on the application level. This mechanism allows for detection of replay attacks with access and refresh tokens.</blockquote><p>In other words, DPoP lets us limit the usage of access and refresh tokens to a client which presents proof that they are in possession of a private key. Such a private key is never transmitted over network, only its corresponding public key is presented to the server for signature verification, effectively letting the token to be bound to the public key and constraining their use to this client.</p><p><em>Why wouldn’t the attacker attempt to steal the private key along with the access token then? Key management is outside the scope of DPoP specification, it is however worth noting, that with the help of </em><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API"><em>Web Crypto API</em></a><em> we can generate a non-extractable private key, to be used as a security primitive for all the required cryptographic operations. Such a primitive cannot be dumped or copied as easily as access tokens, neither can it be saved to local storage. See the specification to learn more.</em></p><h4>DPoP token</h4><p>The following block shows a typical DPoP token before being encoded:</p><pre>{<br>  &quot;typ&quot;:&quot;dpop+jwt&quot;,<br>  &quot;alg&quot;:&quot;ES256&quot;,<br>  &quot;jwk&quot;: {<br>    &quot;kty&quot;:&quot;EC&quot;,<br>    &quot;x&quot;:&quot;l8tFrhx-34tV3hRICRDY9zCkDlpBhF42UQUfWVAWBFs&quot;,<br>    &quot;y&quot;:&quot;9VE4jf_Ok_o64zbTTlcuNJajHmt6v9TDVrU0CdvGRDA&quot;,<br>    &quot;crv&quot;:&quot;P-256&quot;<br>  }<br>}<br>.<br>{<br>  &quot;jti&quot;:&quot;-BwC3ESc6acc2lTc&quot;,<br>  &quot;htm&quot;:&quot;POST&quot;,<br>  &quot;htu&quot;:&quot;https://server.example.com/token&quot;,<br>  &quot;iat&quot;:1562262616<br>}</pre><p>Let’s go through the contents of the token.</p><h4>Header</h4><p>The header must at least contain parameters shown in the code block above:</p><ul><li>typ parameter must have a value of dpop+jwt</li><li>alg must have a value indicating usage of an asymmetrical algorithm</li><li>jwk must contain public key in JWK format [<a href="https://www.rfc-editor.org/rfc/rfc7515.txt">RFC7515</a>]</li></ul><h4>Payload</h4><p>The payload must at least contain the following claims:</p><ul><li>jti must contain a unique identifier of the DPoP token</li><li>htm must contain the method of request</li><li>htu must contain the HTTP target URI without query params of the request</li><li>iat must contain timestamp when the token was created</li></ul><p>There is one more claim to be set in the payload, but only after the access token has been issued and bound to the DPoP proof:</p><ul><li>ath must contain a valid hash of the access token, which is bound to the DPoP proof</li></ul><p>This claim is required by the resource server as much as the access token itself. Binding the access token to the proof prevents the attacker from using a DPoP proof with a different token, e.g., when the client holds more than one access token, or after the token has been rotated.</p><h3>Binding the access token</h3><p>For the access token to be bound to the DPoP proof, an access token request made by the client, e.g., during the last stage of the authorization code flow exchange, must contain a DPoP header with the proof-of-possession token described above. The authorization server should then issue the access token with an additional claim, indicating that the token itself is bound to a public key in the DPoP proof.</p><p>The payload of an access token bound to a DPoP proof contains an additional claim cnf with a member property jkt holding a JWK thumbprint [<a href="https://www.rfc-editor.org/info/rfc7638">RFC7638</a>] of the public key in the DPoP proof:</p><pre>{<br>  &quot;sub&quot;:&quot;someone@example.com&quot;,<br>  &quot;iss&quot;:&quot;https://server.example.com&quot;,<br>  &quot;nbf&quot;:1562262611,<br>  &quot;exp&quot;:1562266216,<br>  &quot;cnf&quot;:<br>  {<br>    &quot;jkt&quot;:&quot;0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I&quot;<br>  }<br>}</pre><p>If the authorization server supports DPoP, then a token response similar to the following should be returned:</p><pre>HTTP/1.1 200 OK<br>Content-Type: application/json<br>Cache-Control: no-store<br><br>{<br> &quot;access_token&quot;: &quot;Kz~8mXK1EalYznwH-LC-1fBAo.4Ljp~zsPE_NeO.gxU&quot;,<br> &quot;token_type&quot;: &quot;DPoP&quot;,<br> &quot;expires_in&quot;: 2677,<br> &quot;refresh_token&quot;: &quot;Q..Zkm29lexi8VnWg2zPW1x-tgGad0Ibc3s3EwM_Ni4-g&quot;<br>}</pre><p>Notice that, the response from an authorization server supporting the specification, contains a parameter token_type with a value of DPoP, instead of Bearer.</p><h3>Resource access</h3><p>Since the client has now been issued a token bound to the DPoP proof, resource access requires that the client proves possession of the same private key that was used to sign the DPoP token, presented to the token endpoint of the authorization server, i.e., each request must contain, aside from the access token itself, a DPoP proof token with a valid matching public key.</p><p>To validate the request, the resource server makes sure that all of the following are true:</p><ul><li>DPoP token is signed and the signature verifies against the public key in the JWT header of the DPoP proof</li><li>Public key in the JWT header of the DPoP proof matches the JKT thumprint in the access token</li><li>Hash of the access token equals the value of the ath claim in the DPoP token’s payload</li><li>HTTP method of the current request and the target URI both match htm and htu claims of the proof, respectively</li><li>DPoP token meets the remaining requirements as described in the specification draft</li></ul><h3>Replay prevention</h3><p>Once we have the access token bound to the DPoP proof, for the request to be validated, it must contain the access token as well as a valid DPoP header, which the token is bound to. So the token itself is safeguarded against replays... Or is it?</p><p>Suppose the attacker has enough control of the network to successfully log a single request, complete with an access token and proof. They will not be able to replay such stolen access token in a request targeted to different URI or using a different HTTP method, as the intercepted proof wouldn’t then be validated. Neither will they be able to forge a DPoP proof for any other request URI, not having access to the private key. Nothing stops them, however, from replaying the exact same request they intercepted. So without any further safeguards the attacker is, in fact, limited to a single URI but they can make the same request repeatedly and their window of opportunity for a successful replay spans the remaining time before token expiration.</p><h3>DPoP Nonce</h3><p>To limit the window when the DPoP proof is valid, the specification introduces optional server-side nonce mechanism. Similarly to a general nonce pattern, DPoP nonce creates a constraint on the use of a DPoP proof. The specification doesn’t form any requirements on how to implement it, but typically such a nonce is being controlled by the server, possibly cached, and is used to limit how many times a DPoP proof can be used or to place a general expiration time on it.</p><p>After having implemented DPoP nonce the proof before encoding looks like this:</p><pre>{<br>  &quot;typ&quot;:&quot;dpop+jwt&quot;,<br>  &quot;alg&quot;:&quot;ES256&quot;,<br>  &quot;jwk&quot;: {<br>    &quot;kty&quot;:&quot;EC&quot;,<br>    &quot;x&quot;:&quot;l8tFrhx-34tV3hRICRDY9zCkDlpBhF42UQUfWVAWBFs&quot;,<br>    &quot;y&quot;:&quot;9VE4jf_Ok_o64zbTTlcuNJajHmt6v9TDVrU0CdvGRDA&quot;,<br>    &quot;crv&quot;:&quot;P-256&quot;<br>  }<br>}<br>.<br>{<br>  &quot;jti&quot;:&quot;-BwC3ESc6acc2lTc&quot;,<br>  &quot;htm&quot;:&quot;POST&quot;,<br>  &quot;htu&quot;:&quot;https://server.example.com/token&quot;,<br>  &quot;iat&quot;:1562262616,<br>  &quot;nonce&quot;: &quot;NDE5MzgxODAyNjY5Mw.09OjsHtynhQEQwv1J99GnA&quot;<br>}</pre><p>Let’s test it.</p><p>The attacker is able to log a complete request with the access token and the DPoP header.</p><pre>GET https://10.0.2.15/authorization/validate<br>Authorization: Bearer VcUHegTYVqMIK7Q7_pfbsKaT8MnDhsCVQBd46-sCOl-tlkj9l...<br>DPoP: eyJ0eXAiOiJkcG9wK2p3dCIsImFsZyI6IkVTMjU2IiwiandrIjp7ImFsZyI6IkVTy...</pre><p>The same request is replayed for the first time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtXNNOXD6gAwRGjn3-EgDA.png" /><figcaption>The response of a validation endpoint confirms that the heist is a success. Status 200.</figcaption></figure><p>In this particular case DPoP nonces are stored server-side as cache items, with a TTL of 100 seconds. We make a second attempt after a while:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0uGJdxKgt32jp3P1j-PEw.png" /><figcaption>In this case a response with code 307 means we’re unauthorized.</figcaption></figure><p>The screenshot above shows the result of the same request with the same DPoP proof and access token, just a few seconds later. The reason for a 307 response is that the nonce in the DPoP proof has expired, thus making the whole DPoP proof invalid.</p><h3>Conclusion</h3><p>DPoP specification has been an IETF draft for several years now, most recently updated to edition #13 and is listed as one of the recommended ways to constrain token usage in the latest edition of [<a href="https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics">OAuth 2.0 Security Best Current Practice</a>]. It uses proof-of-possession based on public/private key pair at the application level, conveniently where other mechanisms like mTLS are hard to implement.</p><p>Personally, I do hope the specification will soon gain more traction and become widely adopted. Stay safe and protect your APIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb72f37954d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>