OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
4 stars 8 forks source link

Build URLs a bit more safely #578

Open josephjclark opened 1 month ago

josephjclark commented 1 month ago

This issue affects many adaptors (especially some of our new ones!)

When building URLs, we often use patterns like www.blah.com/${appId}/${path}, where path is a user defined value.

But should path start with a /? Or end with one?

In practice it shouldn't matter, and I think usually it doesn't matter. But we should take care to build well-formed URLs which are robust to leading and trailing slashes from users.

I thought we could use the URL global object for this but on checking the API I'm not so sure. We might be better off using node:path.resolve(a,b,c) to build the path

See commcare for an example of this.

josephjclark commented 1 week ago

This has bitten TD a couple of times in the last couple of days - we really shouldn't be so brittle

josephjclark commented 1 week ago

Using undici's baseUrl is a pattern we should use more - undici will deal with at least the base slash. That means adaptors need to use baseUrl rather than assembling their own url. The template needs to do this too