feat(sdk): add defineSandboxProxy helper#188
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| } | ||
|
|
||
| sanitizedRequest.headers.set("host", host); | ||
| sanitizedRequest.headers.set("x-forwarded-host", host); |
There was a problem hiding this comment.
Can you clarify why we set this value here?
| } | ||
|
|
||
| const { payload } = await jwtVerify(token, getJwks(issuer), { | ||
| audience: originalUrl.origin + originalUrl.pathname, |
There was a problem hiding this comment.
The path of the request is "proxy URL + original path", so this is likely to not match here, no?
There was a problem hiding this comment.
Hum I only tested the / case, for example:
- Rule on
vercel.comwithforwardURL: "https://proxy.vercel.app/proxy", which is the audience of the OIDC token - I make a request to
https://vercel.comfrom the sandbox - The function at
https://proxy.vercel.app/proxyreceives the request, and has anoriginalUrlofhttps://proxy.vercel.app/proxy&vercel-forwarded-hostofvercel.com
This indeed doesn't handle requests on other paths like https://vercel.com/sandbox, because now the audience would still be https://proxy.vercel.app/proxy but originalUrl would be https://proxy.vercel.app/proxy/sandbox
We could check only the hostname but that defeats the point of having path-defined audiences. The other option is to explicitly require the user to pass in their configured forwardURL into defineSandboxProxy. Thoughts?
This PR adds a new
defineSandboxProxyhelper in@vercel/sandbox/proxyto integrate network policies forwarding rules easily within a Vercel Function, or any other platform that supports the Web Handlers syntax (Request/Responseobjects)We use
joseto verify the OIDC token, then extract the metadata (original host, scheme, port, and source team/project/sandbox ids) before calling a user-defined Web Handler. If the request cannot be authorized, we return a 403 by default, but the user can also override this behavior with a separate Web Handler. A newRequestis constructed to correspond to the original sandbox request before being proxied by the sandbox firewallExample usage in a Vercel Function: