WhiteListing dynamic URLs for Google Sheets Add-On for user configured URLs

Viewed 199

I’m trying to create a Google Sheets add-on which uses an API to the clients own finance system which is deployed on their own web site. The url of the site is configurable so we will only need to deploy a single version of the add-on and all our clients will be able to configure it for their own system.

//getServiceURL() returns the configured URL for the clients system, so https://clientsite/financeapi/
restRequest = UrlFetchApp.fetch(getServiceURL(), params);

The problem I have is that it looks like I need to explicitly reference the urls in the ‘urlFetchWhitelist’ in the appsscript.json file. Otherwise I get the error:-

Exception: Request to https://clientsite/financeapi/blahhh/blahhh failed because the URL has not been whitelisted in the script manifest. (line 510, file "Service")

So I would need to add this to the appsscript.json file.

"urlFetchWhitelist": ["https://clientsite/financeapi/"]

Is there any way round this so that it doesn’t need to be explicitly defined as I don't know these URLs at design time as these are configurable by the client?
If there isn’t I guess we could ask each client what URLs we need to contact and add those to the WhiteList. In which case, is there a limit on the number of whitelisted URLs as we will have hundreds. If we are defining these client URLs could this list be visible to the end user as we can’t have these visible to all users for security reasons.

1 Answers

There seems to be no way to directly bypass this requirement, but I guess you could create web app that would act as a layer between your add-on and the API:

Addon <-> WebApp <-> API

This means that you would only need whitelist the web app's URL and then you can handle any changes to the API URL within the web app with full flexibility.

Related