Block traffic from hosting networks
Keep scripts and bots that run on cloud and hosting servers away from your forms and APIs, without blocking the people behind home and mobile connections.
Real people browse from home internet providers, offices and phones. Scrapers, credential-stuffing tools and spam bots mostly run on rented servers in datacenters. Refusing requests from hosting networks on sensitive endpoints removes much of that automated traffic with little effect on real visitors.
How it works
An answer with every field includes is_hosting, which is true when the address belongs to a hosting, cloud or datacenter provider, and hosting, which names that provider. It also includes asn.type, the kind of network that announces the address: isp, hosting, education, government or business. You refuse matching requests on the endpoints you choose, such as login, sign-up, contact forms and your own API. A paid plan answers both fields on every lookup, and a free key on its organization's first 1,000 lookups each UTC day.
Before you begin
- An API key. A lookup without a key leaves both fields out.
- A list of the endpoints that real people use and bots target.
- A list of the services you rely on that run in datacenters, such as your uptime monitoring or a partner's webhooks, so you can let them through.
1. Check the address
// true, false, or null when the answer can't say
export async function fromHosting(ip) {
try {
const r = await client.lookup(ip);
return r.isHosting ?? null;
} catch (err) {
// Past your organization's lookups with every field, the answer has the basics, without is_hosting.
if (err.kind === 'quota_exceeded' && err.result) {
return null;
}
throw err;
}
}from internetdata import CappedAnswerError
# True, False, or None when the answer can't say
def from_hosting(ip):
try:
return client.lookup(ip).is_hosting
except CappedAnswerError:
# Past your organization's lookups with every field, the answer has the basics, without is_hosting.
return NonePast your organization's lookups with every field, a free key's first 1,000 of the UTC day or a paid plan's quota, the answer leaves is_hosting out and the library raises quota_exceeded, so the function returns null: unknown, which never means that the address isn't a server. is_hosting classifies the address itself, so it stays accurate where a provider mixes hosting and consumer space in one network. asn.type describes the whole network that announces the address. Use it when you want to refuse an entire hosting network, including any of its addresses that is_hosting doesn't mark.
2. Refuse hosting addresses on sensitive routes
With a framework package, a block condition refuses matching requests with 403 before they reach your handlers. A condition is written in the shape of an answer, so it can name is_hosting directly:
app.use(['/login', '/signup', '/contact'], internetdata({
apiKey: process.env.INTERNETDATA_API_KEY,
blockCondition: { isHosting: true },
}));To refuse whole hosting networks instead, write the condition as { asn: { type: 'hosting' } }. Past your organization's lookups with every field, the package counts the answer as a failed lookup and lets the request through, logging quota_exceeded once a minute at most, so requests from hosting networks go through until the full answers return.
3. Let your own services through
Requests from your uptime monitoring, your payment provider's webhooks or a partner's integration can come from datacenters too. Mount the middleware only on the routes that need it, as above, or exclude requests with the skip option:
internetdata({
apiKey: process.env.INTERNETDATA_API_KEY,
blockCondition: { isHosting: true },
skip: (req) => req.path.startsWith('/webhooks/'),
});4. Leave a way in
Some real people do reach you from hosting networks: developers on cloud desktops, people behind a company's cloud gateway, and some privacy services. Don't send them to a dead end. On a form, show a message with another way to reach you; on a login, ask for verification instead of refusing.
Hosting rules work best beside your other defenses. A rate limit catches automation that runs on home connections, and the hosting rule catches the large share that runs in datacenters.
5. Test it
Send a request to a protected route from a cloud server, such as a small virtual machine. It should be refused with 403. The same request from your laptop should succeed.
Next steps
An answer with every field also flags VPNs and datacenter proxies, which you can add to the condition, and a paid plan answers them on every lookup, so a condition holds however many requests you check in a day. To learn more about an address that reaches you, see Investigate an IP address.