parse_duration: sub-unit durations pass validation but floor to the 0 sentinel on the Lua request path (permanent ban / disabled session timeout)
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_durationkeeps the fractional value:int(result) if result.is_integer() else result, so500msin seconds →0.5. - Request path —
src/bw/lua/bunkerweb/duration.lua:28—floor(tonumber(amount) * factor / default_factor), so500msin seconds →floor(0.5)→0.
0 is not a neutral result here — it's a sentinel in the consumers:
BAD_BEHAVIOR_BAN_TIME(default1d, regex^\d+(ms?|[shdwMy])?$) —badbehavior.lua:86parses it in seconds, and:549treatsban_time == 0as a permanent ban (the code comment: "For permanent bans (ban_time = 0), don't set an expiration"). SoBAD_BEHAVIOR_BAN_TIME=500mssilently becomes a permanent ban.SESSIONS_ROLLING_TIMEOUT(default1h, same regex) —sessions.lua:97parses it in seconds, and the session library applies it onlyif rolling_timeout > 0(lua-resty-session/lib/resty/session.lua:360). SoSESSIONS_ROLLING_TIMEOUT=500msfloors to0and the rolling timeout is not applied.SESSIONS_IDLING_TIMEOUT/SESSIONS_ABSOLUTE_TIMEOUTare 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 30Any 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:
- Refuse to let a non-zero input become
0— in both engines, a positive amount that computes to0is rejected (or rounded up to 1 base unit) rather than floored to the sentinel. Preserves the explicit0 = permanent/disabledmeaning while removing the silent path to it. My default recommendation. - 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.
- 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.
Source: bunkerity/bunkerweb