Skip to content

Tamp Zap

BrewingCoder edited this page Nov 20, 2026 · 1 revision

Tamp.Zap

Wrapper for ZAP (Zed Attack Proxy) — dynamic application security testing against a deployed target. SARIF is native, so there is no converter step.

using Tamp.Zap;

Full reference: https://github.com/tamp-build/tamp-zap.

Naming. ZAP left OWASP in September 2023 (to the Linux Foundation's Software Security Project), and in September 2024 the core maintainers joined Checkmarx and it was rebranded ZAP by Checkmarx. It is still Apache-2.0. If a contract or policy says "OWASP ZAP", this is that tool — worth reconciling explicitly in compliance paperwork rather than leaving an auditor to infer it.

DAST is a different kind of scanner

Every other scanner in the security pipeline reads artefacts at rest — source, a lockfile, an image, a repo's history. ZAP needs a running application with a URL, which changes where it belongs in a build: it cannot run in the same job that produced the package, only after something has been deployed.

That makes a deploy a prerequisite, not a detail. See Failure Handling for the "deploy succeeded but the scan target isn't up yet" shape.

Two verbs

Zap.Automation(s => …)     // the Automation Framework — canonical
Zap.PackagedScan(s => …)   // zap-baseline / zap-full-scan / zap-api-scan

Prefer Automation

The packaged scripts are the better-known entry point and the wrong default. They hardcode report handling and cannot express an authentication context.

A real application has more than one auth surface — anonymous routes, a token-authenticated API, a session-authenticated UI. A single packaged scan only ever sees the first. That is how a team ends up with a green DAST scan that never got past the login page: nothing failed, nothing was tested.

The Automation Framework composes contexts, authentication, spec import, spidering, active scanning and reporting as declarative jobs in one plan. Zap.Automation drives that.

Plan generation

You do not hand-author the Automation Framework schema. ZapAutomationPlan emits one plan per auth surface:

ZapAutomationPlan.Anonymous(url, reportFile)   // unauthenticated routes
ZapAutomationPlan.Active(…)                    // session-authenticated UI
ZapAutomationPlan.Api(…)                       // OpenAPI spec import, token auth
ZapAutomationPlan.Spa(…)                       // client-rendered app (AJAX spider)
ZapAutomationPlan.Write(path, planYaml)        // -> AbsolutePath, for SetPlanFile

ZapAutomationPlan.DefaultAssetExcludes drops static assets from the scan scope. Images, fonts and bundles are not an attack surface worth spidering, and excluding them is most of the difference between a scan that finishes and one that times out.

ZapAutomationPlan.SarifReportFileOnDisk(reportFile) resolves where the plan will actually write its SARIF — use it rather than assuming, because the plan's report path is relative to the container's work directory, not the runner's. That mismatch is the single most common reason a scan passes and the pipeline then finds no evidence file.

Docker is the default, and the path translation is the catch

The default mode runs the official image, which bundles a JRE. The alternative is a local zap.sh with a JRE 17+.

In Docker mode the work directory is bind-mounted, so every path in the plan is a path inside the container. SetWorkDirectory is the host side of that mount and is required in Docker run mode — the wrapper refuses the plan without it rather than guessing. SetContainerWorkDirectory overrides the other side. A plan that names a host path will fail to find its input, or write its report somewhere you are not looking.

Settings worth knowing

Shared by both verbs (ZapSettingsBase):

Area Setting
Run mode SetRunMode (Docker or local zap.sh), SetImage, SetNetworkMode, SetDockerCommand, SetZapCommand
Paths SetWorkDirectory (required in Docker mode), SetContainerWorkDirectory, SetWorkingDirectory
Reports SetJsonReportFile, SetHtmlReportFile
Diagnostics SetDebug, SetIgnoreWarnings
Environment SetEnvironmentVariable, SetSecretEnvironmentVariable, SetContainerUser
Escape hatches AddZapArgument, AddDockerArgument

Automation adds SetPlanFile — a host path, which in Docker mode must sit under WorkDirectory or the container will not see it. PackagedScan adds SetKind (baseline / full / api), SetTarget, SetApiFormat, SetSpiderMinutes, SetAjaxSpider, SetPassiveScanTimeoutMinutes, SetHeadless and SetConfig.

SetNetworkMode is the one people need and don't expect: a container scanning an app on the runner's own localhost cannot reach it on the default bridge network.

Credentials: SetSecretEnvironmentVariable

An authenticated plan needs a bearer token or session cookie, and a plan file is a file on disk that gets archived. Don't put the credential in it.

SetSecretEnvironmentVariable(name) forwards a variable by name only, inheriting the value from the runner. The value never appears on the command line or in the plan file; the plan references it as ${NAME}:

var scan = Zap.Automation(s => s
    .SetWorkDirectory(SecurityArtifactsDir)
    .SetPlanFile(plan)
    .SetSecretEnvironmentVariable("ZAP_BEARER_TOKEN"));   // plan says ${ZAP_BEARER_TOKEN}

SetEnvironmentVariable(name, value) sets a literal and is for non-sensitive configuration only.

Quick example — scan a deployed app

Target SecurityScanZap => _ => _
    .Description("ZAP DAST scan against the deployed app; SARIF for the security pipeline.")
    .DependsOn(Deploy)
    .Executes(() =>
    {
        var plan = ZapAutomationPlan.Write(
            SecurityArtifactsDir / "zap-anon.yaml",
            ZapAutomationPlan.Anonymous(TargetUrl, "zap-anon.sarif"));

        var scan = Zap.Automation(s => s
            .SetWorkDirectory(SecurityArtifactsDir)
            .SetPlanFile(plan));

        var rc = ProcessRunner.Execute(scan, Console.Out, Console.Error);
        if (rc != 0) throw new Exception($"zap exited with {rc}");
    });

Severity, and what the SARIF actually carries

ZAP writes an explicit per-result level, so its findings arrive with a severity of their own rather than inheriting one from the rule. That matters because SARIF 2.1.0 §3.27.10 lets a result omit level and defer to the rule's defaultConfiguration — and a scanner that does so was mis-read by Tamp before 1.21.0 (tamp#166): the absent member was overwritten with default(SarifLevel), i.e. None, and written back into the evidence file as "level": "none".

ZAP's own output was therefore largely unaffected. Scanners that do lean on defaultConfiguration were not, so if you ingest ZAP alongside others, 1.21.0 is still the floor worth pinning.

See also

Settings authoring style

The example(s) above use the fluent Set*-chain shape. Every wrapper verb on this page also accepts a new XxxSettings { ... } object-init form. Both produce identical CommandPlans; the fluent shape stays canonical in docs and the tamp init template. See Build Script Authoring → Two authoring styles for the side-by-side comparison.

Clone this wiki locally