Skip to content

Latest commit

 

History

History
554 lines (427 loc) · 24.7 KB

README.md

File metadata and controls

554 lines (427 loc) · 24.7 KB

Scanner Benchmark Framework

This framework grades a security scanner against the ground truth that VulnerableApp already ships. It supports two scan modes today:

  • DAST — graded against the live /scanner/dast endpoint (URL + vulnerability type).
  • SAST — graded against the expected-issues ground truth served by /scanner/sast (file path + line + CWE / vulnerability type).

You POST the scanner's findings as JSON to /scanner/benchmark; the framework returns coverage, missed issues, and unmatched items (findings the scanner reported that don't line up with any ground-truth row), and writes a JSON report to benchmarks/<tool>-results.json.

Running the scanner itself is out of scope. You are responsible for running ZAP / Burp / Semgrep / your tool against VulnerableApp (or its source tree) and converting its output into the input format below.


ZAP By Checkmarx

ZAP is benchmarked against VulnerableApp in two modes — Modern UI (React frontend via VulnerableApp-facade) and Legacy UI (JSP backend directly).

Latest results

UI Results file
Modern benchmarks/ZAP/zap-results.json
Legacy benchmarks/ZAP/zap-results-legacy.json

Results are auto-updated everyday and on every manual workflow run.

Running the benchmark

The full pipeline (start VulnerableApp → run ZAP → convert → benchmark → commit results) is automated via GitHub Actions:

  1. Go to Actions tab → ZAP Benchmark
  2. Click Run workflow
  3. Select legacy, modern, or both
  4. Results are committed automatically to the files above See .github/workflows/zap-benchmark.yml for the full workflow definition.

Conversion script

ZAP's raw JSON report must be converted to the benchmark input format before posting to the endpoint:

python3 benchmarks/ZAP/scripts/convert_zap_to_benchmark.py \
    --input  benchmarks/ZAP/zap-raw-report.json \
    --output benchmarks/ZAP/zap-benchmark-input.json

The script maps each ZAP alert instance to a Finding using CWE and WASC IDs natively — no manual alert-name mapping needed.

A sample benchmark output is at benchmarks/ZAP/zap-results.json.


Semgrep

Semgrep is benchmarked in SAST mode against the VulnerableApp source tree.

Latest results

Ruleset Results file
p/default benchmarks/Semgrep/semgrep-results.json

Results are auto-updated on master every day and on every manual workflow run. Each run installs the latest Semgrep release and prints its version in the run log.

Running the benchmark

The full pipeline (build the VulnerableApp image from the checkout, start the Docker stack like the ZAP benchmark, run Semgrep, convert, benchmark, commit results) is automated via GitHub Actions:

  1. Open the Actions tab and pick Semgrep Benchmark
  2. Click Run workflow
  3. On master, results are committed automatically to the file above, along with the converted findings in benchmarks/Semgrep/findings/semgrep-findings.json. On other branches, nothing is committed; download the semgrep-benchmark-artifacts artifact of the run instead.

See .github/workflows/semgrep-benchmark.yml for the full workflow definition.

To run it locally:

  1. Run the scan from the repository root, so that Semgrep reports project-relative paths. That is what the SAST matcher compares.

    semgrep scan --config p/default --metrics=off --timeout 30 --json \
        --output benchmarks/Semgrep/semgrep-raw-report.json src/main/java
  2. Convert the report with the script described below.

  3. Start VulnerableApp from the same checkout (./gradlew bootRun, port 9090), so that the ground truth it serves matches the sources that were scanned.

  4. Post the findings and save the response:

    curl -s -X POST http://localhost:9090/VulnerableApp/scanner/benchmark \
        -H "Content-Type: application/json" \
        -d @benchmarks/Semgrep/findings/semgrep-findings.json \
        -o benchmarks/Semgrep/semgrep-results.json

Conversion script

Semgrep's JSON report must be converted to the benchmark input format before posting to the endpoint:

python3 benchmarks/Semgrep/scripts/convert_semgrep_to_benchmark.py \
    --input  benchmarks/Semgrep/semgrep-raw-report.json \
    --output benchmarks/Semgrep/findings/semgrep-findings.json

The script emits one finding per CWE of each Semgrep result: the path, the start line, the CWE ID, and the rule's vulnerability_class as the type. When a rule lists several CWEs, only the first finding carries the type, because the SAST matcher skips a finding that repeats the file, line and type of an earlier one. A result with neither a CWE nor a vulnerability_class is skipped with a warning, because the matcher cannot score it. No manual rule mapping is needed.


CodeQL

CodeQL is benchmarked in SAST mode against the VulnerableApp source tree.

See benchmarks/CodeQL/README.md for workflow instructions, local execution, bundle configuration, query coverage, conversion details, and the latest benchmark results.


SpotBugs with FindSecBugs

SpotBugs, enhanced with the FindSecBugs security rules plugin, is benchmarked in SAST mode against VulnerableApp's compiled bytecode. SpotBugs runs via a dynamic Gradle init script without requiring permanent scanner plugins in build.gradle.

Latest results

Tool Results file Raw XML Report
SpotBugs + FindSecBugs benchmarks/SpotBugs/spotbugs-results.json benchmarks/SpotBugs/spotbugs-raw-report.xml

Results are auto-updated on master every day and on every manual workflow run.

Running the benchmark

The full pipeline (build the VulnerableApp image from the checkout, start the Docker stack, run SpotBugs with FindSecBugs, convert, benchmark, commit results and raw XML) is automated via GitHub Actions:

  1. Open the Actions tab and pick SpotBugs Benchmark
  2. Click Run workflow
  3. On master, results and raw reports are committed automatically to the files above, along with converted findings in benchmarks/SpotBugs/findings/spotbugs-findings.json.

See .github/workflows/spotbugs-benchmark.yml for the full workflow definition.

For local execution instructions, CLI options, and conversion script details, see benchmarks/SpotBugs/README.md.


w3af

w3af is benchmarked in DAST mode. See benchmarks/w3af/README.md for the scan setup, the conversion script, and the latest results.

Wapiti

Wapiti is benchmarked against VulnerableApp using its DAST scanner.

Latest results

Scanner Results file
Wapiti benchmarks/Wapiti/wapiti-results.json

Results are auto-updated daily via .github/workflows/wapiti-benchmark.yml.

Conversion script

Convert Wapiti's JSON report (-f json) into the benchmark input format:

python3 benchmarks/Wapiti/scripts/convert_wapiti_to_benchmark.py \
    --input  benchmarks/Wapiti/wapiti-raw-report.json \
    --output benchmarks/Wapiti/findings/wapiti-findings.json

The script emits one finding per CWE reference in Wapiti's classifications: the URL, HTTP method, the CWE ID, and the mapped vulnerability type (if applicable). When a category lists several CWEs (e.g. Resource consumption with CWE-405 and CWE-400), each CWE reference produces a finding so that the benchmark matcher can evaluate all applicable CWE definitions.

See benchmarks/Wapiti/README.md for local scan and reproduction instructions.


Choosing a scan type

The optional scanType field on the request body selects the strategy. When omitted, it defaults to DAST so existing payloads keep working.

scanType Ground truth Per-finding fields
DAST (default) live /scanner/dast endpoint url, type
SAST /scanner/sast (from expectedIssues.csv) filePath, line, plus cwe and/or type

DAST ground-truth schema

This schema applies to each row returned by GET /scanner/dast as applications adopt it.

Field Contract
cweIds Always present. JSON array of unique positive CWE integers, sorted in ascending numeric order.
wascIds Always present. JSON array of unique positive WASC integers, sorted in ascending numeric order.
vulnerabilityTypes Keep the existing field and values until consumers have migrated.
protocol Always present as "HTTP" or "WS". Preserve the endpoint's protocol.

Derive both ID arrays from the application's existing vulnerability metadata (VulnerabilityType in Java). Combine the IDs for all types in the row, omitting missing mappings and non-positive IDs such as 0 and -1. Use [] when a field has no valid IDs. Serialize IDs as numbers, for example 79. Deduplicate each array independently. The two arrays have no positional relationship, so their indexes cannot be used to pair a CWE with a WASC.

The following example has two XSS types with the same IDs. File upload contributes CWE 434 and has no WASC mapping.

{
  "url": "https://example.test/VulnerableApp/example",
  "variant": "UNSECURE",
  "method": "POST",
  "protocol": "HTTP",
  "vulnerabilityTypes": ["UNRESTRICTED_FILE_UPLOAD", "PERSISTENT_XSS", "REFLECTED_XSS", "PATH_TRAVERSAL"],
  "cweIds": [22, 79, 434],
  "wascIds": [8, 33]
}

The Java and PHP applications share this row format. PHP converts its stored string IDs to integers and uses "HTTP" for its HTTP endpoints. The facade groups responses by application and passes through the fields each application returns. During rollout, a legacy row can omit the new fields. An empty array from an updated application means the row has no mapping for that ID system.

DAST input format

{
  "tool": "ZAP",
  "scanType": "DAST",
  "findings": [
    { "url": "/BlindSQLInjectionVulnerability/LEVEL_1", "type": "BLIND_SQL_INJECTION" },
    { "url": "/ErrorBasedSQLInjectionVulnerability/LEVEL_1", "cwe": "CWE-89" },
    { "url": "/PathTraversal/LEVEL_1", "wascId": "33" }
  ]
}
  • findings[].url — relative path (/SQLInjection/LEVEL_1) or absolute URL (http://localhost:9090/VulnerableApp/SQLInjection/LEVEL_1); the comparator normalises both. Query strings, the /VulnerableApp context path, and trailing slashes are stripped.
  • findings[].type — case-insensitive match against VulnerabilityType enum names. See the canonical values below.
  • findings[].cwe — optional. Numeric (89) or CWE--prefixed (CWE-89); matches against VulnerabilityType.getCweID().
  • findings[].wascId — optional. Numeric; matches against VulnerabilityType.getWascID().
  • findings[].method — optional. HTTP method (GET, POST, …); matches against the ground-truth row's request method. See "DAST matching rules" below for the omitted-method semantics.

DAST matching rules

A scanner finding matches a ground-truth row when all three of these hold:

  1. The URL agrees, AND
  2. The HTTP method check passes (opt-in — see below for the omitted-method semantics), AND
  3. Any one of these axes agrees:
    • type matches the VulnerabilityType enum name (case-insensitive), OR
    • cwe matches the type's cweID, OR
    • wascId matches the type's wascID.

The method check is opt-in: if your scanner emits a method field, it is matched strictly (POST vs ground-truth GET becomes unmatched). If the field is omitted, the finding matches the URL's ground-truth row regardless of method — leniency for scanners whose output format does not include the method. This means existing payloads continue to work; emit method to enable the stricter check.

The ground truth says whether each entry is HTTP or WebSocket (protocol; entries without it are HTTP). The method check applies to HTTP entries only. A WebSocket entry is matched on its URL and one of the axes, whatever method the finding carries, since a WebSocket level is always opened with a GET handshake. WebSocket items in the report have no method.

A scanner that emits multiple axes (type + cwe, etc.) for the same alert is counted once. A finding that matches no axis on any expected URL ends up in unmatchedItems.

Canonical DAST vulnerability type values

If you choose to match by type, the full set lives in VulnerabilityType.java; common values:

BLIND_SQL_INJECTION, ERROR_BASED_SQL_INJECTION, UNION_BASED_SQL_INJECTION,
REFLECTED_XSS, PERSISTENT_XSS, DOM_BASED_XSS,
COMMAND_INJECTION, PATH_TRAVERSAL, HEADER_INJECTION, XXE,
OPEN_REDIRECT_3XX_STATUS_CODE, SIMPLE_SSRF, BLIND_SSRF,
LDAP_INJECTION, INSECURE_DIRECT_OBJECT_REFERENCE,
UNRESTRICTED_FILE_UPLOAD, UNCONTROLLED_RESOURCE_CONSUMPTION,
WEAK_CRYPTOGRAPHIC_HASH, INSECURE_CRYPTOGRAPHIC_STORAGE,
USE_OF_BROKEN_CRYPTOGRAPHIC_ALGORITHM, CLICKJACKING,
PLAINTEXT_PASSWORD_STORAGE, WEAK_PASSWORD_HASHING, USERNAME_ENUMERATION,
WEB_CACHE_POISONING

SAST input format

{
  "tool": "Semgrep",
  "scanType": "SAST",
  "findings": [
    {
      "filePath": "src/main/java/org/sasanlabs/service/vulnerability/sqlInjection/BlindSQLInjectionVulnerability.java",
      "line": 93,
      "cwe": "CWE-89",
      "type": "SQL Injection"
    }
  ]
}

The full sample at benchmarks/semgrep-sast-sample.json includes one deliberately invalid entry so a successful run produces a non-empty unmatchedItems list.

Ground truth is loaded from src/main/resources/scanner/sast/expectedIssues.csv, which ships inside the jar, so it resolves regardless of the working directory the app was started from. The same rows are served as JSON by GET /scanner/sast. The source is configurable via the benchmark.sast.ground-truth.path property (default: classpath:scanner/sast/expectedIssues.csv); a value without the classpath: prefix is read from the filesystem, relative to the working directory or absolute.

What a ground-truth row points at

Each row of expectedIssues.csv gives the line of the vulnerable statement, which is the line a SAST tool is expected to report:

  • Where user input reaches a dangerous call (a query, a process, a file or network access, a response), it is the line on which the input reaches that call. When the call is split over several lines, that is the line of the argument that carries the input, not the line where the call starts.
  • Where there is no such call (a weak hash, a missing check, a token accepted without verification), it is the line of the weak call or the faulty check. That line can be in a service class such as AuthLoginService or JWTValidator when the flawed code lives there.

When several vulnerable levels go through the same line, for example a helper shared by all levels of a class, there is one row for that line and Number of Sources holds the number of levels that expose the issue through it. Levels marked Variant.SECURE have no rows.

LineCount is the number of lines the vulnerable statement occupies: 1 if it fits on one line, 2 if it takes two, and so on. When it is above 1, Line is the first line of the statement rather than the argument line described above, and a finding on any line from Line to Line + LineCount - 1 matches the row. When the statement passes a lambda with a block body, such as a row mapper (rs) -> { ... }, the range stops on the line before that lambda, so it covers the call and its arguments but not the lambda's body. The column is optional. A CSV without it, or a row that leaves it empty, gets 1, which keeps the exact Line match.

A row never points at an annotation, including any line a multi-line annotation spans, a comment, a blank line or a brace, and a row with a LineCount above 1 also ends on a line of code inside the file. ExpectedIssuesAlignmentTest fails the build when a row breaks either rule, which is what happens when a vulnerable class is edited and its rows are not moved with it.

SAST matching rules

A finding matches an expected issue when:

  1. The normalised filePath matches, AND
  2. The line is between Line and Line + LineCount - 1, which is exactly Line when LineCount is 1 (the default), AND
  3. The finding's cwe matches the CSV's CWE column. When the finding or the row has no CWE, the finding's type is matched against the Vulnerability Type column (case-insensitively) instead.

A finding whose CWE differs from the row's does not match, even when its type matches the row's Vulnerability Type.

  • Path normalisation: backslashes → forward slashes; leading ./ stripped; whitespace trimmed. Scanner authors should emit project-relative paths; absolute paths or unexpected prefixes will not match.
  • CWE comparison: upper-cased + trimmed (e.g. cwe-89 and CWE-89 both match).
  • Type comparison: lower-cased + trimmed (e.g. "SQL Injection" and "sql injection" both match).
  • Duplicates: a finding with a CWE is counted once per (filePath, line, CWE), so two findings on one line with different CWEs are both kept. A finding without a CWE is counted once per (filePath, line, type), and not at all when a finding with a CWE on the same file and line has the same type, whichever of the two comes first.
  • Line ranges: several findings inside one row's range detect that row once, and none of them is counted as unmatched. A finding inside the ranges of two rows detects both. A row that no finding matches is listed in missedItems at its Line.
  • Number of Sources column: the number of vulnerable levels that expose the issue through that line (1 unless several levels share it). It is there for human reference and is not used for scoring: the first match gets full credit.

Calling the endpoint

# DAST
curl -X POST http://localhost/VulnerableApp/scanner/benchmark \
  -H "Content-Type: application/json" \
  -d @benchmarks/ZAP/findings/zap-findings.json

# SAST
curl -X POST http://localhost/VulnerableApp/scanner/benchmark \
  -H "Content-Type: application/json" \
  -d @benchmarks/semgrep-sast-sample.json

The HTTP response contains the same JSON that gets persisted to disk.

Output format

The output schema is the same for DAST and SAST. The fields inside each detectedItems / missedItems / unmatchedItems entry vary by scan type (unused fields are omitted from the JSON).

{
  "tool": "ZAP",
  "coverage": 4.29,
  "totalExpected": 140,
  "detected": 6,
  "missed": 134,
  "unmatched": 147,
  "detectedItems":   [ { "url": "/...", "type": "..." } ],
  "missedItems":     [ { "url": "/...", "type": "..." } ],
  "unmatchedItems":  [ { "url": "/...", "cwe": "..." } ]
}

For SAST runs, items look like:

{ "filePath": "src/main/java/.../Foo.java", "line": 56, "type": "SQL Injection", "cwe": "CWE-89" }
  • coverage — detected / totalExpected * 100. Reported as 0.0 when ground truth is empty.
  • totalExpected — number of unique ground-truth items. For DAST, count of (URL, vulnerabilityType) pairs across all UNSECURE ground-truth entries, HTTP and WebSocket alike (SECURE entries are intentionally clean and don't count). For SAST, count of rows in the CSV.
  • detectedItems — expected items the scanner reported. Results written before this field existed omit it.
  • missedItems — expected items the scanner did not report.
  • unmatchedItems — items the scanner reported that don't line up with any expected ground-truth row.

Configuration

Property Default Purpose
benchmark.output.dir benchmarks Directory the JSON report is written to.
benchmark.dast.ground-truth.url http://localhost:${server.port:9090}${server.servlet.context-path:/VulnerableApp}/scanner/dast URL the DAST comparator fetches ground truth from. Override when running behind VulnerableApp-facade so coverage spans every backing app.
benchmark.dast.ground-truth.connect-timeout-ms 5000 Connect timeout (ms) for the ground-truth fetch. Fail-fast bound so a stalled endpoint can't tie up Tomcat request threads.
benchmark.dast.ground-truth.read-timeout-ms 10000 Read timeout (ms) for the ground-truth fetch.
benchmark.sast.ground-truth.path classpath:scanner/sast/expectedIssues.csv CSV the SAST comparator loads expected issues from, and /scanner/sast serves. Drop the classpath: prefix to read a file from disk instead.

The default DAST URL is a self-call against the running app, which means benchmarking works out of the box in standalone mode. In a facade-composed deployment, point this at the facade's aggregated /scanner/dast endpoint so scanner findings are graded against the union of every backing app's ground truth.

Where the report is written

By default, benchmarks/<sanitised-tool>-results.json relative to the working directory of the running VulnerableApp process. The directory is configurable via benchmark.output.dir. Filenames are lowercased and stripped of anything outside [a-z0-9_-]. Re-running the endpoint for the same tool (regardless of scan type) overwrites the previous report.

If the file write fails (disk full, permissions, etc.), the endpoint returns HTTP 500 with the same response body as a successful run, plus an extra persistenceError string describing the failure. Callers still get the computed metrics; the non-2xx status is the signal that the on-disk artifact was not created.

Known Limitations

SSL/TLS and header-hardening findings are always unmatched (all DAST scanners)

DAST scanners commonly report findings such as missing Strict-Transport-Security, X-Content-Type-Options, or insecure cookie flags. These are valid security observations but fall outside VulnerableApp's intentional vulnerability set. They will always appear in unmatchedItems and should not be interpreted as false positives. This applies to any DAST scanner benchmarked against VulnerableApp.

A finding on another line of the same flow is unmatched (all SAST scanners)

The SAST matcher only credits a finding on a line from Line to Line + LineCount - 1, which is just Line for a row whose LineCount is 1. A scanner that reports a real issue on another line of the same data flow gets no credit for it: the expected row shows up in missedItems and the finding in unmatchedItems. For example, Semgrep reports SSRF where the URL object is built (SSRFVulnerability.java:73), while the expected row is the openConnection() call at line 91.

unmatchedItems also holds findings on levels marked Variant.SECURE, findings outside the intended vulnerability set (CSRF on request mappings, cookie flags), and findings in classes that have no ground-truth rows yet, so it should not be read as a list of false positives.