In ZAP's alertFilters add-on, how does a global alert filter differ from a context one?
answer
- two collections, not one
- one of them is bound to a context
- empty context key in the job
- globals are walked first
- context id -1 means global
basics
~20 sA global alert filter is tested against every alert and is stored in the add-on's own options, so it survives the next session. A context filter applies only inside its named context and is saved with that context.
solid answer
~40 sThe `alertFilters` add-on keeps two collections. A **global** filter is held in the add-on's own options and is tested against every alert, whatever context the URL falls in; internally it carries a context id of `-1`. A **context** filter belongs to one named context, is exported and imported with that context, and does not come back in a fresh session unless the context is loaded again. In an automation plan one key decides which you get: give an entry a `context:` naming a context and it becomes a context filter; leave the key out and it becomes a global one. Globals are also tested first, and the first filter that matches an alert is the only one applied to it.
go deeper
Know that there are two kinds and that one key in the automation job picks between them: name a context and you get a context filter, leave it out and you get a global one.
Be able to explain the lifetime difference — a global filter is saved in the add-on's options and comes back next session, a context filter is serialised into the context and does not — and what that means for a reused daemon.
Show that you know globals are walked first and the first match wins, so a leftover catch-all global filter silently shadows the per-context work someone else did, and that deleteGlobalAlerts clears the whole collection.
Take a position on where filters are allowed to live across a fleet of pipelines: filters declared in a plan are reviewable with the plan, filters sitting in a long-lived session's options are not, and that difference is the one worth standardising.
## What an alert filter is ZAP's `alertFilters` add-on lets you restate the score of an alert a scan rule has already raised. A filter is a small record: a rule identifier, some optional clauses the alert must match (URL, parameter, attack, evidence, HTTP method), and a `newRisk` — what the alert should carry instead. Nothing is deleted and nothing is blocked. The request was sent, the rule ran, the alert was written to the alert table, and the filter edits that record afterwards. A filter can live in one of two places, and choosing the wrong one is a common way a filter either does nothing or does far more than you meant. ## The global collection A global filter is owned by `GlobalAlertFilterParam`, which is an ordinary options object — it is written into ZAP's configuration and read back when ZAP next starts. Consequences that matter in a pipeline: - It is tested against **every** alert the run produces, no matter which context the alert's URL belongs to, and it is tested even when no context has been defined at all. - It outlives the session. In a container that is thrown away each run this is invisible; on a long-lived desktop or a reused daemon it is exactly why a filter someone added months ago is still quietly rewriting today's findings. - In an automation plan, a filter entry with no `context:` key becomes a global one. That is the intended way to ask for it, not an omission the job complains about. - The job's `deleteGlobalAlerts` parameter, when set true, clears the **whole** global collection before the job adds anything — not just the filters this plan is about to write. ## The context collection A context filter is held by a per-context manager keyed on the context's id, and it is serialised into the context itself. So: - It is only reached when the alert's URL is inside that context. A URL outside it never sees the filter. - It travels with the context. Export the context and the filters go with it; import it somewhere else and they arrive. - It is **not** persisted the way a global one is. Start a fresh session without loading that context back and the filter is gone. - In a plan it is asked for by name: `context: <the name used in env.contexts>`. If the name does not resolve, the job reports an error for that entry rather than silently promoting it to global. ## Side by side | | global filter | context filter | |---|---|---| | stored in | the add-on's own options | the context | | tested against | every alert raised | only alerts whose URL is in that context | | survives a new session | yes | only if the context is loaded again | | how a plan asks for it | omit the `context:` key | `context:` naming a context | | internal marker | context id `-1` | that context's own id | | order of evaluation | first | after every global filter | ## Which one wins when both could match The add-on walks the global collection first and applies the first filter that matches, then stops — it does not go on to look at the context collections. Only if no global filter matched does it walk each context whose scope contains the alert's URL and apply the first match there. Two practical readings: 1. A broad global filter shadows a narrower context filter for the same alert. If you want per-context behaviour, do not also leave a catch-all global filter in place. 2. The walk stops at the first match, so stacking filters to step one finding down twice does not work. ## Choosing one in a pipeline 1. If the noise is a property of one application and you already have a context for it, use a context filter — it is documented next to the thing it applies to and cannot leak onto another target. 2. If the noise is a property of the scan rule itself and you genuinely want it everywhere, use a global filter, and say so in the plan rather than relying on a filter someone left in a saved session. 3. If you inherited a daemon whose findings look wrong, list the global filters before you look anywhere else: they are the ones that are still there from last time.
- What does `deleteGlobalAlerts: true` on the alertFilter job actually remove?Every global alert filter ZAP is currently holding, not only the ones this plan is about to add. The job calls the add-on's delete-all routine before it writes anything, and the cleared collection is saved straight back to the configuration. It never touches context filters. The parameter defaults to false.
- If a global filter and a context filter could both match the same alert, which one applies?The global one. The add-on walks the global collection first, applies the first filter that matches and returns, so the context collections are never reached for that alert. The walk stops at the first match, which is why stacking two filters to step a finding down twice does not work.
- Why might a context alert filter that worked yesterday do nothing today?Because it lives in the context, not in ZAP's options. A fresh session that has not loaded that context has no such filter. In an automation plan this is not usually the cause — the plan rebuilds its contexts and its filters every run — but on a reused desktop session or a hand-driven daemon it is the first thing to check.
saying these in an interview costs you the question
- Says a context alert filter is tested against every alert ZAP raises
- Thinks a context filter comes back on its own in a fresh session
- Believes a global and a context filter both fire on one alert
- Treats an omitted context key in the job as a mistake rather than the way to ask for a global filter
- Assumes deleteGlobalAlerts only removes the filters this plan added