MirLabs / The blog / Security / Open source

One alert per bot is zero alerts

My security bundle was supposed to stay quiet when a bot was already blocked. It never did. Sentinelle 0.6 fixes the bug, and only emails on the spot when something has really gone out.

· Cyril Delage · 3 min read · Lire en français

A smartphone screen lit up
Photo: William Hook on Unsplash

Two days ago, I wrote here that Sentinelle, my Symfony security bundle, no longer sent an email for an address already blocked whose every attempt had failed. That was the quiet_when_blocked setting, on by default since version 0.4.

It was wrong. That setting never applied.

The bug

When a bot crosses the threshold (too many requests for sensitive files within a few minutes), Sentinelle does two things: it blocks the address, then it prepares the alert. The alert service knows how to stay quiet when told "this address has just been blocked, and it got nothing". It was tested, and its tests passed.

Except that the code calling it never passed on the ban it had just set. For the alert service, the address was therefore never blocked. The result: it sent the email every time, with a false sentence thrown in, "not blocked automatically", when it was.

Each piece worked on its own. It was the wire between them that was missing. Version 0.6 fixes that wire, and adds the missing test: the one that checks the caller really passes the ban to the alert service, not only that the service knows what to do with it.

The real problem: too many emails

That bug would not have solved everything anyway. A public site is scanned all day long. On one of my production sites, those emails were climbing to about 200 a week. Nearly all of them told the same story: an address asks for /.env, gets a 404, gets blocked. Nothing happened.

At that rate, you learn to ignore the emails, then to filter them, then to archive them unread. And the day one of them says "a sensitive file was really served", it looks like the two hundred others. That is how you miss a real incident: not for lack of alerts, but because of too many.

Sentinelle 0.6: an email only when something got through

Since 0.6, only one kind of alert goes out immediately by default: a breach. A sensitive path (.env, .git, keys, database backups) that answered successfully, or a secret spotted in a response. Not "someone tried": "the response went out". That email is red, high priority, and says what to do now.

The rest is not ignored. Scans, injection attempts and brute force are still detected, blocked and logged. They are simply counted in a daily summary:

  • the day's alerts by type, and whether that type goes out on the spot or not;
  • the sensitive responses served, in red, first;
  • the hostile requests by type;
  • the blocked addresses by reason, without the detail, so that a hundred scans fit on one line;
  • the ten most active addresses, and whether they are still blocked.

On a day with nothing to report, no email goes out.

Everyone chooses what deserves an immediate email:

sentinelle:
  alert:
    immediate: [breach]                 # default since 0.6
    # immediate: [breach, exploitation] # also every exploitation attempt
    # immediate: all                    # the old behaviour

To get exactly the old emails back: immediate: all and quiet_when_blocked: false.

What I take from it

An alert must answer a single question: do I need to act now? An address that was refused everything asks nothing of you. An address that received your .env calls for action within the hour. The two must not land in the same inbox, in the same form.

And a broader lesson I keep for later: a documented, tested setting is not a setting that works. The test has to follow the real path, from the request to the email, not just the last piece.

I would rather write this article than let the old one say something false. If you use Sentinelle, 0.6 comes with composer update acencyril/sentinelle-bundle; remember to schedule sentinelle:digest once a day, otherwise the held-back alerts only show in the dashboard.

A project like this one?AI integration, a site to make readable by assistants, security: let's talk.
Contact me

Read next