Repository navigation
Scenarios
crowdsec-client-scenarios provides optional scenarios for
crowdsec-http-middleware and compatible middlewares. A
scenario can extract the visitor IP, enrich an alert, or skip alerts for allowed
IPs.
Full documentation: package README.
npm i crowdsec-client-scenariosWhen crowdsec-client-scenarios is installed, omitting the scenarios option in
the middleware watcher configuration loads the defaults:
-
AllowListEnricher: skip alerts for allowed IPs. -
XForwardedForChecker: extract the visitor IP behind a trusted proxy. -
HTTPEnricher: add HTTP request context to alerts.
Passing scenarios: [] disables all scenarios.
Some clients send a fake X-Forwarded-For header to hide their real IP. This
scenario triggers an alert when an untrusted IP sets the header, and can extract
the real client IP.
import { XForwardedForChecker } from 'crowdsec-client-scenarios';
const scenarios = [XForwardedForChecker];
const scenariosOptions = {
'x-forwarded-for': {
// every trusted proxy/CDN CIDR must be listed here
trustedProxies: ['10.0.3.0/24'],
// alert when an untrusted IP sets the header (default: true)
alertOnNotTrustedIps: true
}
};Warning: an incomplete trustedProxies list can ban your reverse proxy. Test
first with alertOnNotTrustedIps: false and log req.ip.
Skip alerts for local and private addresses.
import { AllowListEnricher } from 'crowdsec-client-scenarios';
const scenarios = [AllowListEnricher];
const scenariosOptions = {
'allow-list': {
allowed: ['127.0.0.1', '::1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12']
}
};That list is also the default when allowed is not set.
Add context from the current HTTP request to the alert. This scenario has no options.
import { HTTPEnricher } from 'crowdsec-client-scenarios';
const scenarios = [HTTPEnricher];
const scenariosOptions = {};Add ASN and/or city context using the MaxMind databases.
import { MaxMindEnricher } from 'crowdsec-client-scenarios';
const scenarios = [MaxMindEnricher];
const scenariosOptions = {
maxmind: {
// set at least one of ASN / city
paths: {
ASN: 'path/to/geoLite2-ASN.mmdb',
city: 'path/to/geoLite2-City.mmdb'
},
// reload the database when the file changes
watchForUpdates: true
}
};Download the free databases from the MaxMind GeoLite2 page.
Pass the scenario constructors and their options to the watcher configuration:
const middleware = new CrowdSecHTTPMiddleware({
url: process.env.CROWDSEC_URL,
watcher: {
machineID: process.env.CROWDSEC_MACHINE_ID || '',
password: process.env.CROWDSEC_PASSWORD || '',
scenarios,
scenariosOptions
}
});