Enriching EventContext
What is the best way to enrich EventContext?
For security reason we need to a lot of checks during the middleware, for example to check for CSRF, sessions/login, and so on.
It would be really helpful to be able to pass more data down the next function/middleware. This cannot be done directly with headers in a safe way. What's the best way to do so? what's a safe way to enrich the context?
Related: https://developers.cloudflare.com/pages/functions/api-reference/ lists some fields that are not described.
API reference · Cloudflare Pages docs
Learn about the APIs used within Pages Functions.
10 Replies
req.cf
should be passed around without being modifiedyep, I'm not touching request. I think it's immutable too (at least it seems to be immutable for workers)
No, I mean that it shouldn't be modified by Pages, so you should be able to use that
As long as you don't wipe out anything that is already on
req.cf
it should be fine to tack additional stuff onyes but there is a risk in clobbering future properties
I mean, if you use a random-enough property name, you shouldn't have any issues
where is the .cf property? also maybe it would be safer to add a property to context.env
context.request.cf
it does work but it also is a bodge from the cloudflare instrumentation" does not feel like a good place to add details 🙂
is there a place to file a feature request?
GitHub
GitHub - cloudflare/workers-sdk: ⛅️ Home to Wrangler, the CLI for C...
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - GitHub - cloudflare/workers-sdk: ⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
thank you so much for the support