skip to content

Where must the alertFilter job sit in a ZAP automation plan, and why does its position matter?

level: seniorimportance: should knowfreq 42%

answer

  1. it registers, it does not sweep
  2. new alerts only
  3. the plan runs top to bottom
  4. the declared order is a dialog hint
  5. above every crawl and scan job

basics

~20 s

Before every job that can raise an alert. Filters are applied as each alert is added, not swept over alerts already recorded, and a plan runs its jobs in the order they appear in the file — nothing reorders them for you.

solid answer

~40 s

The `alertFilters` add-on works by subscribing to ZAP's alert-added event: when a scan rule records an alert, the add-on tests the alert against the filters it currently holds and rewrites the record if one matches. It never revisits alerts that already exist. The `alertFilter` job only registers filters, so a job placed after the crawl and scan jobs registers filters that have nothing left to match — and the run reports no error, because the job did what it was asked. A plan loaded from YAML executes its jobs top to bottom in file order; the framework does not sort them. Put the job near the top, alongside the other configuration jobs.

code

yaml · 10 lines
yaml
jobs:
  - type: passiveScan-config
  - type: alertFilter          # registered before anything can raise an alert
    alertFilters:
      - ruleId: '<scan-rule-id>'
        newRisk: 'False Positive'
  - type: spider
  - type: passiveScan-wait
  - type: activeScan
  # an alertFilter job written down here would load, log, and rewrite nothing

go deeper

for a junior

Put the alertFilter job near the top of the plan, with the other configuration jobs, and above anything that crawls or scans.

for a middle

Explain why: the add-on rewrites alerts as they are raised rather than sweeping them afterwards, so a filter registered later has nothing to match.

for a senior

Diagnose the silent failure — the plan is valid, the job logs success, and the finding still fails the build — and know that a loaded plan runs in file order while the job's declared order only steers the desktop dialogs.

for a principal

Decide how plans are reviewed across teams so that job order is something a reviewer checks, given that the framework will not check it and a wrong order produces no signal at all.

## The mechanism that forces the ordering The `alertFilters` add-on does not inspect findings at the end of a run. It registers as a consumer of ZAP's alert-added event. Each time a scan rule writes an alert, the add-on reads the new record back, walks its global filters and then the filters of any context containing the alert's URL, and rewrites the record on the first match. The shipped help states the consequence plainly: filters apply to new alerts. So the question "where does the job go" is really "was the filter registered before the alert existed". The `alertFilter` job itself is short, and everything it does is registration: - It optionally clears the global collection, if `deleteGlobalAlerts` is set. - It converts each entry in the plan into a filter object, rejecting any whose rule id is blank or negative, whose risk name is not one of the accepted five, or whose enabled pattern will not compile. - It adds each surviving filter to the global collection, or to the collection of the context the entry names. - It logs each filter it added, with the rule id and the new risk. - It does **not** walk the alert table afterwards, and nothing else in the plan does it on the job's behalf. ## Plans run in file order A plan read from YAML builds its job list by appending each entry as it is parsed, and the runner iterates that list. There is no sorting step. This is worth stating carefully, because the job class does declare an order — the same one the configuration jobs use. That declaration governs where ZAP's desktop dialogs insert a job you add through the interface, and how the job list is sorted for display. It does **not** reorder a plan you wrote by hand or generated from a script. | | what it controls | what it does not control | |---|---|---| | the job's declared order | where the desktop's add-job dialog inserts it | the execution order of a loaded plan | | the order of entries in the YAML | the execution order of a loaded plan | anything in the desktop dialogs | The practical reading: a plan with `alertFilter` in the wrong place is a valid plan, it loads without a warning, the job runs, it logs the filters it added — and nothing raised before it is ever rewritten. ## The corroboration When ZAP's own packaged scan script generates a plan for you rather than driving the daemon directly, it emits the `alertFilter` job straight after the passive-scan configuration job and ahead of every crawl job. Being above the crawl is not a style choice — it is what makes the filters apply at all. ## Where to put it, concretely 1. After the environment block and after whichever configuration jobs set up scanning. 2. Before any crawl job, because a crawl produces traffic and passive rules raise alerts on that traffic. 3. Before any active-scan job, for the same reason. 4. Before the job that waits for passive scanning to drain, since alerts are still being raised while it waits. 5. Anywhere above the job that decides the run's outcome, which is a consequence of the four above rather than a separate rule. ## The escape hatch, and why it is not one here The add-on's control-API surface does offer actions that walk the alerts already recorded and apply the filters retrospectively, plus matching actions that only count what would match without changing anything. Those exist for the desktop and for scripted use. **No automation job calls them.** In an unattended plan there is no retrospective pass available, which is exactly why position is the whole of the control. ## How this fails in practice The symptom is a pipeline that keeps failing on a finding somebody is certain they filtered. The plan is right, the filter is right, the rule id is right — and the job is sitting below the scan jobs because it was added last, which is where an editor naturally puts a new block. Check the order of the jobs before you start debugging the matching clauses.

  • The `alertFilter` job declares the same order as the configuration jobs. Doesn't the framework use that?
    Only in the desktop. That declaration decides where the add-job dialog inserts a job and how the job list is sorted for display. A plan loaded from YAML is executed in the order its entries appear, with no sorting step, so the declaration has no effect on a plan you wrote or generated.
  • Is there any way to apply filters to alerts a run has already recorded?
    Yes, through the add-on's control-API actions, which walk the existing alerts and apply the filters retrospectively — and paired actions that only count what would match. But no automation job calls them, so inside an unattended plan there is no retrospective pass and position is the only control you have.
  • What does a misplaced alertFilter job look like in the run output?
    Like a success. The job loads, validates its entries and logs each filter it added, because adding filters is all it does. Nothing reports that the filters arrived too late to match anything, so the only visible symptom is that the findings you expected to be quietened are still driving the outcome.
  • Does putting the job first risk filtering something the plan has not scanned yet?
    No, because a filter is not consumed and does not expire. It sits in its collection and is tested against every alert raised from then on. Registering early is exactly the intent; the only thing early registration changes is that the filters are in place when the first alert appears.

saying these in an interview costs you the question

  • Assumes the framework reorders jobs so configuration runs first
  • Thinks an alertFilter job placed after the scan still cleans up its findings
  • Believes a filter stops the request being sent or the rule being run
  • Reads the job's declared order as an execution guarantee for a loaded plan
  • Expects a misplaced alertFilter job to report an error or a warning
  • Thinks a filter is used up once it has matched one alert