Skip to main content
Security guideReviewed

DAST: what a dynamic scanner reaches in your running application, and how to check its coverage

Dynamic application security testing (DAST) uses a running copy of your application from the outside, the way a visitor would, and judges it by the responses.

A scanner can only test what it finds and what its accounts can open. This guide explains how a scanner discovers pages, forms and API operations, why it has to sign in and how it loses its session, and how to read a result that says nothing was found. It comes with a coverage map to fill in from your own scanner and a local lab that shows coverage dropping when a session is lost part way through.

DAST coverage map and local scanning lab

An illustration written for this page, not client code. Five blank tables to fill in from your own scanner on your own staging site (routes, forms, API operations, a session check, and expected findings against evidence), and a Node.js lab that imports only node: modules and installs no packages: a target on 127.0.0.1 that keeps its own route list, a crawler that reads HTML text, the coverage map it printed with every session kept and with sessions ending early, and a node:test regression test that fails when coverage drops.

How to use it

Recorded on macOS 27.2.1 with Node.js v26.0.0.

dast.txt

ILLUSTRATION ONLY. The target application, its accounts, its orders, the crawler and every result below were written and recorded for this page. They are not a client's application or a client's result, and the crawler is not a scanner. Run the lab on your own computer to see how coverage is measured. Point a real scanner only at an application you own or have written permission to test, and prefer a staging copy with test accounts and test data: a scan sends requests that can create, change or delete data.

This asset has four parts:
  PART 1. A coverage map to fill in from your own scanner's results on your own staging site: five blank tables and how to read them.
  PART 2. A local lab in Node.js that imports only node: modules and installs no packages: a target application that keeps its own route list, and a small crawler.
  PART 3. The coverage map the lab printed, first with every session kept, then with the target ending each session early.
  PART 4. A regression test that pins what each pass discovers, with a passing run and a failing one.

==== PART 1. YOUR COVERAGE MAP ====
BEFORE YOU START
1. Get written permission for the target and the scan window, and keep it with the scan record. Use a staging copy where you can.
2. Build the route list from the application itself, not from the scan: the framework's route files or router, the API description, and the developers who wrote it. A list copied from the scan can only agree with the scan.
3. Give the scanner one test account for each role, and note the logged-in indicator it uses to tell a signed-in response from a signed-out one, such as a sign-out link, the account name or a status code.
4. Exclude the sign-out link, and every form or operation that deletes, pays, emails people or changes another account, unless the test data was set up for it.
5. After the scan, export what it reached for each account: its site map, crawl log or list of requests. A report that lists findings without the URLs that were tested cannot be reconciled with your route list.

The tables use pipes so they paste into a spreadsheet. Add a column for each role your application has.

TABLE A. PAGES, FILES AND ROUTES
One row for every route on your list. In each scan column write one of: found; seen, not visited (skipped on purpose, such as the sign-out link); or not found, with the reason: needs sign-in, needs role (name it), added by script, form not submitted, only in API description, not referenced, session lost, blocked (403, 429 or a firewall page), error.

Route | How a visitor reaches it | Who may open it | Signed out | Role: | Role: | Notes
      |                          |                 |            |       |       |
      |                          |                 |            |       |       |
      |                          |                 |            |       |       |

TABLE B. FORMS
One row for every form. In each scan column write: found, submitted; found, not submitted; or not found, with the reason.

Form | Method and action | On page | Changes data? | Signed out | Role: | Role:
     |                   |         |               |            |       |
     |                   |         |               |            |       |

TABLE C. API OPERATIONS
One row for every operation in your API description, plus any route the code serves that the description leaves out. In each scan column write the status code the scan recorded, or not sent, with the reason (changes data, needs a path value, excluded). Then compare each status with your own rule for who may call the operation.

Operation (method and path) | Roles the description lists | Your rule: who may call it | Signed out | Role: | Role: | Matches your rule?
                            |                             |                            |            |       |       |
                            |                             |                            |            |       |       |

TABLE D. SESSION CHECK
One row for every signed-in identity the scan used.

Identity and role | Logged-in indicator | Requests sent | Signed-in routes found, this run and last run | First sign of a lost session (request number and what came back) | Signed in again? | Action
                  |                     |               |                                               |                                                                   |                  |
                  |                     |               |                                               |                                                                   |                  |

TABLE E. EXPECTED FINDINGS AND EVIDENCE
Before you read the scanner's report, list what you expect it to show: issues from earlier reports and tests, bugs fixed since the last scan, and checks you set up on purpose, such as a header every signed-in page should carry. For each one, write which identity could reach it and what evidence would show it: a response read passively, an active check, or a person who knows the rule. Then record what this scan did: CAPTURED (evidence in the report), REACHED, NOT SHOWN (the route is in coverage but no evidence came back), or UNTESTED (the route was not reached).

Expected finding | Where | Identity that could reach it | Evidence that would show it | This scan | Next step
                 |       |                              |                             |           |
                 |       |                              |                             |           |

READING THE FILLED MAP
1. A route, form or operation with no "found" in any column was outside this scan. Write it into the scan record as not covered.
2. A role column that looks like the signed-out column means the scan never got past sign-in for that role.
3. A lower count of signed-in routes than last run, or any "session lost", means the clean areas of this report cannot be compared with the last one. Fix the sign-in or session settings and run it again before reading the findings.
4. REACHED, NOT SHOWN means the check that would show the problem either did not run on that route or did not fire. Find out which before treating the item as fixed.
5. UNTESTED is not a pass. As far as this scan can say, the item is still open.
6. A status that breaks your rule in Table C is evidence for a person to judge. The scanner recorded what happened; only your rule says whether it should have.
7. Keep the filled map with the scan record, compare the counts on the next run, and pin the counts that matter in a regression test like the one in Part 4.

==== PART 2. THE LOCAL LAB ====
WHAT IT NEEDS
Node.js, and no packages: the five files import only node:http, node:crypto, node:process, node:url, node:assert and node:test, besides each other. The test uses node:test, which the Node.js documentation marks stable from v20.0.0. The results below were recorded with Node.js v26.0.0 on macOS 27.2.1.

WHAT IT DOES AND DOES NOT DO
The target listens on 127.0.0.1 only, on a port the system picks, and run-map.mjs refuses any address that is not on 127.0.0.1. The accounts, passwords and orders are invented. The crawler reads the HTML text of each response and follows the links, script file references and form actions it finds there. It runs no script, so it behaves like a crawler that reads page text, not one that drives a browser. It is not a scanner and sends no test inputs. Besides plain GET requests it sends two forms: the sign-in form, at the start of each signed-in pass, and the profile form, once in each signed-in pass, with the value the form already holds. It never follows the sign-out link. The API description pass reads /openapi.json and sends one plain GET to each GET operation that needs no path value, signed out and then as each role.

THE TARGET, IN SHORT (target.mjs keeps these lists, and the map is built from them)
Routes: 17 pages and files, 4 forms and 5 API operations, for two invented accounts: casey.user (role user) and ari.admin (role admin). The routes are reached in these ways: linked from a public page; linked only after sign-in; linked only for the admin role; reached only by submitting a form (the profile form, which the crawler submits, and the help search form, which it does not); a link that only a script adds; listed only in the API description; and not referenced anywhere.
Expected findings, all harmless and invented:
  F1  /admin/users is the one signed-in page sent without Cache-Control: no-store. The lab's own rule is that every page showing the signed-in banner carries that header.
  F2  /help/search returns the search term in a plain-text response.
  F3  GET /api/orders/export answers for the user role, while the API description lists the admin role for it.
  F4  /old/orders-report, an older page that nothing links to, answers without sign-in.

SET-UP
Make an empty folder, save the five files below into it under the names shown, and run the commands under RUN IT from that folder.

==== File 1 of 5: target.mjs ====
// target.mjs: the lab's own target application. It imports only node:
// modules and needs no packages. It listens on 127.0.0.1 at a port the
// system picks, holds two invented accounts, and keeps its own list of every
// route, form and API operation (the ground truth), plus the four harmless
// findings it was built to contain. Run it with: node target.mjs
// LAB_SESSION_LIMIT=4 makes it end each session after four signed-in
// requests, the way a short session timeout would.
import crypto from 'node:crypto'
import http from 'node:http'
import process from 'node:process'
import { fileURLToPath } from 'node:url'

export const ACCOUNTS = {
  user: { username: 'casey.user', password: 'lab-user-password', role: 'user', name: 'Casey' },
  admin: { username: 'ari.admin', password: 'lab-admin-password', role: 'admin', name: 'Ari' },
}

// Ground truth. visibleTo says who sees a reference to the route in normal
// use; reach says how a visitor gets there.
export const ROUTES = [
  { path: '/', visibleTo: 'anyone', reach: 'linked' },
  { path: '/about', visibleTo: 'anyone', reach: 'linked' },
  { path: '/help', visibleTo: 'anyone', reach: 'linked' },
  { path: '/login', visibleTo: 'anyone', reach: 'linked' },
  { path: '/help/search', visibleTo: 'anyone', reach: 'search form' },
  { path: '/old/orders-report', visibleTo: 'anyone', reach: 'not referenced' },
  { path: '/openapi.json', visibleTo: 'anyone', reach: 'API description' },
  { path: '/account', visibleTo: 'signed-in', reach: 'linked' },
  { path: '/account/orders', visibleTo: 'signed-in', reach: 'linked' },
  { path: '/account/profile', visibleTo: 'signed-in', reach: 'linked' },
  { path: '/account/profile/saved', visibleTo: 'signed-in', reach: 'profile form' },
  { path: '/account/reports', visibleTo: 'signed-in', reach: 'script' },
  { path: '/static/account.js', visibleTo: 'signed-in', reach: 'script file' },
  { path: '/static/orders.js', visibleTo: 'signed-in', reach: 'script file' },
  { path: '/logout', visibleTo: 'signed-in', reach: 'sign-out link' },
  { path: '/admin', visibleTo: 'admin', reach: 'linked' },
  { path: '/admin/users', visibleTo: 'admin', reach: 'linked' },
]

export const FORMS = [
  { name: 'sign-in', page: '/login', method: 'POST', action: '/login', visibleTo: 'anyone' },
  { name: 'help search', page: '/help', method: 'GET', action: '/help/search', visibleTo: 'anyone' },
  { name: 'profile', page: '/account/profile', method: 'POST', action: '/account/profile', visibleTo: 'signed-in' },
  { name: 'disable user', page: '/admin/users', method: 'POST', action: '/admin/users/disable', visibleTo: 'admin' },
]

export const OPERATIONS = [
  { method: 'GET', path: '/api/orders', allowed: 'signed-in', reach: 'script and API description' },
  { method: 'POST', path: '/api/orders', allowed: 'signed-in', reach: 'API description' },
  { method: 'GET', path: '/api/orders/{orderId}', allowed: 'signed-in', reach: 'API description' },
  { method: 'GET', path: '/api/orders/export', allowed: 'admin', reach: 'API description' },
  { method: 'GET', path: '/api/admin/stats', allowed: 'admin', reach: 'API description' },
]

export const EXPECTED_FINDINGS = [
  { id: 'F1', label: 'Signed-in page sent without Cache-Control: no-store', where: 'GET /admin/users' },
  { id: 'F2', label: 'Search term reflected in a plain-text response', where: 'GET /help/search?q=' },
  { id: 'F3', label: 'Export answers for the user role', where: 'GET /api/orders/export' },
  { id: 'F4', label: 'Old report answers without sign-in', where: 'GET /old/orders-report' },
]

const ORDERS = [
  { id: '1001', owner: 'casey.user', item: 'Lavender, 12 pots' },
  { id: '1002', owner: 'other.customer', item: 'Rosemary, 6 pots' },
]

function buildApiDescription() {
  const signedIn = [{ labSession: [] }]
  const adminOnly = [{ labSession: ['admin'] }]
  const orderId = [{ name: 'orderId', in: 'path', required: true, schema: { type: 'string' } }]
  return {
    openapi: '3.1.1',
    info: { title: 'Lab orders API', version: '1.0.0' },
    servers: [{ url: '/' }],
    components: { securitySchemes: { labSession: { type: 'apiKey', in: 'cookie', name: 'lab_session' } } },
    paths: {
      '/api/orders': {
        get: { operationId: 'listOrders', security: signedIn, responses: { 200: { description: 'Your orders' } } },
        post: { operationId: 'createOrder', security: signedIn, responses: { 201: { description: 'Created' } } },
      },
      '/api/orders/{orderId}': {
        get: { operationId: 'getOrder', parameters: orderId, security: signedIn, responses: { 200: { description: 'One order' } } },
      },
      '/api/orders/export': {
        get: { operationId: 'exportOrders', security: adminOnly, responses: { 200: { description: 'Every order' } } },
      },
      '/api/admin/stats': {
        get: { operationId: 'adminStats', security: adminOnly, responses: { 200: { description: 'Counts' } } },
      },
    },
  }
}

// ---- Sessions ----

function findAccount(username) {
  for (const key of Object.keys(ACCOUNTS)) {
    if (ACCOUNTS[key].username === username) return ACCOUNTS[key]
  }
  return null
}

function readSessionId(request) {
  const header = request.headers.cookie || ''
  for (const part of header.split(';')) {
    const pair = part.trim().split('=')
    if (pair[0] === 'lab_session') return pair[1]
  }
  return ''
}

// Returns the signed-in account, or null. When a session limit is set, the
// session ends once it has answered that many signed-in requests.
function readAccount(state, request) {
  const sessionId = readSessionId(request)
  const session = state.sessions.get(sessionId)
  if (!session) return null
  session.requests = session.requests + 1
  if (state.sessionLimit > 0 && session.requests > state.sessionLimit) {
    state.sessions.delete(sessionId)
    state.log('session for ' + session.account.username + ' ended after ' + state.sessionLimit + ' signed-in requests')
    return null
  }
  return session.account
}

// ---- Responses ----

function sendHtml(response, status, title, body, headers) {
  const page = '<!doctype html><html><head><title>' + title + '</title></head><body>' + body + '</body></html>'
  response.writeHead(status, Object.assign({ 'Content-Type': 'text/html; charset=utf-8' }, headers || {}))
  response.end(page)
}

function sendText(response, status, text) {
  response.writeHead(status, { 'Content-Type': 'text/plain; charset=utf-8' })
  response.end(text)
}

function sendJson(response, status, value) {
  response.writeHead(status, { 'Content-Type': 'application/json' })
  response.end(JSON.stringify(value))
}

function redirect(response, location, headers) {
  response.writeHead(303, Object.assign({ Location: location }, headers || {}))
  response.end()
}

const NO_STORE = { 'Cache-Control': 'no-store' }

function signedInBanner(account) {
  return '<p>Signed in as ' + account.name + '</p>'
}

// ---- Public pages ----

function homePage(response) {
  const links = '<a href="/about">About</a> <a href="/help">Help</a> <a href="/login">Sign in</a> <a href="/account">Your account</a>'
  sendHtml(response, 200, 'Home', '<h1>Lab plant nursery orders</h1>' + links)
}

function aboutPage(response) {
  sendHtml(response, 200, 'About', '<h1>About</h1><p>An invented business for the lab.</p><a href="/">Home</a>')
}

function helpPage(response) {
  const form = '<form method="GET" action="/help/search"><input name="q" value=""><button>Search</button></form>'
  sendHtml(response, 200, 'Help', '<h1>Help</h1>' + form + '<a href="/">Home</a>')
}

// F2: the search term comes back in a plain-text response.
function helpSearch(response, url) {
  sendText(response, 200, 'No help articles match: ' + (url.searchParams.get('q') || ''))
}

// F4: an older report that nothing links to, still answering without sign-in.
function oldOrdersReport(response) {
  sendText(response, 200, 'Order report (old version): ' + ORDERS.length + ' orders this week')
}

function loginPage(response, message) {
  const fields = '<input name="username" value=""><input name="password" type="password" value="">'
  const form = '<form method="POST" action="/login">' + fields + '<button>Sign in</button></form>'
  sendHtml(response, 200, 'Sign in', '<h1>Sign in</h1>' + (message || '') + form)
}

async function readForm(request) {
  let body = ''
  for await (const chunk of request) body = body + chunk
  return new URLSearchParams(body)
}

async function signIn(state, request, response) {
  const form = await readForm(request)
  const account = findAccount(form.get('username'))
  if (!account || account.password !== form.get('password')) return loginPage(response, '<p>Sign-in failed.</p>')
  const sessionId = crypto.randomBytes(16).toString('hex')
  state.sessions.set(sessionId, { account: account, requests: 0 })
  redirect(response, '/account', { 'Set-Cookie': 'lab_session=' + sessionId + '; HttpOnly; SameSite=Lax; Path=/' })
}

function signOut(state, request, response) {
  state.sessions.delete(readSessionId(request))
  redirect(response, '/', { 'Set-Cookie': 'lab_session=; Max-Age=0; Path=/' })
}

// ---- Signed-in pages ----

function accountPage(response, account) {
  let links = '<a href="/account/orders">Orders</a> <a href="/account/profile">Profile</a> <a href="/logout">Sign out</a> <a href="/">Home</a>'
  if (account.role === 'admin') links = links + ' <a href="/admin">Admin</a>'
  const script = '<nav id="extra"></nav><script src="/static/account.js"></script>'
  sendHtml(response, 200, 'Account', signedInBanner(account) + links + script, NO_STORE)
}

function ordersPage(response, account) {
  const body = signedInBanner(account) + '<div id="orders">Loading orders</div><script src="/static/orders.js"></script><a href="/account">Account</a>'
  sendHtml(response, 200, 'Orders', body, NO_STORE)
}

function profilePage(response, account) {
  const field = '<input name="display_name" value="' + account.name + '">'
  const form = '<form method="POST" action="/account/profile">' + field + '<button>Save</button></form>'
  sendHtml(response, 200, 'Profile', signedInBanner(account) + form + '<a href="/account">Account</a>', NO_STORE)
}

async function saveProfile(state, request, response, account) {
  const form = await readForm(request)
  const unchanged = form.get('display_name') === account.name
  state.log('profile saved for ' + account.username + (unchanged ? ' (value unchanged)' : ' (value changed)'))
  redirect(response, '/account/profile/saved')
}

function profileSavedPage(response, account) {
  sendHtml(response, 200, 'Saved', signedInBanner(account) + '<p>Profile saved.</p><a href="/account">Account</a>', NO_STORE)
}

// Reached only through a link that /static/account.js adds when it runs.
function reportsPage(response, account) {
  sendHtml(response, 200, 'Reports', signedInBanner(account) + '<h1>Reports</h1>', NO_STORE)
}

// The path is split in two so that the link exists only once the script runs.
const ACCOUNT_SCRIPT = [
  'var link = document.createElement("a");',
  'link.href = "/account/" + "reports";',
  'link.textContent = "Reports";',
  'document.getElementById("extra").appendChild(link);',
].join('\n')

const ORDERS_SCRIPT = [
  'fetch("/api/orders").then(function (reply) { return reply.json(); }).then(function (orders) {',
  '  document.getElementById("orders").textContent = orders.length + " orders";',
  '});',
].join('\n')

function sendScript(response, source) {
  response.writeHead(200, { 'Content-Type': 'text/javascript' })
  response.end(source)
}

// ---- Administrator pages ----

function adminPage(response, account) {
  sendHtml(response, 200, 'Admin', signedInBanner(account) + '<a href="/admin/users">Users</a> <a href="/account">Account</a>', NO_STORE)
}

// F1: the only signed-in page sent without Cache-Control: no-store.
function adminUsersPage(response, account) {
  const form = '<form method="POST" action="/admin/users/disable"><input type="hidden" name="user_id" value="2"><button>Disable</button></form>'
  sendHtml(response, 200, 'Users', signedInBanner(account) + '<p>casey.user, other.customer</p>' + form)
}

// The form on /admin/users posts here. The lab's crawler never submits it.
async function disableUser(state, request, response, account) {
  const form = await readForm(request)
  state.log('user ' + form.get('user_id') + ' disabled by ' + account.username)
  redirect(response, '/admin/users')
}

function notAllowed(response) {
  sendHtml(response, 403, 'Not allowed', '<p>Your role cannot open this page.</p>')
}

// ---- JSON API ----

function ordersFor(account) {
  if (account.role === 'admin') return ORDERS
  return ORDERS.filter(function (order) { return order.owner === account.username })
}

async function handleApi(state, request, response, url, account) {
  if (!account) return sendJson(response, 401, { error: 'sign in first' })
  const path = url.pathname
  if (path === '/api/orders' && request.method === 'GET') return sendJson(response, 200, ordersFor(account))
  if (path === '/api/orders' && request.method === 'POST') {
    state.log('order created by ' + account.username)
    return sendJson(response, 201, { created: true })
  }
  // F3: the description says administrators only, but any signed-in role gets the export.
  if (path === '/api/orders/export') return sendJson(response, 200, ORDERS)
  if (path === '/api/admin/stats') {
    if (account.role !== 'admin') return sendJson(response, 403, { error: 'administrators only' })
    return sendJson(response, 200, { orders: ORDERS.length })
  }
  const order = ordersFor(account).find(function (item) { return '/api/orders/' + item.id === path })
  if (order) return sendJson(response, 200, order)
  sendJson(response, 404, { error: 'not found' })
}

// ---- Routing ----

const PUBLIC_PAGES = {
  '/': homePage,
  '/about': aboutPage,
  '/help': helpPage,
  '/help/search': helpSearch,
  '/old/orders-report': oldOrdersReport,
}

const SIGNED_IN_PAGES = {
  '/account': accountPage,
  '/account/orders': ordersPage,
  '/account/profile': profilePage,
  '/account/profile/saved': profileSavedPage,
  '/account/reports': reportsPage,
}

const ADMIN_PAGES = {
  '/admin': adminPage,
  '/admin/users': adminUsersPage,
}

async function handlePublic(state, request, response, url) {
  const path = url.pathname
  if (PUBLIC_PAGES[path]) {
    PUBLIC_PAGES[path](response, url)
    return true
  }
  if (path === '/openapi.json') {
    sendJson(response, 200, buildApiDescription())
    return true
  }
  if (path === '/login' && request.method === 'POST') {
    await signIn(state, request, response)
    return true
  }
  if (path === '/login') {
    loginPage(response)
    return true
  }
  if (path === '/logout') {
    signOut(state, request, response)
    return true
  }
  return false
}

async function handleSignedIn(state, request, response, url, account) {
  const path = url.pathname
  const isKnown = SIGNED_IN_PAGES[path] || ADMIN_PAGES[path] || path === '/admin/users/disable'
  if (!isKnown) return sendHtml(response, 404, 'Not found', '<p>Not found.</p>')
  if (!account) return redirect(response, '/login?next=' + encodeURIComponent(path))
  if (path === '/account/profile' && request.method === 'POST') return saveProfile(state, request, response, account)
  if (SIGNED_IN_PAGES[path]) return SIGNED_IN_PAGES[path](response, account)
  if (account.role !== 'admin') return notAllowed(response)
  if (path === '/admin/users/disable') return disableUser(state, request, response, account)
  ADMIN_PAGES[path](response, account)
}

async function handleRequest(state, request, response) {
  const url = new URL(request.url, 'http://127.0.0.1')
  if (url.pathname === '/static/account.js') return sendScript(response, ACCOUNT_SCRIPT)
  if (url.pathname === '/static/orders.js') return sendScript(response, ORDERS_SCRIPT)
  if (await handlePublic(state, request, response, url)) return
  const account = readAccount(state, request)
  if (url.pathname.indexOf('/api/') === 0) return handleApi(state, request, response, url, account)
  return handleSignedIn(state, request, response, url, account)
}

// Starts the target on 127.0.0.1 at a port the system picks.
export function startTarget(options) {
  const state = { sessions: new Map(), sessionLimit: options.sessionLimit || 0, log: options.log }
  const server = http.createServer(function (request, response) {
    handleRequest(state, request, response).catch(function (error) {
      sendText(response, 500, 'Lab error: ' + error.message)
    })
  })
  return new Promise(function (resolve) {
    server.listen(0, '127.0.0.1', function () {
      const baseUrl = 'http://127.0.0.1:' + server.address().port
      resolve({ baseUrl: baseUrl, close: function () { server.close() } })
    })
  })
}

async function main() {
  const sessionLimit = Number(process.env.LAB_SESSION_LIMIT || '0')
  const log = function (line) { console.log('target: ' + line) }
  const target = await startTarget({ sessionLimit: sessionLimit, log: log })
  log('listening on ' + target.baseUrl + (sessionLimit ? ', sessions end after ' + sessionLimit + ' signed-in requests' : ''))
}

if (process.argv[1] === fileURLToPath(import.meta.url)) main()

==== File 2 of 5: crawler.mjs ====
// crawler.mjs: an illustration of how a crawler finds its way around a
// running application. It is not a scanner. It reads links, forms and script
// tags from the HTML text it receives, using simple patterns that fit the
// lab's own pages. It never runs a script. Besides plain GET requests, it
// sends only the sign-in form and the profile form (with the value the form
// already holds), and it never follows the sign-out link.
import http from 'node:http'

const EXCLUDED_PATHS = ['/logout']
const SUBMITTED_FORM_ACTIONS = ['/account/profile']
const MAX_REQUESTS_PER_PASS = 60

// Sends one request and resolves with the status, headers and body text.
function sendRequest(baseUrl, method, path, cookie, formBody) {
  const headers = {}
  if (cookie) headers.Cookie = cookie
  if (formBody) headers['Content-Type'] = 'application/x-www-form-urlencoded'
  return new Promise(function (resolve, reject) {
    const request = http.request(new URL(path, baseUrl), { method: method, headers: headers }, function (response) {
      let text = ''
      response.setEncoding('utf8')
      response.on('data', function (chunk) { text = text + chunk })
      response.on('end', function () { resolve({ status: response.statusCode, headers: response.headers, text: text }) })
    })
    request.on('error', reject)
    request.end(formBody || '')
  })
}

// ---- Reading HTML text ----

function readAttribute(tagText, name) {
  const match = new RegExp('\\b' + name + '="([^"]*)"').exec(tagText)
  return match ? match[1] : ''
}

function readTags(html, pattern) {
  const tags = []
  let match = pattern.exec(html)
  while (match) {
    tags.push(match)
    match = pattern.exec(html)
  }
  return tags
}

function readLinks(html) {
  return readTags(html, /<a\s[^>]*>/g).map(function (match) { return readAttribute(match[0], 'href') })
}

function readScriptFiles(html) {
  return readTags(html, /<script\s[^>]*>/g).map(function (match) { return readAttribute(match[0], 'src') })
}

function readForms(html) {
  return readTags(html, /<form\s([^>]*)>([\s\S]*?)<\/form>/g).map(function (match) {
    const fields = readTags(match[2], /<input\s[^>]*>/g).map(function (input) {
      return { name: readAttribute(input[0], 'name'), value: readAttribute(input[0], 'value') }
    })
    return { method: readAttribute(match[1], 'method').toUpperCase(), action: readAttribute(match[1], 'action'), fields: fields }
  })
}

// Keeps a link only when it stays on the target, and drops any fragment.
function toLocalPath(baseUrl, pagePath, href) {
  if (!href) return ''
  const url = new URL(href, new URL(pagePath, baseUrl))
  if (url.origin !== new URL(baseUrl).origin) return ''
  return url.pathname + url.search
}

// ---- One pass ----

function startPass(name, account) {
  return { name: name, account: account, requests: [], found: [], seenNotVisited: [], forms: [], noStoreMissing: [], sessionLost: '' }
}

function logRequest(pass, method, path, response) {
  const location = response.headers.location ? ' to ' + response.headers.location : ''
  pass.requests.push(method + ' ' + path + ' ' + response.status + location)
}

function isSentToSignIn(response) {
  return response.status === 303 && String(response.headers.location).indexOf('/login') === 0
}

// The logged-out indicator: a signed-in pass that is sent to the sign-in page,
// or told to sign in first, has lost its session.
function checkSession(pass, method, path, response) {
  if (!pass.account || pass.sessionLost) return
  if (isSentToSignIn(response)) pass.sessionLost = 'request ' + pass.requests.length + ', ' + method + ' ' + path + ' was sent to the sign-in page'
  if (response.status === 401) pass.sessionLost = 'request ' + pass.requests.length + ', ' + method + ' ' + path + ' answered 401'
}

async function signIn(baseUrl, pass) {
  const page = await sendRequest(baseUrl, 'GET', '/login', '')
  logRequest(pass, 'GET', '/login', page)
  const form = readForms(page.text)[0]
  const body = new URLSearchParams({ username: pass.account.username, password: pass.account.password })
  const response = await sendRequest(baseUrl, form.method, form.action, '', body.toString())
  logRequest(pass, form.method, form.action + ' (sign-in as ' + pass.account.username + ')', response)
  pass.forms.push({ page: '/login', method: form.method, action: form.action, submitted: true })
  const cookie = String(response.headers['set-cookie'] || '').split(';')[0]
  return { cookie: cookie, landing: response.headers.location }
}

// Submits the profile form with the values it already holds, once per pass.
async function submitForm(baseUrl, pass, cookie, form) {
  const body = new URLSearchParams()
  for (const field of form.fields) body.append(field.name, field.value)
  const response = await sendRequest(baseUrl, form.method, form.action, cookie, body.toString())
  logRequest(pass, form.method, form.action + ' (form submitted)', response)
  checkSession(pass, form.method, form.action, response)
  return response.headers.location || ''
}

async function readPage(baseUrl, pass, cookie, path, response, queue) {
  for (const href of readLinks(response.text).concat(readScriptFiles(response.text))) {
    const link = toLocalPath(baseUrl, path, href)
    if (!link) continue
    if (EXCLUDED_PATHS.indexOf(link) !== -1) {
      if (pass.seenNotVisited.indexOf(link) === -1) pass.seenNotVisited.push(link)
      continue
    }
    queue.push(link)
  }
  for (const form of readForms(response.text)) {
    const shouldSubmit = pass.account && SUBMITTED_FORM_ACTIONS.indexOf(form.action) !== -1
    pass.forms.push({ page: path, method: form.method, action: form.action, submitted: Boolean(shouldSubmit) })
    if (shouldSubmit) queue.push(await submitForm(baseUrl, pass, cookie, form))
  }
}

// Passive reading: a page showing the signed-in banner should carry
// Cache-Control: no-store under the lab's own rule. Nothing extra is sent.
function recordPage(pass, path, response) {
  pass.found.push(path)
  const showsAccount = response.text.indexOf('Signed in as ') !== -1
  if (showsAccount && response.headers['cache-control'] !== 'no-store') pass.noStoreMissing.push(path)
}

// Crawls breadth first from the seeds, as the account given (or signed out).
export async function runHtmlPass(baseUrl, name, account) {
  const pass = startPass(name, account)
  let cookie = ''
  const queue = []
  if (account) {
    const session = await signIn(baseUrl, pass)
    cookie = session.cookie
    queue.push(session.landing)
  }
  queue.push('/')
  const visited = []
  while (queue.length > 0 && pass.requests.length < MAX_REQUESTS_PER_PASS) {
    const path = queue.shift()
    if (!path || visited.indexOf(path) !== -1) continue
    visited.push(path)
    const response = await sendRequest(baseUrl, 'GET', path, cookie)
    logRequest(pass, 'GET', path, response)
    checkSession(pass, 'GET', path, response)
    if (response.status !== 200) continue
    recordPage(pass, path, response)
    await readPage(baseUrl, pass, cookie, path, response, queue)
  }
  return pass
}

// ---- The API description pass ----

function describedRoles(operation) {
  const requirements = operation.security || []
  if (requirements.length === 0) return 'anyone'
  const roles = requirements[0].labSession || []
  return roles.length ? roles.join(', ') : 'any signed-in account'
}

function listOperations(description) {
  const operations = []
  for (const path of Object.keys(description.paths)) {
    for (const method of Object.keys(description.paths[path])) {
      const operation = description.paths[path][method]
      operations.push({ method: method.toUpperCase(), path: path, roles: describedRoles(operation), results: {} })
    }
  }
  return operations
}

function reasonNotSent(operation) {
  if (operation.method !== 'GET') return 'not sent: changes data'
  if (operation.path.indexOf('{') !== -1) return 'not sent: needs a path value'
  return ''
}

// Reads the API description, then sends one plain GET to each GET operation
// that needs no path value: signed out, then after signing in as each role.
export async function runApiPass(baseUrl, descriptionPath, accounts) {
  const pass = startPass('API description', null)
  const reply = await sendRequest(baseUrl, 'GET', descriptionPath, '')
  logRequest(pass, 'GET', descriptionPath + ' (the API description)', reply)
  const operations = listOperations(JSON.parse(reply.text))
  const identities = [{ label: 'signed out', account: null }, { label: 'user', account: accounts.user }, { label: 'admin', account: accounts.admin }]
  for (const identity of identities) {
    pass.account = identity.account
    const cookie = identity.account ? (await signIn(baseUrl, pass)).cookie : ''
    for (const operation of operations) {
      const reason = reasonNotSent(operation)
      if (reason) {
        operation.results[identity.label] = reason
        continue
      }
      const response = await sendRequest(baseUrl, 'GET', operation.path, cookie)
      logRequest(pass, 'GET', operation.path + ' as ' + identity.label, response)
      checkSession(pass, 'GET', operation.path, response)
      operation.results[identity.label] = String(response.status)
    }
  }
  pass.account = null
  pass.operations = operations
  return pass
}

==== File 3 of 5: coverage-map.mjs ====
// coverage-map.mjs: reconciles the target's own lists (the ground truth)
// with what each pass discovered, then reconciles the expected findings with
// the evidence the passes captured. The reasons in the map come from the
// route list's note of how each route is reached: a crawler cannot tell you
// why it missed something, only what it reached.
import { EXPECTED_FINDINGS, FORMS, OPERATIONS, ROUTES } from './target.mjs'

function printGrid(title, columns, rows) {
  let widths = columns.map(function (column) { return column.length })
  for (const row of rows) {
    widths = widths.map(function (width, index) { return Math.max(width, row[index].length) })
  }
  if (title) console.log(title)
  for (const line of [columns].concat(rows)) {
    const cells = line.map(function (cell, index) { return cell.padEnd(widths[index]) })
    console.log(cells.join('  ').trimEnd())
  }
  console.log('')
}

function isUserRole(pass) {
  return Boolean(pass.account) && pass.account.role === 'user'
}

// Why a pass did not reach something, from the route list's own notes.
// Reasons that would hold on any run come before a lost session.
function explainMissing(item, pass) {
  if (item.reach === 'not referenced') return 'no: not referenced'
  if (item.reach === 'API description') return 'no: given to API pass'
  if (!pass.account && item.visibleTo !== 'anyone') return 'no: needs sign-in'
  if (isUserRole(pass) && item.visibleTo === 'admin') return 'no: needs admin role'
  if (item.reach === 'script') return 'no: added by script'
  if (item.reach === 'search form') return 'no: form not submitted'
  if (pass.sessionLost) return 'no: session lost'
  return 'no: reason not in route list'
}

function describeRoute(route, pass) {
  if (pass.found.indexOf(route.path) !== -1) return 'found'
  if (pass.seenNotVisited.indexOf(route.path) !== -1) return 'seen, not visited'
  return explainMissing(route, pass)
}

function describeForm(form, pass) {
  const seen = pass.forms.find(function (item) { return item.page === form.page && item.action === form.action })
  if (seen && seen.submitted) return 'found, submitted'
  if (seen) return 'found, not submitted'
  return explainMissing(form, pass)
}

const IDENTITIES = ['signed out', 'user', 'admin']

function columnName(pass) {
  return pass.name.charAt(0).toUpperCase() + pass.name.slice(1)
}

function printRoutes(passes) {
  const rows = ROUTES.map(function (route) {
    return [route.path, route.reach, route.visibleTo].concat(passes.map(function (pass) { return describeRoute(route, pass) }))
  })
  const columns = ['Page or file', 'How it is reached', 'Visible to'].concat(passes.map(columnName))
  printGrid('TABLE 1A. PAGES AND FILES, BY PASS', columns, rows)
}

function printForms(passes) {
  const rows = FORMS.map(function (form) {
    return [form.name, form.method + ' ' + form.action, form.page].concat(passes.map(function (pass) { return describeForm(form, pass) }))
  })
  const columns = ['Form', 'Method and action', 'On page'].concat(passes.map(columnName))
  printGrid('TABLE 1B. FORMS, BY PASS', columns, rows)
}

// Compares one status with the route list's rule for who is allowed.
function checkAgainstRule(allowed, identity, status) {
  const isAllowed = identity !== 'signed out' && (allowed === 'signed-in' || identity === 'admin')
  const isSuccess = status.indexOf('2') === 0
  return isAllowed === isSuccess ? '' : identity + ' got ' + status
}

function describeCheck(operation, rule) {
  const notSent = operation.results.user
  if (notSent.indexOf('not sent') === 0) return notSent
  const mismatches = []
  for (const identity of IDENTITIES) {
    const mismatch = checkAgainstRule(rule.allowed, identity, operation.results[identity])
    if (mismatch) mismatches.push(mismatch)
  }
  return mismatches.length ? 'NO: ' + mismatches.join(', ') : 'matches'
}

function findRule(operation) {
  return OPERATIONS.find(function (item) { return item.method === operation.method && item.path === operation.path })
}

function shortResult(result) {
  return result.indexOf('not sent') === 0 ? 'not sent' : result
}

function describeHtmlPassesOnApi(passes) {
  const apiPathsFound = passes.filter(function (pass) {
    return pass.found.some(function (path) { return path.indexOf('/api/') === 0 })
  })
  if (apiPathsFound.length) return 'HTML passes: some API paths were reached; read the crawl log above.'
  const scripted = OPERATIONS.filter(function (item) { return item.reach.indexOf('script') === 0 })
  const names = scripted.map(function (item) { return item.method + ' ' + item.path })
  return 'HTML passes: reached none of these operations. Route list: ' + names.join(', ') + ' is called by script; the others appear only in the API description.'
}

function printOperations(passes, apiPass) {
  const rows = apiPass.operations.map(function (operation) {
    const rule = findRule(operation)
    const results = IDENTITIES.map(function (identity) { return shortResult(operation.results[identity]) })
    return [operation.method + ' ' + operation.path, operation.roles, rule.allowed].concat(results, [describeCheck(operation, rule)])
  })
  const columns = ['Operation', 'Roles in description', 'Rule', 'Signed out', 'User', 'Admin', 'Check against the rule']
  printGrid('TABLE 1C. API OPERATIONS, FROM THE API DESCRIPTION PASS', columns, rows)
  console.log(describeHtmlPassesOnApi(passes))
  console.log('')
}

// ---- Expected findings ----

function passesThatFound(passes, path) {
  const names = passes.filter(function (pass) { return pass.found.indexOf(path) !== -1 }).map(function (pass) { return pass.name })
  return names.length ? names.join(', ') : 'none'
}

function evaluateCacheHeader(passes) {
  const read = passes.filter(function (pass) { return pass.noStoreMissing.indexOf('/admin/users') !== -1 })
  const result = read.length ? 'CAPTURED: ' + read[0].name + ' pass read no Cache-Control: no-store' : 'UNTESTED: no pass reached the page'
  return [passesThatFound(passes, '/admin/users'), 'headers, read passively', result]
}

function evaluateExport(apiPass) {
  const operation = apiPass.operations.find(function (item) { return item.path === '/api/orders/export' })
  const sentAs = IDENTITIES.filter(function (identity) { return operation.results[identity].indexOf('not sent') !== 0 })
  const userStatus = operation.results.user
  const result = userStatus === '200' ? 'CAPTURED: user got 200; description lists ' + operation.roles : 'not shown: user got ' + userStatus
  return ['API pass (' + sentAs.join(', ') + ')', 'status by role, against the rule', result]
}

function evaluateFinding(finding, passes, apiPass) {
  if (finding.id === 'F1') return evaluateCacheHeader(passes)
  if (finding.id === 'F2') return [passesThatFound(passes, '/help/search'), 'marker in q comes back (active)', 'UNTESTED: form not submitted, no test inputs sent']
  if (finding.id === 'F3') return evaluateExport(apiPass)
  return [passesThatFound(passes, '/old/orders-report'), 'plain GET, signed out', 'UNTESTED: nothing references it']
}

function printFindings(passes, apiPass) {
  console.log('TABLE 2. EXPECTED FINDINGS AND EVIDENCE')
  for (const finding of EXPECTED_FINDINGS) console.log(finding.id + '  ' + finding.label + ', ' + finding.where)
  console.log('')
  const rows = EXPECTED_FINDINGS.map(function (finding) {
    return [finding.id].concat(evaluateFinding(finding, passes, apiPass))
  })
  printGrid('', ['ID', 'Reached by', 'Evidence that would show it', 'This run'], rows)
}

function countFound(pass) {
  return ROUTES.filter(function (route) { return pass.found.indexOf(route.path) !== -1 }).length
}

function printSummary(passes, apiPass) {
  console.log('SUMMARY')
  for (const pass of passes) {
    const session = pass.account ? (pass.sessionLost ? 'SESSION LOST at ' + pass.sessionLost : 'session kept') : 'no session'
    console.log(columnName(pass) + ' pass: ' + pass.requests.length + ' requests, ' + countFound(pass) + ' of ' + ROUTES.length + ' pages and files found, ' + session)
  }
  console.log('API description pass: ' + apiPass.requests.length + ' requests, ' + apiPass.operations.length + ' operations listed' + (apiPass.sessionLost ? ', SESSION LOST at ' + apiPass.sessionLost : ''))
  console.log('')
}

export function printCoverageMap(passes, apiPass) {
  printSummary(passes, apiPass)
  printRoutes(passes)
  printForms(passes)
  printOperations(passes, apiPass)
  printFindings(passes, apiPass)
}

==== File 4 of 5: run-map.mjs ====
// run-map.mjs: runs the three HTML passes and the API description pass
// against the lab target, which must already be running, then prints what
// each pass sent and the coverage map. It refuses any address that is not
// on 127.0.0.1. Usage: node run-map.mjs http://127.0.0.1:PORT
import process from 'node:process'
import { printCoverageMap } from './coverage-map.mjs'
import { runApiPass, runHtmlPass } from './crawler.mjs'
import { ACCOUNTS } from './target.mjs'

function printRequests(pass) {
  console.log('WHAT THE ' + pass.name.toUpperCase() + ' PASS SENT')
  pass.requests.forEach(function (line, index) { console.log(String(index + 1).padStart(2) + '  ' + line) })
  console.log('')
}

async function main() {
  const baseUrl = process.argv[2] || ''
  if (baseUrl.indexOf('http://127.0.0.1:') !== 0) {
    console.log('Give the address target.mjs printed, such as http://127.0.0.1:PORT')
    process.exitCode = 1
    return
  }
  const passes = [
    await runHtmlPass(baseUrl, 'signed out', null),
    await runHtmlPass(baseUrl, 'user', ACCOUNTS.user),
    await runHtmlPass(baseUrl, 'admin', ACCOUNTS.admin),
  ]
  const apiPass = await runApiPass(baseUrl, '/openapi.json', ACCOUNTS)
  console.log('Node.js ' + process.version + '. Target on 127.0.0.1; its port changes on every run, so it is not printed.')
  console.log('')
  for (const pass of passes.concat([apiPass])) printRequests(pass)
  printCoverageMap(passes, apiPass)
}

main()

==== File 5 of 5: coverage.test.mjs ====
// coverage.test.mjs: a regression test that pins what each pass discovers.
// It starts its own copy of the target on 127.0.0.1 and stops it at the end.
// If a later change loses the session, hides a page behind script or drops
// an operation from the API description, the test fails and says what went.
// Run: node --test coverage.test.mjs
// LAB_SESSION_LIMIT=4 node --test coverage.test.mjs shows a failing run.
import assert from 'node:assert/strict'
import process from 'node:process'
import { after, before, test } from 'node:test'
import { runApiPass, runHtmlPass } from './crawler.mjs'
import { ACCOUNTS, startTarget } from './target.mjs'

const PUBLIC_PAGES = ['/', '/about', '/help', '/login']
const ACCOUNT_PAGES = ['/account', '/account/orders', '/account/profile', '/account/profile/saved', '/static/account.js', '/static/orders.js']
const ADMIN_PAGES = ['/admin', '/admin/users']

let target

before(async function () {
  const sessionLimit = Number(process.env.LAB_SESSION_LIMIT || '0')
  target = await startTarget({ sessionLimit: sessionLimit, log: function () {} })
})

after(function () {
  target.close()
})

function coverageOf(pass) {
  return { sessionLost: pass.sessionLost, found: pass.found.slice().sort() }
}

test('signed-out pass finds the public pages only', async function () {
  const pass = await runHtmlPass(target.baseUrl, 'signed out', null)
  assert.deepEqual(coverageOf(pass), { sessionLost: '', found: PUBLIC_PAGES.slice().sort() })
})

test('user pass keeps its session and finds every account page', async function () {
  const pass = await runHtmlPass(target.baseUrl, 'user', ACCOUNTS.user)
  assert.deepEqual(coverageOf(pass), { sessionLost: '', found: PUBLIC_PAGES.concat(ACCOUNT_PAGES).sort() })
})

test('admin pass keeps its session and finds the admin pages too', async function () {
  const pass = await runHtmlPass(target.baseUrl, 'admin', ACCOUNTS.admin)
  const expected = PUBLIC_PAGES.concat(ACCOUNT_PAGES, ADMIN_PAGES).sort()
  assert.deepEqual(coverageOf(pass), { sessionLost: '', found: expected })
})

test('API description pass lists all five operations', async function () {
  const pass = await runApiPass(target.baseUrl, '/openapi.json', ACCOUNTS)
  const listed = pass.operations.map(function (operation) { return operation.method + ' ' + operation.path })
  assert.equal(listed.length, 5)
  assert.equal(pass.sessionLost, '')
})

==== RUN IT ====
1. In one terminal, start the target and leave it running. It prints its address.
     node target.mjs
2. In a second terminal, run the passes against the address it printed.
     node run-map.mjs http://127.0.0.1:PORT
3. Stop the target with Ctrl+C in its terminal. Start it again with each session ending after four signed-in requests, and run the passes once more against the new address.
     LAB_SESSION_LIMIT=4 node target.mjs
     node run-map.mjs http://127.0.0.1:PORT
4. Stop the target again. Run the regression test, which starts and stops its own copy of the target, first as it is and then with sessions ending early.
     node --test coverage.test.mjs
     LAB_SESSION_LIMIT=4 node --test coverage.test.mjs
PORT stands for the port number the target printed, which changes on every run. The commands set LAB_SESSION_LIMIT the way macOS and Linux shells do; on Windows, set it the way your shell does.

==== PART 3. THE COVERAGE MAP AS THE LAB PRINTED IT ====
Copied from the captured output of each command. In the two target logs the port number is shown as PORT, because it changes on every run.

OUTPUT OF node target.mjs (left running while run-map.mjs ran)
target: listening on http://127.0.0.1:PORT
target: profile saved for casey.user (value unchanged)
target: profile saved for ari.admin (value unchanged)

OUTPUT OF node run-map.mjs http://127.0.0.1:PORT
Node.js v26.0.0. Target on 127.0.0.1; its port changes on every run, so it is not printed.

WHAT THE SIGNED OUT PASS SENT
 1  GET / 200
 2  GET /about 200
 3  GET /help 200
 4  GET /login 200
 5  GET /account 303 to /login?next=%2Faccount

WHAT THE USER PASS SENT
 1  GET /login 200
 2  POST /login (sign-in as casey.user) 303 to /account
 3  GET /account 200
 4  GET / 200
 5  GET /account/orders 200
 6  GET /account/profile 200
 7  POST /account/profile (form submitted) 303 to /account/profile/saved
 8  GET /static/account.js 200
 9  GET /about 200
10  GET /help 200
11  GET /login 200
12  GET /static/orders.js 200
13  GET /account/profile/saved 200

WHAT THE ADMIN PASS SENT
 1  GET /login 200
 2  POST /login (sign-in as ari.admin) 303 to /account
 3  GET /account 200
 4  GET / 200
 5  GET /account/orders 200
 6  GET /account/profile 200
 7  POST /account/profile (form submitted) 303 to /account/profile/saved
 8  GET /admin 200
 9  GET /static/account.js 200
10  GET /about 200
11  GET /help 200
12  GET /login 200
13  GET /static/orders.js 200
14  GET /account/profile/saved 200
15  GET /admin/users 200

WHAT THE API DESCRIPTION PASS SENT
 1  GET /openapi.json (the API description) 200
 2  GET /api/orders as signed out 401
 3  GET /api/orders/export as signed out 401
 4  GET /api/admin/stats as signed out 401
 5  GET /login 200
 6  POST /login (sign-in as casey.user) 303 to /account
 7  GET /api/orders as user 200
 8  GET /api/orders/export as user 200
 9  GET /api/admin/stats as user 403
10  GET /login 200
11  POST /login (sign-in as ari.admin) 303 to /account
12  GET /api/orders as admin 200
13  GET /api/orders/export as admin 200
14  GET /api/admin/stats as admin 200

SUMMARY
Signed out pass: 5 requests, 4 of 17 pages and files found, no session
User pass: 13 requests, 10 of 17 pages and files found, session kept
Admin pass: 15 requests, 12 of 17 pages and files found, session kept
API description pass: 14 requests, 5 operations listed

TABLE 1A. PAGES AND FILES, BY PASS
Page or file            How it is reached  Visible to  Signed out              User                    Admin
/                       linked             anyone      found                   found                   found
/about                  linked             anyone      found                   found                   found
/help                   linked             anyone      found                   found                   found
/login                  linked             anyone      found                   found                   found
/help/search            search form        anyone      no: form not submitted  no: form not submitted  no: form not submitted
/old/orders-report      not referenced     anyone      no: not referenced      no: not referenced      no: not referenced
/openapi.json           API description    anyone      no: given to API pass   no: given to API pass   no: given to API pass
/account                linked             signed-in   no: needs sign-in       found                   found
/account/orders         linked             signed-in   no: needs sign-in       found                   found
/account/profile        linked             signed-in   no: needs sign-in       found                   found
/account/profile/saved  profile form       signed-in   no: needs sign-in       found                   found
/account/reports        script             signed-in   no: needs sign-in       no: added by script     no: added by script
/static/account.js      script file        signed-in   no: needs sign-in       found                   found
/static/orders.js       script file        signed-in   no: needs sign-in       found                   found
/logout                 sign-out link      signed-in   no: needs sign-in       seen, not visited       seen, not visited
/admin                  linked             admin       no: needs sign-in       no: needs admin role    found
/admin/users            linked             admin       no: needs sign-in       no: needs admin role    found

TABLE 1B. FORMS, BY PASS
Form          Method and action          On page           Signed out            User                  Admin
sign-in       POST /login                /login            found, not submitted  found, submitted      found, submitted
help search   GET /help/search           /help             found, not submitted  found, not submitted  found, not submitted
profile       POST /account/profile      /account/profile  no: needs sign-in     found, submitted      found, submitted
disable user  POST /admin/users/disable  /admin/users      no: needs sign-in     no: needs admin role  found, not submitted

TABLE 1C. API OPERATIONS, FROM THE API DESCRIPTION PASS
Operation                  Roles in description   Rule       Signed out  User      Admin     Check against the rule
GET /api/orders            any signed-in account  signed-in  401         200       200       matches
POST /api/orders           any signed-in account  signed-in  not sent    not sent  not sent  not sent: changes data
GET /api/orders/{orderId}  any signed-in account  signed-in  not sent    not sent  not sent  not sent: needs a path value
GET /api/orders/export     admin                  admin      401         200       200       NO: user got 200
GET /api/admin/stats       admin                  admin      401         403       200       matches

HTML passes: reached none of these operations. Route list: GET /api/orders is called by script; the others appear only in the API description.

TABLE 2. EXPECTED FINDINGS AND EVIDENCE
F1  Signed-in page sent without Cache-Control: no-store, GET /admin/users
F2  Search term reflected in a plain-text response, GET /help/search?q=
F3  Export answers for the user role, GET /api/orders/export
F4  Old report answers without sign-in, GET /old/orders-report

ID  Reached by                          Evidence that would show it       This run
F1  admin                               headers, read passively           CAPTURED: admin pass read no Cache-Control: no-store
F2  none                                marker in q comes back (active)   UNTESTED: form not submitted, no test inputs sent
F3  API pass (signed out, user, admin)  status by role, against the rule  CAPTURED: user got 200; description lists admin
F4  none                                plain GET, signed out             UNTESTED: nothing references it

OUTPUT OF LAB_SESSION_LIMIT=4 node target.mjs (left running while run-map.mjs ran)
target: listening on http://127.0.0.1:PORT, sessions end after 4 signed-in requests
target: profile saved for casey.user (value unchanged)
target: session for casey.user ended after 4 signed-in requests
target: profile saved for ari.admin (value unchanged)
target: session for ari.admin ended after 4 signed-in requests

OUTPUT OF node run-map.mjs http://127.0.0.1:PORT, AGAINST THAT TARGET
Node.js v26.0.0. Target on 127.0.0.1; its port changes on every run, so it is not printed.

WHAT THE SIGNED OUT PASS SENT
 1  GET / 200
 2  GET /about 200
 3  GET /help 200
 4  GET /login 200
 5  GET /account 303 to /login?next=%2Faccount

WHAT THE USER PASS SENT
 1  GET /login 200
 2  POST /login (sign-in as casey.user) 303 to /account
 3  GET /account 200
 4  GET / 200
 5  GET /account/orders 200
 6  GET /account/profile 200
 7  POST /account/profile (form submitted) 303 to /account/profile/saved
 8  GET /static/account.js 200
 9  GET /about 200
10  GET /help 200
11  GET /login 200
12  GET /static/orders.js 200
13  GET /account/profile/saved 303 to /login?next=%2Faccount%2Fprofile%2Fsaved

WHAT THE ADMIN PASS SENT
 1  GET /login 200
 2  POST /login (sign-in as ari.admin) 303 to /account
 3  GET /account 200
 4  GET / 200
 5  GET /account/orders 200
 6  GET /account/profile 200
 7  POST /account/profile (form submitted) 303 to /account/profile/saved
 8  GET /admin 303 to /login?next=%2Fadmin
 9  GET /static/account.js 200
10  GET /about 200
11  GET /help 200
12  GET /login 200
13  GET /static/orders.js 200
14  GET /account/profile/saved 303 to /login?next=%2Faccount%2Fprofile%2Fsaved

WHAT THE API DESCRIPTION PASS SENT
 1  GET /openapi.json (the API description) 200
 2  GET /api/orders as signed out 401
 3  GET /api/orders/export as signed out 401
 4  GET /api/admin/stats as signed out 401
 5  GET /login 200
 6  POST /login (sign-in as casey.user) 303 to /account
 7  GET /api/orders as user 200
 8  GET /api/orders/export as user 200
 9  GET /api/admin/stats as user 403
10  GET /login 200
11  POST /login (sign-in as ari.admin) 303 to /account
12  GET /api/orders as admin 200
13  GET /api/orders/export as admin 200
14  GET /api/admin/stats as admin 200

SUMMARY
Signed out pass: 5 requests, 4 of 17 pages and files found, no session
User pass: 13 requests, 9 of 17 pages and files found, SESSION LOST at request 13, GET /account/profile/saved was sent to the sign-in page
Admin pass: 14 requests, 9 of 17 pages and files found, SESSION LOST at request 8, GET /admin was sent to the sign-in page
API description pass: 14 requests, 5 operations listed

TABLE 1A. PAGES AND FILES, BY PASS
Page or file            How it is reached  Visible to  Signed out              User                    Admin
/                       linked             anyone      found                   found                   found
/about                  linked             anyone      found                   found                   found
/help                   linked             anyone      found                   found                   found
/login                  linked             anyone      found                   found                   found
/help/search            search form        anyone      no: form not submitted  no: form not submitted  no: form not submitted
/old/orders-report      not referenced     anyone      no: not referenced      no: not referenced      no: not referenced
/openapi.json           API description    anyone      no: given to API pass   no: given to API pass   no: given to API pass
/account                linked             signed-in   no: needs sign-in       found                   found
/account/orders         linked             signed-in   no: needs sign-in       found                   found
/account/profile        linked             signed-in   no: needs sign-in       found                   found
/account/profile/saved  profile form       signed-in   no: needs sign-in       no: session lost        no: session lost
/account/reports        script             signed-in   no: needs sign-in       no: added by script     no: added by script
/static/account.js      script file        signed-in   no: needs sign-in       found                   found
/static/orders.js       script file        signed-in   no: needs sign-in       found                   found
/logout                 sign-out link      signed-in   no: needs sign-in       seen, not visited       seen, not visited
/admin                  linked             admin       no: needs sign-in       no: needs admin role    no: session lost
/admin/users            linked             admin       no: needs sign-in       no: needs admin role    no: session lost

TABLE 1B. FORMS, BY PASS
Form          Method and action          On page           Signed out            User                  Admin
sign-in       POST /login                /login            found, not submitted  found, submitted      found, submitted
help search   GET /help/search           /help             found, not submitted  found, not submitted  found, not submitted
profile       POST /account/profile      /account/profile  no: needs sign-in     found, submitted      found, submitted
disable user  POST /admin/users/disable  /admin/users      no: needs sign-in     no: needs admin role  no: session lost

TABLE 1C. API OPERATIONS, FROM THE API DESCRIPTION PASS
Operation                  Roles in description   Rule       Signed out  User      Admin     Check against the rule
GET /api/orders            any signed-in account  signed-in  401         200       200       matches
POST /api/orders           any signed-in account  signed-in  not sent    not sent  not sent  not sent: changes data
GET /api/orders/{orderId}  any signed-in account  signed-in  not sent    not sent  not sent  not sent: needs a path value
GET /api/orders/export     admin                  admin      401         200       200       NO: user got 200
GET /api/admin/stats       admin                  admin      401         403       200       matches

HTML passes: reached none of these operations. Route list: GET /api/orders is called by script; the others appear only in the API description.

TABLE 2. EXPECTED FINDINGS AND EVIDENCE
F1  Signed-in page sent without Cache-Control: no-store, GET /admin/users
F2  Search term reflected in a plain-text response, GET /help/search?q=
F3  Export answers for the user role, GET /api/orders/export
F4  Old report answers without sign-in, GET /old/orders-report

ID  Reached by                          Evidence that would show it       This run
F1  none                                headers, read passively           UNTESTED: no pass reached the page
F2  none                                marker in q comes back (active)   UNTESTED: form not submitted, no test inputs sent
F3  API pass (signed out, user, admin)  status by role, against the rule  CAPTURED: user got 200; description lists admin
F4  none                                plain GET, signed out             UNTESTED: nothing references it

==== PART 4. THE REGRESSION TEST ====
Copied from the test runner's output. Durations change from run to run. In the failing run, each stack trace and the error properties after it are cut, because the stack names the folder the lab ran in; the assertion and its diff are kept.

Run: node --test coverage.test.mjs
✔ signed-out pass finds the public pages only (12.144917ms)
✔ user pass keeps its session and finds every account page (4.261833ms)
✔ admin pass keeps its session and finds the admin pages too (3.562208ms)
✔ API description pass lists all five operations (3.308083ms)
ℹ tests 4
ℹ suites 0
ℹ pass 4
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 129.583542
Exit code: 0

Run: LAB_SESSION_LIMIT=4 node --test coverage.test.mjs
✔ signed-out pass finds the public pages only (12.145167ms)
✖ user pass keeps its session and finds every account page (5.414875ms)
✖ admin pass keeps its session and finds the admin pages too (3.108417ms)
✔ API description pass lists all five operations (3.006375ms)
ℹ tests 4
ℹ suites 0
ℹ pass 2
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 128.987125

✖ failing tests:

test at coverage.test.mjs:37:1
✖ user pass keeps its session and finds every account page (5.414875ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    {
      found: [
        '/',
        '/about',
        '/account',
        '/account/orders',
        '/account/profile',
  -     '/account/profile/saved',
        '/help',
        '/login',
        '/static/account.js',
        '/static/orders.js'
      ],
  +   sessionLost: 'request 13, GET /account/profile/saved was sent to the sign-in page'
  -   sessionLost: ''
    }
  
  (stack trace and error properties cut here: the stack names the folder the lab ran in)

test at coverage.test.mjs:42:1
✖ admin pass keeps its session and finds the admin pages too (3.108417ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    {
      found: [
        '/',
        '/about',
        '/account',
        '/account/orders',
        '/account/profile',
  -     '/account/profile/saved',
  -     '/admin',
  -     '/admin/users',
        '/help',
        '/login',
        '/static/account.js',
        '/static/orders.js'
      ],
  +   sessionLost: 'request 8, GET /admin was sent to the sign-in page'
  -   sessionLost: ''
    }
  
  (stack trace and error properties cut here: the stack names the folder the lab ran in)
Exit code: 1

==== READING THE LAB'S MAP ====
Signed out. The crawler reached 4 of the 17 pages and files. It followed the "Your account" link and was sent to the sign-in page, which is all a signed-out scan sees of an account area.
Signed in. The user pass reached 10 and the admin pass 12. The only difference between them is the admin link, which the target shows to the admin role alone.
Missed by every pass. /account/reports, because only a script adds the link to it. /help/search, because only the search form leads there and the crawler does not submit that form. /old/orders-report, because nothing links to it. The map gives each a different reason, and each reason has a different fix: a crawler that runs scripts, a form submission, or a route list taken from the code.
The API. The crawler fetched /static/orders.js but did not run it, so the HTML passes never learned that the orders page calls GET /api/orders. Only the API description pass reached the API, and it sent requests only to the three GET operations that need no path value.
Writes. The profile form was submitted once in each signed-in pass, and the target logged a save each time. The crawl sent a request that saves data, with no active check running at all, though the value it saved was the one already there.
F3. The export answered 200 for the user role. Table 2 lists F3 as an expected finding and marks it CAPTURED on that 200 alone. Table 1C flags the 200 because the route list's rule says the export is for the admin role; the API description lists the same role, but the check reads the route list alone. Without that rule, a 200 is just a 200.
The lost session. With LAB_SESSION_LIMIT=4, the target ended each session after four signed-in requests. The user pass lost its session at its 13th request and missed /account/profile/saved. The admin pass lost its session at its 8th request, GET /admin, and reached 9 pages and files instead of 12: /account/profile/saved, /admin and /admin/users dropped out. F1 moved from CAPTURED to UNTESTED. No finding was added and none was marked fixed. The map still printed in full, and only the summary lines and the coverage columns show what went missing.
The test. The regression test passed against the first target and exited with code 0. Against the second it failed the user and admin tests, named each missing page in the diff, printed the request where the session was lost, and exited with code 1.

==== USING THE LAB WITH YOUR OWN SCANNER ====
1. Start target.mjs and point your scanner at the address it prints, on your own computer. Give it the two accounts from ACCOUNTS in target.mjs, exclude /logout, and import http://127.0.0.1:PORT/openapi.json as the API description.
2. Fill in Part 1's tables from your scanner's export, using the route list, forms and operations in target.mjs as the ground truth. Compare your columns with the lab's.
3. Restart the target with LAB_SESSION_LIMIT=4 and scan again. If your scanner signs in again when it loses a session, its signed-in columns should hold; if it does not, they will drop the way the lab's did. Check its log for the moment it noticed.
4. Then do the same on your own staging copy, with your own route list and accounts, and keep the filled tables with the scan record.

What DAST is

Dynamic application security testing, or DAST, tests a web application while it runs.

The tool stands where a visitor stands: it sends requests to a deployed copy, reads what comes back and judges the application by those responses. It does not read the source code. OWASP describes web application vulnerability scanners as automated tools that scan web applications, normally from the outside, looking for vulnerabilities such as cross-site scripting, SQL injection and insecure server configuration, and says this category of tools is frequently referred to as DAST tools.

NISTIR 8397, NIST's guidelines on minimum standards for developer verification, recommends that software providing a web service be checked with a DAST tool, such as a web application scanner, or an interactive application security testing (IAST) tool.

It says web app scanners create inputs as they run and monitor for general unusual behaviour, and that when an input causes some detectable anomaly, the tool can use variations of the input to probe for failures.

That outside view is the method's strength and its limit. A scanner meets the application as deployed, with the headers, redirects and error pages a browser really receives. It also tests only what it can find and open. This guide is mainly about that second half: how a scanner discovers what to test, what it cannot discover alone, and how to tell from its results how much of your application it reached.

How dynamic testing compares with static analysis of the code, and which to adopt first, is the subject of the SAST vs DAST page in this library.

How a dynamic scan works: a map, then the checks

A scan does two jobs.

It builds a map of the application, and it runs checks against what is on that map. PortSwigger's documentation for Burp Scanner calls the first job the crawl phase, usually the first part of a scan, in which the scanner navigates around the application, following links, submitting forms and logging in where necessary, to catalogue its content and navigational paths. Its auditing phase analyses how the application responds to different types of input.

The relationship between the two decides how to read a report. A check runs against requests the scanner knows about, whether they came from its crawl, from an imported API description or from addresses you gave it. A page that never made it onto the map had no checks at all, and it appears in the findings neither as a problem nor as a pass.

This guide quotes the documentation of two scanners, ZAP and PortSwigger's Burp Scanner, because each explains these mechanisms plainly. Quoting them is not a recommendation, and neither is ranked against the other. OWASP keeps a list of DAST tools, says it does not endorse any of the vendors or tools by listing them, and says all of these tools have their own strengths and weaknesses.

How a scanner finds its way around a running application

Everything a scanner tests, it first has to find.

It can read the pages it receives, run their scripts in a browser, or import an API description, which a later section covers. Each way in leaves something out.

Links and forms in the HTML

The simplest crawler reads the HTML of each response for addresses. ZAP's documentation describes its Spider as starting from a list of URLs to visit, called the seeds, identifying all the hyperlinks in each page, adding them to the list and continuing recursively as long as new resources are found.

It reads more than links: the src attribute of script, iframe and image tags, among others, and forms with both GET and POST methods, for which it generates field values.

If set in its options, it also reads robots.txt and sitemap.xml for new addresses, and its documentation notes that it does not follow the rules specified in robots.txt.

Routes that exist only once a script runs

An application can build part of its navigation in the browser, so that a link or an API request appears only after its JavaScript runs. A crawler that reads only page text can miss it. ZAP's documentation says its Spider parses text responses that are not HTML, scanning for the URL pattern.

That can pick up an address written out in full in a script file, but an address a script assembles as it runs leaves nothing to match. PortSwigger's documentation says some websites use JavaScript to dynamically generate a navigational UI that is not present in raw HTML, and that Burp Scanner can use a browser to load the page, execute the scripts that build the UI and continue crawling.

ZAP's documentation calls its Client Spider the recommended option for crawling modern web apps, and says it has access to the DOM through the ZAP Browser Extension, so it can find content the older AJAX Spider cannot.

In the lab on this page, a script adds the only link to one page, and the text-reading crawler never finds it.

What a crawler cannot find on its own

A crawl follows references from one response to the next. Four kinds of route stay out of it unless something else supplies them:

  • Routes nothing links to: an old report page, a debug route, an endpoint kept for one integration. The OWASP Web Security Testing Guide (WSTG) test for identifying application entry points, WSTG-INFO-06, describes a tool that reads source code to find endpoints, including the unlinked endpoints a spider will not be able to find.
  • Routes behind a form the crawler does not submit, or submits with values the application turns away, such as the later steps of a checkout.
  • Routes behind a role the scanner does not hold. A crawl signed in as a customer does not see a link that only an administrator's page carries.
  • API operations that no web page calls, such as those used only by a mobile app or a partner's system.

Authenticated DAST: why the scanner has to sign in

In an application with customer accounts, everything that belongs to a customer, such as orders, invoices and settings, is meant to sit behind the sign-in page, and so is the administration.

A scan that does not sign in sees the public pages, the sign-in form and anything else that answers without a session, and every link into the account area ends at the sign-in page. ZAP's authentication decision tree puts it plainly: if your application uses authentication, you will need to configure ZAP to handle it, otherwise ZAP will not be able to access any of the protected functionality.

PortSwigger says authenticated scanning lets Burp crawl privileged content that requires a login to access, such as user dashboards and admin panels.

One account is not enough when the application has roles. PortSwigger's documentation says Burp Scanner logs in with each set of credentials in turn and crawls the content behind the login, which lets it capture the different functions available to different types of user. Give the scan a test account for every role, and record a role without one as not covered.

In the lab, the user pass never sees the link to the admin pages and the admin pass does, which is the whole difference between their two columns in the map.

Signing in can fail without stopping the scan. The same ZAP page notes that web app authentication is very complicated and that there are many ways in which applications implement it. Check before reading any finding that each role's account reached that role's pages. Testing the sign-in flows themselves, from password reset to account enumeration, is covered in the broken authentication guide in this library.

How a scan stays signed in, and how it loses the session

A session can end part way through a scan.

For example, the crawler follows the sign-out link, the session times out, or a check sends something that logs the user out: PortSwigger warns that its medium active scan checks may log users out, among other effects, when run on live systems.

From then on, requests go out without a valid session. Pages that need one send the scanner to the sign-in page or refuse it, the scanner carries on, and the report covers less than it appears to.

Both scanners quoted here document a way to deal with this. ZAP asks for a verification strategy and at least one indicator: a logged-in indicator, such as a logout link or a welcome message, or a logged-out indicator, such as a login link. Its documentation says that whenever a user appears to be unauthenticated under that strategy, a new authentication is performed and the session is updated.

One of its verification strategies has ZAP poll a URL you name to see whether the user is still authenticated. PortSwigger says that an audit that follows on from an automated crawl can use the crawl results to maintain its session automatically: while performing its audit checks, Burp periodically monitors the application's responses to confirm the session is still valid, and if it is not, rolls back to the latest checkpoint and resumes from there.

Signing in again works only if the scanner can tell it was signed out. An indicator that also matches the sign-in page, or that never appears in JSON responses, leaves it guessing. Check each run yourself:

  • Count the signed-in pages each role reached and compare the count with the last run.
  • Search the request log for redirects to the sign-in page, or 401 responses, after the scanner signed in.
  • Exclude the sign-out link from the crawl, and any other route that ends the session.
  • Read the scanner's own log for the moments it signed in again, and what it had requested just before.

What the lab showed

In the lab's second run, the target ended each session after four signed-in requests. The admin pass was sent to the sign-in page at its eighth request, never reached the admin users page, and the finding that lives on that page went from captured to untested.

The map still printed in full. Only the summary lines and the coverage columns showed the drop, which is why the session check comes before the findings.

What an API description adds to a scan

An API that only scripts and other systems call gives a crawler nothing to follow, and an API description fills that gap.

The OpenAPI Specification, whose version 3.2.1 is dated 10 September 2026, defines a standard, programming language-agnostic interface description for HTTP APIs that lets humans and computers discover and understand what a service can do without access to source code, additional documentation or inspection of network traffic.

Both scanners quoted here take a description as input. ZAP's OpenAPI add-on imports definitions in versions 1.2, 2.0, 3.0 and 3.1, and can import as a chosen user so the requests are authenticated. PortSwigger says Burp Scanner detects endpoints, parameters and authentication details in an uploaded definition, treats each server, path and method combination as a separate endpoint, and also parses definitions it comes across while crawling.

A description adds reach, not judgement. It covers only the operations its author listed, and the specification allows some objects in a description to be left empty or removed altogether, as an additional layer of access control over the documentation. It can name the roles an operation needs: for security schemes other than OAuth 2 and OpenID Connect, a security requirement may list role names, which the specification says are not otherwise defined or exchanged in-band.

The description can state the rule, but nothing in a response tells a scanner whether the rule held.

The lab shows both sides. Its API description pass listed all five operations, none of which the crawling passes reached, because the only page that calls the API does so from a script the crawler fetched but did not run.

The pass sent nothing to the operation that creates an order or to the one that needs an order number. It recorded that the export operation answered with status 200 for the user role.

The map's table of expected findings marks that as captured on the 200 alone, and its check column flags it because the target's route list reserves the export for administrators, as the description also does.

Passive reading and active testing

With a map in hand, a scanner's checks come in two kinds.

Passive checks read the requests and responses that have already passed. ZAP's documentation says its passive scanner, which by default scans all messages sent to the application being tested, does not change the messages in any way and is therefore safe to use.

Burp Scanner's passive audit phase likewise analyses normal traffic without sending any additional or modified requests. A passive check can notice a missing response header, a cookie without the attributes you expect, or an error message that gives away internal details.

Active checks send new requests built to provoke a fault, with altered parameters and unexpected values. ZAP's documentation says active scanning attempts to find potential vulnerabilities by using known attacks against the selected targets, that it is an attack on those targets, and that you should not use it on web applications you do not own.

PortSwigger grades its active checks by intensity. It says medium checks may trigger security alerts, log users out or cause other unintended effects on live systems, and that intrusive checks carry a significant risk of modifying or damaging the application or its data, and may cause permanent data loss, service outages or other irreversible impacts on live systems.

Even a crawl can write data. PortSwigger says Burp Scanner by default attempts to register a user if the application supports self-registration, and its crawler submits forms. In the lab, the crawler submitted one profile form in each signed-in pass, with the value already in it, and the target logged a save each time. This page's advice follows from that:

  • Scan only an application you own or have written permission to test, and keep that permission with the scan record.
  • Prefer a staging copy with test accounts and test data. NIST SP 800-115 says that in some cases organisations should consider whether testing should be performed on production systems or similarly configured non-production systems, if such alternate systems are available, and that if testing could expose sensitive personally identifiable information (PII) to individuals who are not authorised to have access, they should consider testing on a non-production system with test data instead of actual PII. It also notes that there are usually inconsistencies between test and production environments, which can result in missed vulnerabilities if non-production systems are used. Record how your staging copy differs from production.
  • Before an active scan, decide which checks are off and which forms and operations are excluded, such as sign-out, delete, payment and anything that emails real people.
  • Tell the people who watch the application. SP 800-115 says an assessment plan should identify the IP addresses that testing will come from, so administrators can tell assessment activity apart from real attacks.

DAST coverage: the first thing to check in a result

Before reading a single finding, find out what the scan reached.

WSTG-INFO-07, the WSTG's test for mapping execution paths through an application, says that without a thorough understanding of the layout of the application, it is unlikely that it will be tested thoroughly. It says that in black-box testing it is extremely difficult to test the entire codebase, and that one way to reconcile this is to document what code paths were discovered and tested.

To show coverage to the application owner, it says, a tester can start with a spreadsheet of all the links discovered by spidering the application.

It also notes that many modern DAST tools can use a web server agent, or be paired with a third-party agent, to monitor coverage.

NISTIR 8397 makes a related point about test coverage of code: low coverage indicates inadequate testing, while very high code coverage assures little. A scan reads the same way. A route missing from the scan's map is untested. A route present on it was requested, which by itself shows neither which checks ran against it nor with which account.

The coverage map in the asset on this page turns that into a routine. It sets the route list taken from your code beside what each scan identity reached, by page, form and API operation, and gives every gap a reason: needs sign-in, needs another role, added by script, form not submitted, only in the API description, not referenced, or session lost.

Each reason points to a different fix, from adding an account, to importing the description, to crawling with a browser.

How to read a scan that found nothing

A result with no findings means that none were found in what the scan reached, by the checks that ran, with the accounts it held, on that build.

Each of those limits can be checked, and the coverage map exists to check what was reached and with which accounts. NIST SP 800-115 says scanners suffer from the high false negative rates that characterise other signature-based tools, and that vulnerabilities automated scanners miss can potentially be caught by using multiple scanners or additional forms of testing.

Some questions are out of a scanner's reach because the answer is not in any response. Whether a customer should be able to export every customer's orders, or whether a refund should be possible after goods ship, is a rule of your business.

ZAP's documentation says logical vulnerabilities, such as broken access control, will not be found by any active or automated vulnerability scanning, and the WSTG says business logic flaws cannot be detected by a vulnerability scanner.

The lab's export operation is that case in miniature: the scan can record that the user role received status 200, but only a written rule says that is wrong.

So write a clean result down with its limits: the build, the date, the accounts, the coverage counts from the map, the checks that were switched off and the areas recorded as not covered. The WSTG introduction warns that relying only on successful results from automated tools gives security practitioners a false sense of security.

Where a dynamic scan belongs in a release process

A scan needs a running build, so it fits after deployment to a test environment and before release.

NIST's Secure Software Development Framework (SP 800-218, version 1.1) describes testing executable code as a way to identify vulnerabilities so they can be corrected before the software is released, and says automated methods lower the effort and resources needed to detect vulnerabilities and improve traceability and repeatability.

Its notional implementation examples for task PW.8.2 include integrating dynamic vulnerability testing into the project's automated test suite, adding tests for previously reported vulnerabilities so errors are not reintroduced, and taking the production infrastructure and technology stack into account when writing test plans.

That gives a scan three places in a release:

  • On each release candidate in staging, with an account for every role. Compare the coverage counts with the last run before anyone reads the findings, and treat a drop the way you would treat a failing test.
  • After a fix. Add a regression test that pins the fix, and check on the next scan that the route is still in coverage.
  • In the record. Task PW.8.2 asks for the results to be documented, including recording and triaging all discovered issues and recommended remediations in the team's workflow or issue tracking system. Keep the coverage map and the list of areas not covered in the same place.

The scanner's accounts live in the pipeline

A scan that runs in a pipeline holds test account credentials and reaches a staging copy, so treat those credentials as pipeline secrets; the CI/CD security guide in this library covers who can make a pipeline run and what each job can reach.

Walking through the coverage lab

The lab in the asset is an illustration written for this page.

A target application in Node.js, which imports only node: modules and installs no packages, listens on 127.0.0.1 at a port the system picks. It has public pages, a sign-in form, two invented accounts (an ordinary user and an administrator), a form that changes data, a JSON API with five operations and an API description, and it keeps its own list of every route, form and operation as the ground truth.

A small crawler visits it signed out and then as each role, reading links, script references and forms from the HTML text it receives.

It runs no page script and it is not a scanner: besides plain page requests it sends only the sign-in form and the profile form. A separate pass reads the API description and sends one plain GET to each GET operation that needs no path value.

What the first run reached

On Node.js v26.0.0, the signed-out pass reached 4 of the 17 pages and files on the route list, the user pass 10 and the admin pass 12. No pass reached the reports page, whose only link is added by a script, the help search results, which only the search form leads to, or the old orders report, which nothing links to.

Two of the four expected findings had evidence: a missing Cache-Control header on the admin users page, read passively in the admin pass, and the export that answered status 200 for the user role. The other two stayed untested, and the map says so.

The run that lost its session

With the target restarted to end each session after four signed-in requests, the user pass lost its session at its 13th request and the admin pass at its 8th. The admin pass reached 9 pages and files instead of 12, and the Cache-Control finding moved to untested. No finding was added and none was marked fixed; the evidence for one simply went missing.

The regression test uses the Node.js built-in test runner to pin the pages each pass should reach and to require that each signed-in pass keeps its session. It passed against the first target. Against the second it failed the user and admin tests, named each missing page in its diff and exited with code 1, which the Node.js documentation says the runner sets when any test fails.

DAST tools and scanners: judge one by its coverage

A feature list says what a scanner can do in general.

What matters is what it reaches in your application, and you can measure that before you commit: run a trial against your staging copy, or the lab's target, and fill in the coverage map. Ask each candidate these questions:

  • Can it sign in the way your application does, with an account for each role?
  • How does it tell that it is still signed in, does it sign in again when it is not, and does its log show when that happened?
  • Does it crawl with a browser, so that links and requests added by script are found? Compare its result for a script-driven page with your route list.
  • Will it import your API description, signed in, and what does it do with operations that change data or need a path value?
  • Can you exclude the sign-out link and destructive operations, and switch off intrusive checks for a given environment?
  • Can it export the URLs, forms and operations it reached for each account, so the map can be filled in?
  • Does its report say what it did not reach, or only what it found?

No ranking here

Neither scanner quoted on this page is recommended over the other, or over any tool on OWASP's list. The scanner that reaches more of your route list, with each role, and tells you when it lost a session, is the better fit for your application, and only a trial on that application shows which one it is.

Where a Clever Ops test sits beside your own scans

Clever Ops does not offer a scanner-only subscription, and does not sell raw scan output as a service of its own.

Scans are a step inside a check or test. Routine scanning between tests is usually best run by your developer or host, who can act on the results directly.

If your team already scans, send the current results with the scope, so known issues are recognised as known rather than reported back to you as new. The methodology page explains how a Clever Ops test is run at unauthenticated, authenticated and code-assisted depths, and the website security audit page sets out what an external review of a website covers without signing in.

Frequently asked questions

Dynamic application security testing. It tests a running application from the outside by sending requests and reading the responses, with no access to the source code. OWASP notes that web application vulnerability scanners are frequently referred to as DAST tools.

A scan that signs in with test accounts, so it can reach pages and API operations behind the sign-in page. It needs an account for each role, an indicator that tells the scanner whether it is still signed in, and a check afterwards that each role reached its own pages. ZAP's documentation says that if an application uses authentication and ZAP is not configured to handle it, ZAP will not be able to access any of the protected functionality.

Yes. Active checks send modified requests, and PortSwigger says its intrusive checks carry a significant risk of modifying or damaging the application or its data. A crawl can write data too, by submitting forms or registering an account. Scan a staging copy with test data where you can, exclude destructive operations, and scan only applications you own or have written permission to test.

Do not count on it. ZAP's documentation says logical vulnerabilities, such as broken access control, will not be found by any active or automated vulnerability scanning. A scan can record which role received which response, as the lab on this page does, but deciding whether a role should have been refused needs your own rules. The broken access control guide in this library covers testing it.

Yes, given a way in. An API that only scripts or other systems call gives a crawler nothing to follow, so import its description, such as an OpenAPI file, and supply credentials. Both scanners quoted on this page accept OpenAPI definitions that meet the requirements their documentation sets out. Then check which operations were sent and which were skipped, such as those that change data or need a path value.

Compare the number of signed-in pages each role reached with the last run, search the request log for redirects to the sign-in page or 401 responses after sign-in, and make sure the sign-out link was excluded. In the lab on this page, the target ended sessions early and the map still printed in full: only the coverage counts and the session line showed the drop.

This page does not rank tools. Run each candidate against your staging copy, fill in the coverage map from its results, and prefer the one that reaches more of your route list with each role and tells you when it lost its session. OWASP keeps a list of DAST tools and says all of them have their own strengths and weaknesses.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.