npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crowdsec-client-scenarios

v0.0.13

Published

tmp

Downloads

81

Readme

crowdsec-client-scenarios

NPM version CI codecov Downloads License Known Vulnerabilities

Donate GitHub stars Package Quality

Bugs Code Smells Duplicated Lines (%) Lines of Code Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

Dependencies update - renovate

NPM

This library is a Node.js client to talk with crowdsec rest API .

Start

install it

npm i crowdsec-client-scenarios

and then read the documentation in the wiki

Usage

This package, is planned to host scenarios used by crowdsec-http-middleware and other middleware that extend it

Scenarios

in this part, we will use the variables scenarios and scenariosOptions, to illustrate the use in the middlewares

Defaults scenarios

the defaults scenarios are (defined here) :

Available scenarios

The available scenarios are :

XForwardedForChecker

This scenario will validate the XForwardedFor header . Some malicious persons will send you a fake X-Forwarded-For header, to hide their real IP . This scenario will trigger an alert, if an untrusted IP try to pass X-Forwarded-For

const scenarios = [XForwardedForChecker];
const scenariosOptions = {
    'x-forwarded-for': {
        //list of trusted CIDR, you need to setup here that all the trusted proxies, else, it will trigger alert for your reverse proxies, and extract incorrect ip
        trustedProxies: [],
        //trigger alert if an untrusted ip set the header (true by default)
        alertOnNotTrustedIps: true
    }
}

this scenario support the extractIp capability, so, if you enable it, it will extract the IP automatically from the headers, will use set it on req.ip, and will use it to trigger alerts and check if decisions exists

Example

you are using cloudflare (you can get cloudflare ips here, then traefik in subnet 10.0.3.0/24, and finally your webserver

on your server, you will configure :

const scenarios = [XForwardedForChecker];
const scenariosOptions = {
    'x-forwarded-for': {
        //list of trusted CIDR, you need to setup here that all the trusted proxies, else, it will trigger alert for your reverse proxies, and extract incorrect ip
        trustedProxies: [
            //cloudflare ips
            "173.245.48.0/20",
            "103.21.244.0/22",
            "103.22.200.0/22",
            "103.31.4.0/22",
            "141.101.64.0/18",
            "108.162.192.0/18",
            "190.93.240.0/20",
            "188.114.96.0/20",
            "197.234.240.0/22",
            "198.41.128.0/17",
            "162.158.0.0/15",
            "104.16.0.0/13",
            "104.24.0.0/14",
            "172.64.0.0/13",
            "131.0.72.0/22",
            "2400:cb00::/32",
            "2606:4700::/32",
            "2803:f800::/32",
            "2405:b500::/32",
            "2405:8100::/32",
            "2a06:98c0::/29",
            "2c0f:f248::/32",
            //traefik ip
            "10.0.3.0/24"
        ],
        //trigger alert if an untrusted ip set the header
        alertOnNotTrustedIps: true
    }
}

so, if someone with ip 1.2.3.4 it will produce an X-Forwarded-For like 1.2.3.4, 173.245.48.2, and your webserver will detect a remote address like 10.0.3.1 . This scenario will parse the information, and so set req.ip = "1.2.3.4", so you now know the real ip of your visitor .

I need to warn you, if you miss configured the list of allowed ips, it can ban your reverse proxy . you can test it before, by setting alertOnNotTrustedIps to false, and log req.ip, if the IP is correct, you can enable the alerts

AllowList

This scenario allow you to exclude some ips from alerts

const scenarios = [AllowListEnricher];
const scenariosOptions = {
    'allow-list': {
        //list of CIDR/IP to allow to skip alert checks
        allowed: ['127.0.0.1']
    }
}

by default, the CIDR allowed are the RFC 1918 one (private network)

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']
    }
}

HTTPEnricher

this scenario will add context to your alert, linked with the current http request

const scenarios = [AllowListEnricher];
//no options
const scenariosOptions = {}

MaxMindEnricher

this scenario will add context to your alert with the help of the maxmind databases

const scenarios = [MaxMindEnricher];
const scenariosOptions = {
    maxmind: {
        //specify path to ASN or city databases . you need need to set one, or the two databases
        paths: {
            ASN: 'path/to/geoLite2-ASN.mmdb',
            city: 'path/to/geoLite2-City.mmdb'
        },
        //you can watch for updates, and so, updating the database on the filesytem will automatically reload the database
        watchForUpdates: true
    }
}

to use this scenario, you will need to download free databases available here. If you need better accuracy you should consider buying commercial subscription.

Debug

this library include debug, to debug, you can set the env variable :

DEBUG=crowdsec-client-scenarios:*