Skip to content

Access Control Decorators

Restrict access to specific IP addresses or CIDR ranges per route.

const adminHandler = guard.requireIp(
['10.0.0.0/8', '192.168.1.0/24'],
['10.0.0.99'],
)(async (req, res) => {
res.json({ admin: true });
});
app.get('/admin', adminHandler);

When whitelist is provided, only those IPs can access the route. When blacklist is provided, those IPs are blocked even if they match the whitelist.

Block requests from specific countries. Requires a geoIpHandler or geoResolver in the config.

const handler = guard.blockCountries(['CN', 'RU', 'KP'])(async (req, res) => {
res.json({ data: 'not available in blocked countries' });
});
app.get('/api/data', handler);

Country codes are ISO 3166-1 alpha-2 (two uppercase letters).

Only allow requests from specific countries. All other countries are blocked.

const handler = guard.allowCountries(['US', 'CA', 'GB'])(async (req, res) => {
res.json({ data: 'US/CA/GB only' });
});
app.get('/api/domestic', handler);

Block requests originating from cloud provider IP ranges. Useful for preventing automated scraping from cloud-hosted bots.

const handler = guard.blockClouds(['AWS', 'GCP'])(async (req, res) => {
res.json({ data: 'no cloud access' });
});
app.get('/api/resource', handler);

Without arguments, blocks all three providers (AWS, GCP, Azure):

const handler = guard.blockClouds()(async (req, res) => {
res.json({ data: 'residential IPs only' });
});

Bypass specific security checks for a route. Check names correspond to the 17 checks in the security pipeline.

const handler = guard.bypass([
'rate_limit',
'suspicious_activity',
])(async (req, res) => {
res.json({ webhook: 'processed' });
});
app.post('/webhook', handler);

Available check names:

Check NamePipeline Step
route_configRoute configuration extraction
emergency_modeEmergency mode
https_enforcementHTTPS enforcement
request_loggingRequest logging
request_size_contentSize/content validation
required_headersRequired headers
authenticationAuthentication
referrerReferrer validation
custom_validatorsCustom validators
time_windowTime windows
cloud_ip_refreshCloud IP refresh
ip_securityIP security
cloud_providerCloud provider blocking
user_agentUser agent filtering
rate_limitRate limiting
suspicious_activitySuspicious activity detection
custom_requestCustom request checks