Improve DPoP nonce caching for manually constructed responses from customFetch #200
Replies: 1 comment 3 replies
-
Except that cacheNonce is not part of the public API.
I'm kinda not a fan. Honestly, when you're running into nonce cache issues due to self-contructed Response objects (that the docs do elude to), i would expect you to keep the cache outside yourself and use DPoP's modify assertion option to add the nonce before it is signed. That is already part of the public API. |
Beta Was this translation helpful? Give feedback.
3 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.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! First of all, thank you for creating and maintaining this library. It’s been incredibly helpful.
I’d like to propose a small improvement around DPoP nonce caching. As a user of the library, I ran into a pitfall when using
customFetchthat I think could be addressed with a minimal API adjustment or, alternatively, a documentation note.Context
In my use case, I must return a manually constructed
ResponsefromcustomFetch(i.e., one created withnew Response(...)). As noted in the comment here, that can interfere with DPoP nonce caching:oauth4webapi/src/index.ts
Lines 218 to 219 in fa7414e
The issue appears to stem from
DPoPHandle/DPoPHandler’scacheNonceusingresponse.urlas the cache key. Unlike aResponsereturned by the platformfetch, aResponseconstructed vianew Response(...)does not have itsurlproperty set, so thecacheNoncemethod fails to compute the URL to be used as the cache key and the nonce is not cached.oauth4webapi/src/index.ts
Lines 2335 to 2342 in fa7414e
Proposal
Allow
cacheNonceto accept the request URL explicitly, in addition to theResponse. For example:By passing the correct URL even when
response.urlis unset, we can reliably cache nonces for manually constructed responses. From reading the current code, the code that invokes it already has access to the URL object, so this change should require minimal changesAlternative (Docs-only mitigation)
If changing the method signature is not feasible, could we at least add a note to the
customFetchcomment showing how to avoid the cache miss by setting theurlproperty on a self-constructed response? For example:Documenting this workaround would likely save other users time when they must return a synthetic
Response.If you’re open to either approach (API change or docs note), I’m happy to open a PR. Please let me know what you think!
Beta Was this translation helpful? Give feedback.
All reactions