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

firewalker

v1.0.9

Published

It's easy to treat firewall rules as plain configuration. It's incredibly easy to manage a couple of rules that look like. ``` http.host eq "www.example.org" ```

Downloads

262

Readme

Build Status Codecov npm version

A framework for executing and testing Cloudflare Firewall rules locally.

const firewall = new Firewall()
const rule = firewall.createRule(`
    http.host eq "www.example.org"
`)

rule.match(new Request('http://www.example.org')) // -> true
rule.match(new Request('http://www.example.com')) // -> false

See more examples.

And for integration testing see some of the ruleset examples

Motivation

It's easy to treat firewall rules as plain configuration. It's incredibly easy to manage a couple of rules that look like.

http.host eq "www.example.org"

And end up with a rule that looks more like.

http.host matches "(www|api)\.example\.org"
and not lower(http.request.uri.path) matches "/(auth|login|logut).*"
and (
  any(http.request.uri.args.names[*] == "token") or
  ip.src in { 93.184.216.34 62.122.170.171 }
)
or cf.threat_score lt 10

Over time, the number of rules and their complexity grows. Manually testing rules like the above is error-prone as humans are known to make mistakes. After a few steps up in complexity, it becomes apparent that firewall rules are code, and need to be treated as code. They need to be stored in a source code repository, managed with a tool like Terraform, and the changes need to be tested on CI.

Here is where Firewalker comes into play allowing you to write unit tests to ensure that a change to the path regex isn't going to block all of the traffic to your site or cancel out the effect of the rule completely. For instance, for the rule above, you can define multiple assertions with jest.

const rule = firewall.createRule(/* */)

expect(rule.match(new Request('http://www.example.org'))).toBeFalsy()
expect(rule.match(new Request('http://www.example.org?token=abc'))).toBeTruthy()
expect(rule.match(new Request('http://www.example.org/login/user?token=abc'))).toBeFalsy()
expect(rule.match(new Request('http://www.example.org/login/user?token=abc', {
    cf: {'cf.threat_score': 5}
}))).toBeTruthy();
// etc

Firewalker builds on top of Cloudflare's wirefilter rule engine and provides API to construct the requests in JS. After all, if the tests for your workers are in JS, why not to use the same syntax for the WAF rules?

Supported platforms

Firewalker relies on a binary build wirefilter to run and execute the firewall rules. Therefore, only the platforms which binaries were pre-built will be able to run Firewalker. Currently supported platforms are:

  • MacOS
  • Linux

Disclaimer

The Firewalker project is not officially supported by Cloudflare or affiliated with Cloudflare in any way. While Firewalker tries to preserve the semantics of the Cloudflare WAF rule engine, there will always be some differences, so use it at your own risk as general guidance for local testing rather than the ultimate truth.

Contribute

Contributions are always welcome!