Commit 982e953
authored
chore(appsec): skip user block when auto mode resolves to disabled (#17580)
## Summary
`block_request_if_user_blocked` has a guard-ordering bug: it checks
`mode == DISABLED` **before** resolving `AUTO` to the configured mode.
When called with `mode="auto"` (via `set_user_for_asm`) and
`DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE=disabled`, the guard reads
`"auto" == "disabled"` → False and proceeds, calling `should_block_user`
unnecessarily. That WAF call returns `keep=True` and causes the tracer
to force-keep the trace via `_asm_manual_keep` — even though no
automated user event was generated.
Fix: resolve `AUTO` to the configured mode first, then apply the
disabled guard.
```python
# Before (buggy)
if not asm_config._asm_enabled or mode == LOGIN_EVENTS_MODE.DISABLED:
return
if mode == LOGIN_EVENTS_MODE.AUTO:
mode = asm_config._user_event_mode # too late — guard already passed
# After
if mode == LOGIN_EVENTS_MODE.AUTO:
mode = asm_config._user_event_mode # resolve first
if not asm_config._asm_enabled or mode == LOGIN_EVENTS_MODE.DISABLED:
return # now correctly catches disabled
```
## How the bug was found
While writing end-to-end tests for the `APPSEC_AUTO_EVENTS_TRACKING=disabled`
scenario in [system-tests](DataDog/system-tests#6750),
login-success traces were unexpectedly force-kept (`_sampling_priority_v1=2`,
`_dd.p.dm=-5`) even though no user event tags were emitted. Debug
tracing confirmed `_asm_manual_keep` was called from `_processor.py:399`
via `should_block_user` → `call_waf_callback(usr.id=...)`, bypassing the
disabled guard due to the ordering bug described above.
## Release notes
> **Note:** Release notes still needed before this can be merged.
Co-authored-by: romain.marcadier <romain.marcadier@datadoghq.com>1 parent 80d6ce3 commit 982e953
1 file changed
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
363 | | - | |
364 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
| 369 | + | |
| 370 | + | |
368 | 371 | | |
369 | 372 | | |
370 | 373 | | |
| |||
0 commit comments