Can I access a custom list from a worker?

Hi there, is it possible to get the data from the custom list within a worker fetch request?

I have created an IP allowlist in my account (manage account → configuration → lists) and I am now also trying to do some stuff based on those IP’s within the worker. I already found out I could do something like this in the worker code:

export default {
  async fetch(request) {
    const clientIP = request.headers.get("CF-Connecting-IP");
    const ipList = ['1.2.3.4', '1.2.3.5', '1.2.3.6'];    
    if (ipList.includes(clientIP)) {
      // do something when specific IP is spotted
      console.log('something');
    }
    return fetch(request);
  },
};

However, I’d like to replace ipList with the custom list that’s already configured in the account so it can be managed from 1 place.

You can’t access configured IP lists but you can maintain your own version in something like KV (KV · Cloudflare Workers docs)

You can add IPs and pull them without having to redeploy. You could add new IPs in the dash or through IP or through the Worker.

1 Like