egze

egze

Hey everyone! I just released CfBouncer, a small library that keeps your Cloudflare WAF block rules in sync with your Phoenix application.

The problem

If you’re using Cloudflare in front of your Phoenix app, you might want to block requests to paths that don’t exist in your application — vulnerability scanners probing for /wp-admin, /.env, /phpmyadmin, etc. Manually maintaining a WAF rule for this gets tedious and falls out of date as your app evolves.

What CfBouncer does

CfBouncer reads your Phoenix router, endpoint websockets, and static file paths, then generates a Cloudflare WAF expression that blocks everything except your known routes. It pushes this rule via the Cloudflare API.

For example, given routes like /, /users/:id, /auth/login and static paths like assets, robots.txt, it generates:

not (
  http.request.uri.path eq "/"
  or starts_with(http.request.uri.path, "/assets/")
  or starts_with(http.request.uri.path, "/auth")
  or starts_with(http.request.uri.path, "/live")
  or starts_with(http.request.uri.path, "/robots.txt")
  or starts_with(http.request.uri.path, "/users")
)

Usage

Add it to your mix deps:

{:cf_bouncer, "~> 0.1.0"}

Configure your router, endpoint, and Cloudflare credentials:

# config/config.exs
config :cf_bouncer,
  router: MyAppWeb.Router,
  endpoint: MyAppWeb.Endpoint,
  static_module: MyAppWeb,
  rule_description: "[CfBouncer] Block non-allowlisted paths"

# config/runtime.exs
config :cf_bouncer,
  zone_id: System.get_env("CLOUDFLARE_ZONE_ID"),
  api_token: System.get_env("CLOUDFLARE_API_TOKEN")

Then run it as part of your deploy:

mix cf_bouncer.sync

It’s idempotent — it only updates the rule when the expression actually changes. There’s also --dry-run to preview what would be pushed and --force to push regardless.

You can also add extra_paths for routes served outside Phoenix (proxied services, webhooks, etc.).

Cloudflare

On Cloudflare - your pushed rule will look like this:

Links

https://github.com/egze/cf_bouncer

Would love to hear your feedback!

First Post!

krasenyp

krasenyp

Congrats on the release, this is a very cool library.

I have three suggestions.

  • Don’t bring in Req by default. Use the built in HTTP library - httpc. Maybe Req can be optional dependency.
  • For the text generation part you can use EEx instead of concatenation strings.
  • You use the application environment while your library is not a supervised application. It’s not a very good practice. The docs feature library guidelines.

Most Liked

egze

egze OP

Thanks for the tips. Just pushed the new version:

## 0.2.0

- Switch from `Req` to Erlang's built-in `:httpc` for HTTP requests
- Use EEx templates for configuration
- Only read application config in mix task, not in library code

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
rodloboz
I’ve started working on a new library to run SQL queries and do basic business intelligence. Think “Blazer for Elixir.” Currently it fe...
New

Other Trending Topics Top

mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews