#3960·bunkerweb

parse_duration: sub-unit durations pass validation but floor to the 0 sentinel on the Lua request path (permanent ban / disabled session timeout)

Author: Ayushsinha322Created Sep 23, 2026Updated Sep 25, 2026
Labelsbugconfigcore

Affected area

core — the duration-suffix feature added in 3075b9d. Two parse_duration implementations disagree on sub-unit values, and the request-path result lands on a 0 sentinel.

What happened?

A duration below the setting's base unit (e.g. 500ms on a setting whose consumer parses in seconds) passes validation, but the two parsers handle it differently:

  • Config path — src/common/utils/common_utils.py:43,60 — parse_duration keeps the fractional value: int(result) if result.is_integer() else result, so 500ms in seconds → 0.5.
  • Request path — src/bw/lua/bunkerweb/duration.lua:28 — floor(tonumber(amount) * factor / default_factor), so 500ms in seconds → floor(0.5) → 0.

0 is not a neutral result here — it's a sentinel in the consumers:

  • BAD_BEHAVIOR_BAN_TIME (default 1d, regex ^\d+(ms?|[shdwMy])?$) — badbehavior.lua:86 parses it in seconds, and :549 treats ban_time == 0 as a permanent ban (the code comment: "For permanent bans (ban_time = 0), don't set an expiration"). So BAD_BEHAVIOR_BAN_TIME=500ms silently becomes a permanent ban.
  • SESSIONS_ROLLING_TIMEOUT (default 1h, same regex) — sessions.lua:97 parses it in seconds, and the session library applies it only if rolling_timeout > 0 (lua-resty-session/lib/resty/session.lua:360). So SESSIONS_ROLLING_TIMEOUT=500ms floors to 0 and the rolling timeout is not applied. SESSIONS_IDLING_TIMEOUT / SESSIONS_ABSOLUTE_TIMEOUT are parsed the same way.

Validation accepts all of these — the regex ^\d+(ms?|[shdwMy])?$ permits the ms suffix on second-scale settings — so the operator gets no error, and the config layer and the request layer then disagree about what the value is.

How to reproduce?

Parser-level, no runtime needed (Python vs a faithful transcription of duration.lua):

value    validates?   config (python, s)   request (lua, s)
500ms    yes          0.5                  0     ← ban: permanent; rolling timeout: not applied
250ms    yes          0.25                 0
999ms    yes          0.999                0
1500ms   yes          1.5                  1
30       yes          30                   30

Any value in (0, 1) of the base unit validates, is non-zero in the config layer, and floors to the 0 sentinel in the request layer.

Scope, stated honestly

Not remotely exploitable — it requires an operator to set a sub-base-unit value on a setting whose consumer uses a larger base unit, which validation wrongly accepts. It's a silent-transformation footgun with two directions: BAD_BEHAVIOR_BAN_TIME over-blocks (a short ban becomes permanent), and the session timeouts under-enforce (a lifetime control is silently switched off). I'm flagging it because a value the operator entered as a small non-zero duration shouldn't quietly become "permanent" or "disabled", and because the two engines shouldn't disagree on a validated value.

The fix is a design call — hence issue first

I didn't want to presume one in a PR, since it spans both parsers and the semantics of several controls. Options, roughly:

  1. Refuse to let a non-zero input become 0 — in both engines, a positive amount that computes to 0 is rejected (or rounded up to 1 base unit) rather than floored to the sentinel. Preserves the explicit 0 = permanent/disabled meaning while removing the silent path to it. My default recommendation.
  2. Tighten validation per setting — reject sub-base-unit suffixes on second-or-larger settings. More precise but needs the base unit expressed in the schema.
  3. Make the two engines agree some other way you prefer.

Happy to send the PR for whichever direction you pick — I have the reproducer and the two-engine test ready.

BunkerWeb version

dev at 4128411 (feature landed in 3075b9d, shipped in 1.6.15 / 1.6.16~rc1).

What integration are you using?

Integration-independent — it's setting parsing.

Notes

I work on WAF engineering commercially; numbers here are BunkerWeb measured against itself, no comparative data.