Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crowdsec-client-scenarios

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crowdsec-client-scenarios

tmp

  • 0.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

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:*

Keywords

FAQs

Package last updated on 01 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc