zapier / zapier-platform

The SDK for you to build an integration on Zapier
https://platform.zapier.com
Other
344 stars 188 forks source link

[PDE-5063] feat(core): Add afterResponse middleware to check if HTTP redirect is made to disallowed domain #803

Closed rnegron closed 4 months ago

rnegron commented 4 months ago

As mentioned in the work ticket, node-fetch doesn't support conditional erroring on redirects. In this MR, we add an "after" middleware to check if the z.request experienced a redirect, and error out if the redirection ended up in a disallowed domain (currently only disallowing localhost). We need to check the resp.url as the req.url does not change on redirect.

Changes:

An alternative approach here could be to set redirect: 'manual' as an option and then perform manual parsing of the headers here.

The big upside to the alternative approach is that we could prevent the disallowed domain request from even happening, as opposed to just catching it like we do here. A potential downside is that it could potentially introduce breaking changes by not fully understanding how integrations are leveraging redirects (speaking for myself!) But ultimately, this change is just an attempt to help protect partners from end-user redirect abuse, which this this MR tackles.