Security misconfiguration: when the software is sound and a setting leaves it open
A security misconfiguration is a weakness in a setting, not in the code: debug mode left on, a default account that still signs in, a folder that lists its files, an admin page or a storage bucket open to everyone.
This guide explains why those settings drift between development, staging and production, what each one exposes, and how to compare what you intended with what is running. It comes with an environment drift worksheet and a lab you can run on your own computer.
In this guide
Environment drift worksheet and drift lab
Part 1 is a worksheet with ten rows, from debug mode to security headers: the expected production value and its source, how to observe the real value from outside and in the configuration, and spaces for development, staging, production, an owner and the evidence. Parts 2 and 3 are an illustration you can run with Node.js and no installs: one invented app started from three configuration files, a drift checker, a probe and a regression test, with every output copied from one recorded run on Node.js 26.0.0.
How to use itHide the instructions
Part 4 lists the same checks for your own application.
security-misconfiguration.txt
Introduction15 lines
Part 1: The environment drift worksheet134 lines
Part 2: The lab files768 lines
Part 3: The recorded run571 lines
Part 4: The same checks on your own application25 lines
Whole template1,537 lines
ENVIRONMENT DRIFT WORKSHEET AND DRIFT LAB
ILLUSTRATION ONLY. Part 1 is a worksheet for your own application. Parts 2 and 3 are a lab: an invented application, Fixture Bookings, with invented settings, owners, reasons and data, written for this page and run on one computer. Nothing in it is a client's system or a client's result, and it does not show how any real framework, web server or cloud service behaves. Its debug page, directory listing, error output and admin page are the lab's own. What it shows is a way to compare settings and a way to look from outside. The lab has one account, setup-admin, with the password invented-lab-password-not-real. Both were made up for this page and are no product's default. Use what the lab teaches only on systems you own or are authorised in writing to test.
WHAT THE LAB NEEDS
Node.js. Apart from each other, the scripts import only node:assert/strict, node:child_process, node:crypto, node:fs, node:http, node:path, node:test, node:timers/promises and node:url, and the lab installs no packages. The run in Part 3 was recorded on macOS with Node.js 26.0.0, the only version and the only system it was run on. Process ids, timings and the error reference differ from run to run.
WHAT THE LAB DOES NOT DO
Every instance listens on 127.0.0.1, on a port the system picks, and no port is printed. The app's "files" and "storage" folders are short lists inside app.mjs, so it serves nothing from your disk. The app writes only to a lab-state folder inside the lab folder, and set-production.mjs writes config/production.json. No request leaves your computer. Instances run in the background and are stopped by the process id each one recorded when it started, never by name. The operator token each instance makes when it starts is random and is never printed.
WHAT IS HERE
Part 1 The environment drift worksheet: ten rows to fill in for your own application
Part 2 The lab files: fourteen files
Part 3 The recorded run: fifteen commands and what each printed
Part 4 The same checks on your own application
================================================================
PART 1: THE ENVIRONMENT DRIFT WORKSHEET
================================================================
How to use it
Give every row an owner. For each environment, write the value the setting has today: read it from the configuration, then confirm it from outside. Where a value differs from the expected production value, either change it, or write the reason and who accepted it. A difference in production is drift until it is fixed. Add a row for any other setting of your own that changes what a stranger can reach. Run the outside checks only against hostnames you own or are authorised in writing to test, one request at a time.
Each expected value names the source behind it, or says that it is this page's advice.
ROW 1: DEBUG MODE AND DEBUG ROUTES
Expected in production
Debug mode off in every component, and no route that prints settings, environment values or diagnostics.
Source of the expected value
ASVS 5.0 requirement 13.4.2 (Level 2): debug modes are disabled for all components in production environments. WSTG v4.2, WSTG-CONF-02: one objective is to validate that no debugging code or extensions are left in the production environments.
Observe from outside
Ask your developer for every debug or diagnostic path the framework and the application define, and request each one on each of your hostnames. A correctly configured server answers with an error such as 404 and shows no settings.
Observe in the configuration
The framework's debug setting in the production settings, and the environment variables the production process was started with. Two examples from this page: Django's DEBUG, and Express's env setting, which follows NODE_ENV.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 2: DEFAULT ACCOUNTS AND SAMPLE CONTENT
Expected in production
No account that came with a product still signs in, no component connects to another with a default credential, and no sample application, sample page or bundled documentation is installed.
Source of the expected value
ASVS 5.0 requirement 6.3.2 (Level 1): default user accounts are not present in the application or are disabled. ASVS 5.0 requirement 13.2.3 (Level 2): a credential used for service authentication is not a default credential. OWASP Top 10:2025 A02: a minimal platform without any unnecessary features, components, documentation or samples. WSTG v4.2, WSTG-CONF-02: one objective is to ensure that defaults and known files have been removed.
Observe from outside
On your own installation only: one sign-in attempt with the first-run account that your product's own installation guide names. A correctly configured system refuses it. WSTG-ATHN-02 warns that multiple password guesses with a known user name may cause the account to be locked. Do not repeat the attempt. Then request the sample paths the product's documentation names: each answers with an error such as 404.
Observe in the configuration
The user list of each admin interface and database, compared with the built-in accounts the product's documentation lists. WSTG-ATHN-02's inside steps include asking whether default passwords are changed and default user accounts are disabled, and examining the user database for default credentials and empty password fields.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 3: DIRECTORY LISTINGS
Expected in production
Off. A URL that maps to a folder with no index page returns an error, not a list of files, unless a listing is explicitly intended and written down here.
Source of the expected value
ASVS 5.0 requirement 13.4.3 (Level 2): web servers do not expose directory listings to clients unless explicitly intended.
Observe from outside
Request a folder URL on your own site that has no index page, such as an uploads, assets or images folder, ending in a slash. A correctly configured server answers with an error such as 403 or 404 and no list of file names.
Observe in the configuration
nginx: the autoindex directive, whose documented default is off. Apache HTTP Server 2.4: the Options directive for each directory and each .htaccess file, where Indexes turns listings on. For a storage bucket, see row 4.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 4: STORAGE PERMISSIONS
Expected in production
Private, unless a bucket or folder is public by a decision written down here. Anonymous requests cannot list it, read private objects from it or write to it.
Source of the expected value
OWASP Top 10:2025 A02: review cloud storage permissions. WSTG v4.2, WSTG-CONF-11: the objective is to assess that the access control configuration for the storage services is properly in place. For Amazon S3, Amazon recommends turning on all four Block Public Access settings for the account, and additionally for each bucket to comply with AWS Security Hub Foundational Security Best Practices control S3.8. That a public bucket needs a written decision is this page's advice.
Observe from outside
Signed out, in a private browser window, open the address of a stored file of your own that should be private. A correctly configured store answers with an access-denied error, not the file. Check write access in the configuration, not by uploading.
Observe in the configuration
The bucket policy, any access control lists, and the provider's public access settings at account level and at bucket level. On Amazon S3 those are the four Block Public Access settings.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 5: ERROR OUTPUT
Expected in production
A generic message, with a reference the team can look up. The detail goes to the server's log.
Source of the expected value
ASVS 5.0 requirement 16.5.1 (Level 2): a generic message is returned to the consumer when an unexpected or security-sensitive error occurs, with no exposure of sensitive internal system data such as stack traces, queries, secret keys and tokens. The reference is this page's advice.
Observe from outside
Request a URL of your own with a malformed value, such as letters where the application expects a number, one request at a time. A correctly configured application answers with a plain error page: no stack trace, file path, query text or framework name.
Observe in the configuration
The framework's production mode setting, the custom error pages of the web server, and the error pages of each proxy or CDN in front of it.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 6: ADMINISTRATIVE INTERFACES
Expected in production
Reachable only by the people who use them: not accessible to everyone, and with no default credentials.
Source of the expected value
WSTG v4.2, WSTG-CONF-05: hardening means administrator pages are not accessible to everyone, through the use of IP filtering or other controls, and, where applicable, components that do not use default credentials or configurations. Which control to use is this page's advice: restrict by network where you can, and put the interface behind sign-in with multi-factor authentication where you cannot.
Observe from outside
From a network that is not your office or VPN, such as a phone on mobile data, request each admin path. A correctly configured system either does not answer or shows a sign-in page and nothing else.
Observe in the configuration
The address and port each admin interface listens on, the firewall or security group rules in front of it, and the reverse proxy rules that route to it.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 7: HTTP METHODS AND UNNEEDED SERVICES
Expected in production
TRACE not supported. Only the ports, services and server modules the application needs are enabled, and the list of required ports is written down and kept under change control.
Source of the expected value
ASVS 5.0 requirement 13.4.4 (Level 2): the HTTP TRACE method is not supported in production environments. WSTG v4.2, WSTG-CONF-01: a list of defined ports which are required for the application should be maintained and kept under change control. WSTG-CONF-02: only enable server modules that are needed for the application. OWASP Top 10:2025 A02: one sign that an application might be vulnerable is unnecessary features that are enabled or installed, and its examples include unnecessary ports and services. That only the ports and services the application needs are enabled is this page's advice.
Observe from outside
Send one TRACE request to your own site. A server with TRACE off answers with an error such as 405 and does not send the request back. For ports, compare the written list with the rules your host's firewall or security group shows.
Observe in the configuration
Apache HTTP Server 2.4: the TraceEnable directive, whose documented default is on. The modules each server loads. The ports the server is listening on, and the addresses they are bound to.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 8: MONITORING AND DOCUMENTATION ENDPOINTS
Expected in production
Not exposed, unless explicitly intended and written down here.
Source of the expected value
ASVS 5.0 requirement 13.4.5 (Level 2): documentation, such as for internal APIs, and monitoring endpoints are not exposed unless explicitly intended.
Observe from outside
Request your status, health, metrics and API documentation paths from outside your network. A correctly configured system answers with an error, or with only what you decided to publish.
Observe in the configuration
The application's route list, and the status modules of the web server. On Apache HTTP Server 2.4, the Location block for /server-status and its Require rule.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 9: SOURCE MAPS
Expected in production
Not served, unless you decided to publish your source.
Source of the expected value
This page's advice. Next.js's documentation says that during production builds source maps are disabled, to prevent you leaking your source on the client, unless you specifically opt in with the productionBrowserSourceMaps configuration flag.
Observe from outside
Open the address of your site's main JavaScript file, then the same address with .map added. A build without published source maps answers the second request with an error such as 404.
Observe in the configuration
The build's source map setting, and whether the deploy step uploads files ending in .map.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
ROW 10: SECURITY HEADERS ON EVERY RESPONSE
Expected in production
Each security header your policy sets is on every response: pages, API answers, redirects and error pages, whichever layer answers.
Source of the expected value
ASVS 5.0 words three header requirements this way: 3.4.1 (Level 1), Strict-Transport-Security on all responses; 3.4.4 (Level 2), X-Content-Type-Options: nosniff on all HTTP responses; and 3.4.6 (Level 2), the frame-ancestors directive for every HTTP response. For any other header, "every response" is this page's advice.
Observe from outside
On each hostname, request a page that exists, a page that does not and an address that redirects, and compare the response headers. The same security headers appear on all three.
Observe in the configuration
Where each header is set: application code, web server configuration or a CDN rule. On nginx, whether add_header carries the always parameter. On Apache HTTP Server 2.4, whether the Header directive uses the always condition.
Development: ____________ Staging: ____________ Production: ____________
Owner: ____________ Evidence (what was checked, from where, on which date): ____________
================================================================
PART 2: THE LAB FILES
================================================================
Make an empty folder named drift-lab with two folders inside it, config and production-versions. Save the fourteen files below under the names shown, then run the commands in Part 3 from the drift-lab folder. config/production.json is not among them: set-production.mjs creates it from one of the two files in production-versions. The ten settings follow the worksheet's ten rows, in the same order.
================================================================
FILE 1 OF 14: expected-production.json
================================================================
{
"note": "Illustration only. The one reviewed place for the settings of the invented app, Fixture Bookings. Owners and reasons are invented.",
"settings": [
{ "worksheetRow": 1, "name": "debugRoutes", "expectedInProduction": false, "owner": "application lead" },
{ "worksheetRow": 2, "name": "defaultAccount", "expectedInProduction": "removed", "owner": "application lead" },
{ "worksheetRow": 3, "name": "directoryListing", "expectedInProduction": false, "owner": "hosting lead" },
{ "worksheetRow": 4, "name": "storageAccess", "expectedInProduction": "private", "owner": "hosting lead" },
{ "worksheetRow": 5, "name": "errorDetail", "expectedInProduction": "generic-message", "owner": "application lead" },
{ "worksheetRow": 6, "name": "adminAccess", "expectedInProduction": "operators-only", "owner": "application lead" },
{ "worksheetRow": 7, "name": "traceMethod", "expectedInProduction": false, "owner": "hosting lead" },
{ "worksheetRow": 8, "name": "statusEndpoint", "expectedInProduction": "off", "owner": "hosting lead" },
{ "worksheetRow": 9, "name": "sourceMaps", "expectedInProduction": false, "owner": "application lead" },
{ "worksheetRow": 10, "name": "securityHeaders", "expectedInProduction": "every-response", "owner": "hosting lead" }
],
"acceptedDifferences": {
"development": {
"debugRoutes": "developers read the running settings while building",
"defaultAccount": "a fresh local install signs in with the setup account",
"directoryListing": "a quick look at which files a build produced",
"storageAccess": "test exports are opened straight from a browser",
"errorDetail": "the stack trace is read in the browser while coding",
"adminAccess": "admin screens are built without signing in each time",
"traceMethod": "used to see what a local proxy adds to a request",
"statusEndpoint": "watched during local load checks",
"sourceMaps": "readable code in the browser debugger",
"securityHeaders": "error pages are still being restyled"
},
"staging": {
"statusEndpoint": "the team watches staging through it during release rehearsals"
}
}
}
================================================================
FILE 2 OF 14: config/development.json
================================================================
{
"environment": "development",
"debugRoutes": true,
"defaultAccount": "enabled",
"directoryListing": true,
"storageAccess": "public-read",
"errorDetail": "stack-trace",
"adminAccess": "anyone",
"traceMethod": true,
"statusEndpoint": "public",
"sourceMaps": true,
"securityHeaders": "success-responses-only"
}
================================================================
FILE 3 OF 14: config/staging.json
================================================================
{
"environment": "staging",
"debugRoutes": false,
"defaultAccount": "removed",
"directoryListing": false,
"storageAccess": "private",
"errorDetail": "generic-message",
"adminAccess": "operators-only",
"traceMethod": false,
"statusEndpoint": "public",
"sourceMaps": false,
"securityHeaders": "every-response"
}
================================================================
FILE 4 OF 14: production-versions/careless.json
================================================================
{
"environment": "production",
"debugRoutes": true,
"defaultAccount": "enabled",
"directoryListing": true,
"storageAccess": "public-read",
"errorDetail": "stack-trace",
"adminAccess": "anyone",
"traceMethod": false,
"statusEndpoint": "off",
"sourceMaps": false,
"securityHeaders": "every-response"
}
================================================================
FILE 5 OF 14: production-versions/careful.json
================================================================
{
"environment": "production",
"debugRoutes": false,
"defaultAccount": "removed",
"directoryListing": false,
"storageAccess": "private",
"errorDetail": "generic-message",
"adminAccess": "operators-only",
"traceMethod": false,
"statusEndpoint": "off",
"sourceMaps": false,
"securityHeaders": "every-response"
}
================================================================
FILE 6 OF 14: lab-common.mjs
================================================================
// lab-common.mjs: names, paths and helpers shared by every script in the lab.
// Illustration only. The application, its settings, its one account and its
// data are invented for this lab, and nothing leaves 127.0.0.1.
import { readFileSync } from 'node:fs'
import { request as httpRequest } from 'node:http'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
export const LAB_DIR = fileURLToPath(new URL('.', import.meta.url))
export const STATE_DIR = join(LAB_DIR, 'lab-state')
export const ENVIRONMENTS = ['development', 'staging', 'production']
export const NEWLINE = String.fromCharCode(10)
// The one account the invented app is installed with. The user name and the
// password are invented for this lab and are no product's default.
export const LAB_ACCOUNT = { username: 'setup-admin', password: 'invented-lab-password-not-real' }
// The ten settings the app reads besides its environment name, and the only
// values it accepts for each. The environment name must be one of ENVIRONMENTS.
export const ALLOWED_VALUES = {
debugRoutes: [true, false],
defaultAccount: ['enabled', 'removed'],
directoryListing: [true, false],
storageAccess: ['public-read', 'private'],
errorDetail: ['stack-trace', 'generic-message'],
adminAccess: ['anyone', 'operators-only'],
traceMethod: [true, false],
statusEndpoint: ['public', 'off'],
sourceMaps: [true, false],
securityHeaders: ['success-responses-only', 'every-response'],
}
export function readJson(path) {
return JSON.parse(readFileSync(path, 'utf8'))
}
export function configPath(environment) {
return join(LAB_DIR, 'config', environment + '.json')
}
export function statePath(environment) {
return join(STATE_DIR, environment + '.json')
}
export function readExpected() {
return readJson(join(LAB_DIR, 'expected-production.json'))
}
// What a running instance wrote when it started: its process id, its port
// and its operator token.
export function readState(environment) {
return readJson(statePath(environment))
}
// Reads one configuration file and stops if a setting is missing or has a
// value the app does not know. The app never guesses a value.
export function loadSettings(path) {
const settings = readJson(path)
if (!ENVIRONMENTS.includes(settings.environment)) throw new Error('unknown environment in ' + path)
for (const name of Object.keys(ALLOWED_VALUES)) {
if (ALLOWED_VALUES[name].includes(settings[name])) continue
throw new Error('setting ' + name + ' is missing or has a value the app does not know')
}
return settings
}
// Sends one request to a running instance on 127.0.0.1 and returns the
// status, the headers and the body.
export function requestFromInstance(environment, options) {
const target = {
host: '127.0.0.1',
port: readState(environment).port,
method: options.method || 'GET',
path: options.path,
headers: options.headers || {},
agent: false,
}
return new Promise((resolve, reject) => {
const outgoing = httpRequest(target, (incoming) => {
let body = ''
incoming.setEncoding('utf8')
incoming.on('data', (chunk) => { body = body + chunk })
incoming.on('end', () => resolve({ status: incoming.statusCode, headers: incoming.headers, body: body }))
})
outgoing.on('error', reject)
outgoing.end(options.body || '')
})
}
================================================================
FILE 7 OF 14: app.mjs
================================================================
// app.mjs: the invented application, Fixture Bookings. Illustration only.
// It reads one configuration file, named on the command line, once, when it
// starts. Changing the file later changes nothing until the app restarts.
// It listens on 127.0.0.1 only, on a port the system picks. Its "files" and
// "storage" folders are short lists in this file, so it serves nothing from
// your disk. It writes only to the lab-state folder.
import { randomBytes } from 'node:crypto'
import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs'
import { createServer } from 'node:http'
import { join } from 'node:path'
import { LAB_ACCOUNT, NEWLINE, STATE_DIR, loadSettings, statePath } from './lab-common.mjs'
const settings = loadSettings(process.argv[2])
// Made when the instance starts and never printed. An operator's request
// carries it in the x-operator-token header.
const operatorToken = randomBytes(16).toString('hex')
const BOOKINGS = new Map([['1042', { service: 'boat survey', day: 'Tuesday' }]])
const PUBLIC_FILES = {
'brochure.txt': 'Fixture Bookings brochure. Invented text.',
'opening-hours.txt': 'Open weekdays. Invented text.',
}
const STORAGE = {
'exports/bookings.csv': 'booking,service,day' + NEWLINE + '1042,boat survey,Tuesday' + NEWLINE,
}
const BUNDLE = 'function greet(){return "Fixture Bookings"}' + NEWLINE + '//# sourceMappingURL=app.js.map' + NEWLINE
const SOURCE_MAP = {
version: 3,
file: 'app.js',
sources: ['src/greet.js'],
sourcesContent: ['// The original source, comments included.' + NEWLINE + 'function greet() { return "Fixture Bookings" }'],
names: [],
mappings: '',
}
function text(status, body) {
return { status: status, type: 'text/plain; charset=utf-8', body: body }
}
function json(status, value) {
return { status: status, type: 'application/json', body: JSON.stringify(value, null, 2) + NEWLINE }
}
function hasOperatorToken(request) {
return request.headers['x-operator-token'] === operatorToken
}
// Row 1: a route that prints the running settings.
function debugReply() {
if (!settings.debugRoutes) return text(404, 'Not found')
return json(200, { page: 'DEBUG PAGE', settings: settings, nodeVersion: process.version })
}
// Row 2: the account the app is installed with.
function loginReply(bodyText) {
let attempt = null
try {
attempt = JSON.parse(bodyText)
} catch (error) {
return text(400, 'Bad request')
}
if (attempt === null || typeof attempt !== 'object') return text(400, 'Bad request')
const matches = attempt.username === LAB_ACCOUNT.username && attempt.password === LAB_ACCOUNT.password
if (settings.defaultAccount === 'enabled' && matches) return json(200, { signedIn: LAB_ACCOUNT.username })
return json(401, { error: 'sign-in refused' })
}
// Row 3: a listing of everything in the files folder.
function listingReply() {
if (!settings.directoryListing) return text(404, 'Not found')
return text(200, 'Index of /files/' + NEWLINE + Object.keys(PUBLIC_FILES).join(NEWLINE) + NEWLINE)
}
function fileReply(folder, name) {
if (!Object.hasOwn(folder, name)) return text(404, 'Not found')
return text(200, folder[name])
}
// Row 4: the storage folder, which stands in for a storage bucket.
function storageReply(request, name) {
if (settings.storageAccess !== 'public-read' && !hasOperatorToken(request)) return text(403, 'Access denied')
return fileReply(STORAGE, name)
}
// Row 5: this function has a real fault. An unknown booking id makes it read
// a property of undefined, and what the visitor then sees is a setting.
function bookingReply(id) {
const booking = BOOKINGS.get(id)
return text(200, 'Booking ' + id + ': ' + booking.service + ' on ' + booking.day)
}
function errorReply(error) {
if (settings.errorDetail === 'stack-trace') return text(500, error.stack)
const reference = randomBytes(4).toString('hex')
appendFileSync(join(STATE_DIR, settings.environment + '-errors.log'), reference + ' ' + error.stack + NEWLINE)
return text(500, 'Something went wrong. Reference: ' + reference)
}
// Row 6: the admin page.
function adminReply(request) {
if (settings.adminAccess === 'anyone' || hasOperatorToken(request)) {
return text(200, 'ADMIN PAGE: bookings, accounts and settings for Fixture Bookings')
}
return text(401, 'Operator sign-in needed')
}
function methodNotAllowed() {
const reply = text(405, 'Method not allowed')
reply.headers = { allow: 'GET, HEAD, POST' }
return reply
}
// Row 7: TRACE sends the request back to whoever sent it.
function traceReply(request) {
if (!settings.traceMethod) return methodNotAllowed()
const lines = ['TRACE ' + request.url + ' HTTP/' + request.httpVersion]
for (let index = 0; index < request.rawHeaders.length; index = index + 2) {
lines.push(request.rawHeaders[index] + ': ' + request.rawHeaders[index + 1])
}
return { status: 200, type: 'message/http', body: lines.join(NEWLINE) + NEWLINE }
}
// Row 8: a monitoring endpoint.
function statusReply() {
if (settings.statusEndpoint !== 'public') return text(404, 'Not found')
const status = { status: 'ok', environment: settings.environment, uptimeSeconds: Math.round(process.uptime()), nodeVersion: process.version }
return json(200, status)
}
// Row 9: the source map for the bundle.
function sourceMapReply() {
if (!settings.sourceMaps) return text(404, 'Not found')
return json(200, SOURCE_MAP)
}
function route(request, bodyText) {
const path = request.url.split('?')[0]
if (request.method === 'TRACE') return traceReply(request)
if (request.method === 'POST' && path === '/login') return loginReply(bodyText)
if (request.method !== 'GET' && request.method !== 'HEAD') return methodNotAllowed()
if (path === '/') return text(200, 'Fixture Bookings, ' + settings.environment + ' instance')
if (path === '/debug/settings') return debugReply()
if (path === '/files/') return listingReply()
if (path.startsWith('/files/')) return fileReply(PUBLIC_FILES, path.slice('/files/'.length))
if (path.startsWith('/storage/')) return storageReply(request, path.slice('/storage/'.length))
if (path.startsWith('/bookings/')) return bookingReply(path.slice('/bookings/'.length))
if (path === '/admin') return adminReply(request)
if (path === '/status') return statusReply()
if (path === '/assets/app.js') return text(200, BUNDLE)
if (path === '/assets/app.js.map') return sourceMapReply()
return text(404, 'Not found')
}
// Row 10: a successful answer always carries the header. An error answer
// carries it only when the setting says every response.
function sendReply(response, reply) {
const headers = Object.assign({ 'content-type': reply.type }, reply.headers || {})
const isError = reply.status >= 400
if (!isError || settings.securityHeaders === 'every-response') headers['x-content-type-options'] = 'nosniff'
response.writeHead(reply.status, headers)
response.end(reply.body)
}
const server = createServer((request, response) => {
let bodyText = ''
request.on('data', (chunk) => {
if (bodyText.length < 2000) bodyText = bodyText + chunk
})
request.on('end', () => {
let reply = null
try {
reply = route(request, bodyText)
} catch (error) {
reply = errorReply(error)
}
sendReply(response, reply)
})
})
server.listen(0, '127.0.0.1', () => {
mkdirSync(STATE_DIR, { recursive: true })
const state = { pid: process.pid, port: server.address().port, operatorToken: operatorToken }
writeFileSync(statePath(settings.environment), JSON.stringify(state), { mode: 0o600 })
})
process.on('SIGTERM', () => {
server.closeAllConnections()
server.close(() => process.exit(0))
})
================================================================
FILE 8 OF 14: instances.mjs
================================================================
// instances.mjs: starts, restarts or stops instances of the app: one for each
// name in the ENVIRONMENTS list, or only the one named on the command line.
// Each is started from the config file of that name, runs in the background
// and is stopped by the process id it recorded, never by name.
// Usage: node instances.mjs start
// node instances.mjs restart production
// node instances.mjs stop
import { spawn } from 'node:child_process'
import { existsSync, mkdirSync, openSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import { setTimeout as wait } from 'node:timers/promises'
import { ENVIRONMENTS, LAB_DIR, STATE_DIR, configPath, readState, statePath } from './lab-common.mjs'
function isRunning(pid) {
try {
process.kill(pid, 0)
return true
} catch (error) {
return false
}
}
async function start(environment) {
mkdirSync(STATE_DIR, { recursive: true })
if (existsSync(statePath(environment)) && isRunning(readState(environment).pid)) {
console.log(environment.padEnd(12) + 'is already running, pid ' + readState(environment).pid)
return
}
rmSync(statePath(environment), { force: true })
const log = openSync(join(STATE_DIR, environment + '.log'), 'a')
const options = { detached: true, stdio: ['ignore', log, log] }
const child = spawn(process.execPath, [join(LAB_DIR, 'app.mjs'), configPath(environment)], options)
child.unref()
for (let attempt = 0; attempt < 50 && !existsSync(statePath(environment)); attempt++) await wait(100)
if (!existsSync(statePath(environment))) throw new Error(environment + ' did not start: read its log in lab-state')
const pid = readState(environment).pid
console.log(environment.padEnd(12) + 'started from config/' + environment + '.json on 127.0.0.1, pid ' + pid)
}
async function stop(environment) {
const pid = readState(environment).pid
process.kill(pid, 'SIGTERM')
for (let attempt = 0; attempt < 50 && isRunning(pid); attempt++) await wait(100)
if (isRunning(pid)) throw new Error(environment + ' is still running, pid ' + pid)
rmSync(statePath(environment))
console.log(environment.padEnd(12) + 'stopped, pid ' + pid)
}
const action = process.argv[2]
const targets = process.argv[3] ? [process.argv[3]] : ENVIRONMENTS
const known = targets.every((environment) => ENVIRONMENTS.includes(environment))
if (!known || !['start', 'restart', 'stop'].includes(action)) {
console.log('Usage: node instances.mjs start, restart or stop, then an optional environment name')
process.exit(1)
}
for (const environment of targets) {
if (action !== 'start') await stop(environment)
if (action !== 'stop') await start(environment)
}
================================================================
FILE 9 OF 14: set-production.mjs
================================================================
// set-production.mjs: copies one of the two versions of the production
// configuration into config/production.json. It changes the file only. An
// instance that is already running keeps the settings it loaded at start.
// Usage: node set-production.mjs careless
// node set-production.mjs careful
import { copyFileSync } from 'node:fs'
import { join } from 'node:path'
import { LAB_DIR, configPath } from './lab-common.mjs'
const version = process.argv[2]
if (version !== 'careless' && version !== 'careful') {
console.log('Usage: node set-production.mjs careless, or node set-production.mjs careful')
process.exit(1)
}
copyFileSync(join(LAB_DIR, 'production-versions', version + '.json'), configPath('production'))
console.log('config/production.json now holds production-versions/' + version + '.json')
console.log('any instance already running keeps the settings it loaded when it started')
================================================================
FILE 10 OF 14: drift-check.mjs
================================================================
// drift-check.mjs: reads the three configuration files and reports every
// setting that differs from the expected production value. A difference in
// development or staging is accepted only if expected-production.json gives a
// written reason for it. A difference in production is always drift. It reads
// files only, so it says nothing about what a running instance is doing.
// Exits with code 1 if any difference is not accepted in writing.
import { ENVIRONMENTS, configPath, readExpected, readJson } from './lab-common.mjs'
const expected = readExpected()
function show(value) {
return value === undefined ? '(missing)' : JSON.stringify(value)
}
function printExpected() {
console.log('EXPECTED IN PRODUCTION, from expected-production.json')
console.log(' row setting expected value owner')
for (const setting of expected.settings) {
const row = String(setting.worksheetRow).padEnd(5)
console.log(' ' + row + setting.name.padEnd(18) + show(setting.expectedInProduction).padEnd(22) + setting.owner)
}
}
// Production has no accepted differences: the expected values describe it.
function findDifferences(environment) {
const config = readJson(configPath(environment))
const accepted = environment === 'production' ? {} : expected.acceptedDifferences[environment] || {}
const differences = []
for (const setting of expected.settings) {
if (config[setting.name] === setting.expectedInProduction) continue
differences.push({ setting: setting, value: config[setting.name], reason: accepted[setting.name] })
}
return differences
}
function printEnvironment(environment, differences) {
console.log('')
console.log(environment + ', from config/' + environment + '.json')
for (const difference of differences) {
const row = String(difference.setting.worksheetRow).padEnd(5)
const verdict = difference.reason ? 'accepted: ' + difference.reason : 'DRIFT, owner: ' + difference.setting.owner
console.log(' ' + row + difference.setting.name.padEnd(18) + show(difference.value).padEnd(26) + verdict)
}
const drift = differences.filter((difference) => !difference.reason).length
const accepted = differences.length - drift
const total = expected.settings.length
console.log(' ' + differences.length + ' of ' + total + ' settings differ: ' + accepted + ' accepted in writing, ' + drift + ' drift')
return drift
}
printExpected()
let driftCount = 0
for (const environment of ENVIRONMENTS) {
driftCount = driftCount + printEnvironment(environment, findDifferences(environment))
}
console.log('')
if (driftCount === 0) console.log('RESULT: no drift. Every difference from the expected production values is accepted in writing.')
else console.log('RESULT: ' + driftCount + ' setting(s) differ from the expected production value with no written acceptance.')
process.exitCode = driftCount === 0 ? 0 : 1
================================================================
FILE 11 OF 14: observations.mjs
================================================================
// observations.mjs: the ten requests that the probe and the regression test
// both send, one for each worksheet row, how each answer is read, and the
// answer the intended production settings give. The regression test sends one
// more request of its own, which is not listed here. Every request goes to an
// instance of the lab's own app on 127.0.0.1.
import { LAB_ACCOUNT, NEWLINE, requestFromInstance } from './lab-common.mjs'
const STACK_LINE = NEWLINE + ' at '
const MARKER = 'trace-check-marker'
export const OBSERVATIONS = [
{
row: 1,
label: 'debug route',
shownAs: 'GET /debug/settings',
request: { path: '/debug/settings' },
read: (response) => (response.body.includes('DEBUG PAGE') ? 'debug page shown' : 'no debug page'),
intended: '404 no debug page',
},
{
row: 2,
label: 'default account',
shownAs: 'POST /login as the lab account',
request: { method: 'POST', path: '/login', body: JSON.stringify(LAB_ACCOUNT) },
read: (response) => (response.body.includes('signedIn') ? 'signed in' : 'refused'),
intended: '401 refused',
},
{
row: 3,
label: 'directory listing',
shownAs: 'GET /files/',
request: { path: '/files/' },
read: (response) => (response.body.includes('Index of') ? 'listing shown' : 'no listing'),
intended: '404 no listing',
},
{
row: 4,
label: 'storage file',
shownAs: 'GET /storage/exports/bookings.csv',
request: { path: '/storage/exports/bookings.csv' },
read: (response) => (response.body.includes('booking,service,day') ? 'file returned' : 'no file'),
intended: '403 no file',
},
{
row: 5,
label: 'error output',
shownAs: 'GET /bookings/not-a-number',
request: { path: '/bookings/not-a-number' },
read: (response) => (response.body.includes(STACK_LINE) ? 'stack trace in body' : 'no stack trace'),
intended: '500 no stack trace',
},
{
row: 6,
label: 'admin page',
shownAs: 'GET /admin with no token',
request: { path: '/admin' },
read: (response) => (response.body.includes('ADMIN PAGE') ? 'admin page shown' : 'no admin page'),
intended: '401 no admin page',
},
{
row: 7,
label: 'TRACE method',
shownAs: 'TRACE /',
request: { method: 'TRACE', path: '/', headers: { 'x-lab-marker': MARKER } },
read: (response) => (response.body.includes(MARKER) ? 'request echoed' : 'not echoed'),
intended: '405 not echoed',
},
{
row: 8,
label: 'status endpoint',
shownAs: 'GET /status',
request: { path: '/status' },
read: (response) => (response.body.includes('uptimeSeconds') ? 'status data shown' : 'no status data'),
intended: '404 no status data',
},
{
row: 9,
label: 'source map',
shownAs: 'GET /assets/app.js.map',
request: { path: '/assets/app.js.map' },
read: (response) => (response.body.includes('sourcesContent') ? 'source map returned' : 'no source map'),
intended: '404 no source map',
},
{
row: 10,
label: 'header on a 404',
shownAs: 'GET /no-such-page',
request: { path: '/no-such-page' },
read: (response) => (response.headers['x-content-type-options'] === 'nosniff' ? 'nosniff sent' : 'nosniff missing'),
intended: '404 nosniff sent',
},
]
// Sends one observation's request and returns the answer as short text, such
// as "404 no debug page", ready to compare with the intended answer.
export async function observe(environment, observation) {
const response = await requestFromInstance(environment, observation.request)
return response.status + ' ' + observation.read(response)
}
================================================================
FILE 12 OF 14: probe.mjs
================================================================
// probe.mjs: asks each running instance for the ten observable items and
// prints what came back: the status, and what the answer shows. For rows 1 to
// 9 that is read from the body (a debug page, a listing, a stack trace and so
// on), and for row 10 from a response header. It looks from outside, so it
// reports what an instance is doing now, whatever its file says.
// Usage: node probe.mjs (all three instances)
// node probe.mjs production (one instance)
import { ENVIRONMENTS } from './lab-common.mjs'
import { OBSERVATIONS, observe } from './observations.mjs'
async function probeEnvironment(environment) {
console.log('')
console.log(environment + ' instance')
let differing = 0
for (const observation of OBSERVATIONS) {
const answer = await observe(environment, observation)
const verdict = answer === observation.intended ? 'as intended' : 'DIFFERS'
if (verdict === 'DIFFERS') differing = differing + 1
const row = String(observation.row).padEnd(5)
console.log(' ' + row + observation.label.padEnd(19) + observation.shownAs.padEnd(35) + answer.padEnd(26) + verdict)
}
console.log(' ' + differing + ' of ' + OBSERVATIONS.length + ' answers differ from the intended production answer')
}
console.log('PROBE OF THE RUNNING INSTANCES, every request to 127.0.0.1')
console.log(' row looked at request answer against intended production')
const targets = ENVIRONMENTS.includes(process.argv[2]) ? [process.argv[2]] : ENVIRONMENTS
for (const environment of targets) await probeEnvironment(environment)
================================================================
FILE 13 OF 14: show-response.mjs
================================================================
// show-response.mjs: prints one answer from one running instance: the status,
// two of its headers and the body.
// Usage: node show-response.mjs production /bookings/not-a-number
import { ENVIRONMENTS, requestFromInstance } from './lab-common.mjs'
const environment = process.argv[2]
const path = process.argv[3]
if (!ENVIRONMENTS.includes(environment) || !path) {
console.log('Usage: node show-response.mjs, then an environment name, then a path')
process.exit(1)
}
const response = await requestFromInstance(environment, { path: path })
console.log(environment + ' instance, GET ' + path)
console.log('HTTP ' + response.status)
console.log('content-type: ' + response.headers['content-type'])
console.log('x-content-type-options: ' + (response.headers['x-content-type-options'] || '(not sent)'))
console.log('')
console.log(response.body)
================================================================
FILE 14 OF 14: drift.test.mjs
================================================================
// drift.test.mjs: the regression test. It checks production twice: the file,
// against the expected production values, and the running instance, from
// outside. The two can disagree, so it needs both. The last test confirms
// that the restriction did not lock the operators out.
// Run it with: node --test drift.test.mjs
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { configPath, readExpected, readJson, readState, requestFromInstance } from './lab-common.mjs'
import { OBSERVATIONS, observe } from './observations.mjs'
const expected = readExpected()
const production = readJson(configPath('production'))
for (const setting of expected.settings) {
const wanted = setting.expectedInProduction
test('file: production ' + setting.name + ' is ' + JSON.stringify(wanted), () => {
const found = production[setting.name]
const message = 'config/production.json has ' + setting.name + ' = ' + JSON.stringify(found) + ', worksheet row ' + setting.worksheetRow
assert.equal(found, wanted, message)
})
}
for (const observation of OBSERVATIONS) {
test('running: production ' + observation.label + ' answers ' + observation.intended, async () => {
const answer = await observe('production', observation)
const message = observation.shownAs + ' on the running production instance, worksheet row ' + observation.row
assert.equal(answer, observation.intended, message)
})
}
test('running: production admin page opens for an operator who sends the token', async () => {
const token = readState('production').operatorToken
const response = await requestFromInstance('production', { path: '/admin', headers: { 'x-operator-token': token } })
assert.equal(response.status, 200)
})
================================================================
PART 3: THE RECORDED RUN
================================================================
Each command was run from the drift-lab folder, in this order, starting from a folder that held only the fourteen files. Every output is copied from that run by a script. Lines were cut from three outputs, and each cut is marked where it was made: three stack frames in step 6, and the stack trace and error properties of every failed check in steps 7 and 10. Each cut holds a file path on the computer that ran the lab.
Step 1. Command: node set-production.mjs careless
config/production.json now holds production-versions/careless.json
any instance already running keeps the settings it loaded when it started
Exit code: 0
Reading it: the starting point is the careless version of the production file. Nothing is running yet.
Step 2. Command: node instances.mjs start
development started from config/development.json on 127.0.0.1, pid 87196
staging started from config/staging.json on 127.0.0.1, pid 87198
production started from config/production.json on 127.0.0.1, pid 87199
Exit code: 0
Reading it: three instances of the same app, one for each configuration file. The process ids differ from run to run.
Step 3. Command: node drift-check.mjs
EXPECTED IN PRODUCTION, from expected-production.json
row setting expected value owner
1 debugRoutes false application lead
2 defaultAccount "removed" application lead
3 directoryListing false hosting lead
4 storageAccess "private" hosting lead
5 errorDetail "generic-message" application lead
6 adminAccess "operators-only" application lead
7 traceMethod false hosting lead
8 statusEndpoint "off" hosting lead
9 sourceMaps false application lead
10 securityHeaders "every-response" hosting lead
development, from config/development.json
1 debugRoutes true accepted: developers read the running settings while building
2 defaultAccount "enabled" accepted: a fresh local install signs in with the setup account
3 directoryListing true accepted: a quick look at which files a build produced
4 storageAccess "public-read" accepted: test exports are opened straight from a browser
5 errorDetail "stack-trace" accepted: the stack trace is read in the browser while coding
6 adminAccess "anyone" accepted: admin screens are built without signing in each time
7 traceMethod true accepted: used to see what a local proxy adds to a request
8 statusEndpoint "public" accepted: watched during local load checks
9 sourceMaps true accepted: readable code in the browser debugger
10 securityHeaders "success-responses-only" accepted: error pages are still being restyled
10 of 10 settings differ: 10 accepted in writing, 0 drift
staging, from config/staging.json
8 statusEndpoint "public" accepted: the team watches staging through it during release rehearsals
1 of 10 settings differ: 1 accepted in writing, 0 drift
production, from config/production.json
1 debugRoutes true DRIFT, owner: application lead
2 defaultAccount "enabled" DRIFT, owner: application lead
3 directoryListing true DRIFT, owner: hosting lead
4 storageAccess "public-read" DRIFT, owner: hosting lead
5 errorDetail "stack-trace" DRIFT, owner: application lead
6 adminAccess "anyone" DRIFT, owner: application lead
6 of 10 settings differ: 0 accepted in writing, 6 drift
RESULT: 6 setting(s) differ from the expected production value with no written acceptance.
Exit code: 1
Reading it: the first table is the one reviewed place, expected-production.json. Development differs from it in all ten settings and every difference has a written reason. Staging differs in one, with a reason. Production differs in six. A difference in production is never accepted, because the expected values describe production, so each line is drift and names the owner to ask. The script exits with code 1.
Step 4. Command: node probe.mjs
PROBE OF THE RUNNING INSTANCES, every request to 127.0.0.1
row looked at request answer against intended production
development instance
1 debug route GET /debug/settings 200 debug page shown DIFFERS
2 default account POST /login as the lab account 200 signed in DIFFERS
3 directory listing GET /files/ 200 listing shown DIFFERS
4 storage file GET /storage/exports/bookings.csv 200 file returned DIFFERS
5 error output GET /bookings/not-a-number 500 stack trace in body DIFFERS
6 admin page GET /admin with no token 200 admin page shown DIFFERS
7 TRACE method TRACE / 200 request echoed DIFFERS
8 status endpoint GET /status 200 status data shown DIFFERS
9 source map GET /assets/app.js.map 200 source map returned DIFFERS
10 header on a 404 GET /no-such-page 404 nosniff missing DIFFERS
10 of 10 answers differ from the intended production answer
staging instance
1 debug route GET /debug/settings 404 no debug page as intended
2 default account POST /login as the lab account 401 refused as intended
3 directory listing GET /files/ 404 no listing as intended
4 storage file GET /storage/exports/bookings.csv 403 no file as intended
5 error output GET /bookings/not-a-number 500 no stack trace as intended
6 admin page GET /admin with no token 401 no admin page as intended
7 TRACE method TRACE / 405 not echoed as intended
8 status endpoint GET /status 200 status data shown DIFFERS
9 source map GET /assets/app.js.map 404 no source map as intended
10 header on a 404 GET /no-such-page 404 nosniff sent as intended
1 of 10 answers differ from the intended production answer
production instance
1 debug route GET /debug/settings 200 debug page shown DIFFERS
2 default account POST /login as the lab account 200 signed in DIFFERS
3 directory listing GET /files/ 200 listing shown DIFFERS
4 storage file GET /storage/exports/bookings.csv 200 file returned DIFFERS
5 error output GET /bookings/not-a-number 500 stack trace in body DIFFERS
6 admin page GET /admin with no token 200 admin page shown DIFFERS
7 TRACE method TRACE / 405 not echoed as intended
8 status endpoint GET /status 404 no status data as intended
9 source map GET /assets/app.js.map 404 no source map as intended
10 header on a 404 GET /no-such-page 404 nosniff sent as intended
6 of 10 answers differ from the intended production answer
Exit code: 0
Reading it: this is the outside view, and here it agrees with the files, because each instance was started from the file it is compared with. Development answers differ from the intended production answer in all ten rows, staging in one and production in six. The probe does not know which differences someone accepted. It reports what each instance does.
Step 5. Command: node show-response.mjs production /debug/settings
production instance, GET /debug/settings
HTTP 200
content-type: application/json
x-content-type-options: nosniff
{
"page": "DEBUG PAGE",
"settings": {
"environment": "production",
"debugRoutes": true,
"defaultAccount": "enabled",
"directoryListing": true,
"storageAccess": "public-read",
"errorDetail": "stack-trace",
"adminAccess": "anyone",
"traceMethod": false,
"statusEndpoint": "off",
"sourceMaps": false,
"securityHeaders": "every-response"
},
"nodeVersion": "v26.0.0"
}
Exit code: 0
Reading it: this is what anyone who requested the debug route would read. It is every running setting, which makes it a list of the five other things worth trying, plus the runtime version.
Step 6. Command: node show-response.mjs production /bookings/not-a-number
production instance, GET /bookings/not-a-number
HTTP 500
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
TypeError: Cannot read properties of undefined (reading 'service')
(3 lines cut here, each a stack frame that holds a local file path: bookingReply at app.mjs:90:53; route at app.mjs:147:45; IncomingMessage.<anonymous> at app.mjs:173:15)
at IncomingMessage.emit (node:events:509:20)
at endReadableNT (node:internal/streams/readable:1734:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Exit code: 0
Reading it: the fault is real. An unknown booking id makes bookingReply read a property of undefined. The three cut lines are the first three stack frames. Each held a file path on the computer that ran the lab, and the marker keeps what else they showed: the function, the file and the line and column that failed. The same response on a real system gives a stranger that, plus where the application is installed.
Step 7. Command: node --test drift.test.mjs
✖ file: production debugRoutes is false (1.302459ms)
✖ file: production defaultAccount is "removed" (0.197583ms)
✖ file: production directoryListing is false (0.05975ms)
✖ file: production storageAccess is "private" (0.057667ms)
✖ file: production errorDetail is "generic-message" (0.055583ms)
✖ file: production adminAccess is "operators-only" (0.055417ms)
✔ file: production traceMethod is false (0.064875ms)
✔ file: production statusEndpoint is "off" (0.034042ms)
✔ file: production sourceMaps is false (0.052083ms)
✔ file: production securityHeaders is "every-response" (0.067917ms)
✖ running: production debug route answers 404 no debug page (6.653708ms)
✖ running: production default account answers 401 refused (1.533792ms)
✖ running: production directory listing answers 404 no listing (1.055542ms)
✖ running: production storage file answers 403 no file (0.992083ms)
✖ running: production error output answers 500 no stack trace (1.156375ms)
✖ running: production admin page answers 401 no admin page (0.982416ms)
✔ running: production TRACE method answers 405 not echoed (0.797834ms)
✔ running: production status endpoint answers 404 no status data (0.738542ms)
✔ running: production source map answers 404 no source map (1.08475ms)
✔ running: production header on a 404 answers 404 nosniff sent (0.878875ms)
✔ running: production admin page opens for an operator who sends the token (0.771458ms)
ℹ tests 21
ℹ suites 0
ℹ pass 9
ℹ fail 12
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 133.37425
✖ failing tests:
test at drift.test.mjs:16:3
✖ file: production debugRoutes is false (1.302459ms)
AssertionError [ERR_ASSERTION]: config/production.json has debugRoutes = true, worksheet row 1
true !== false
(12 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:16:3
✖ file: production defaultAccount is "removed" (0.197583ms)
AssertionError [ERR_ASSERTION]: config/production.json has defaultAccount = "enabled", worksheet row 2
+ actual - expected
+ 'enabled'
- 'removed'
(14 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:16:3
✖ file: production directoryListing is false (0.05975ms)
AssertionError [ERR_ASSERTION]: config/production.json has directoryListing = true, worksheet row 3
true !== false
(14 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:16:3
✖ file: production storageAccess is "private" (0.057667ms)
AssertionError [ERR_ASSERTION]: config/production.json has storageAccess = "public-read", worksheet row 4
+ actual - expected
+ 'public-read'
- 'private'
(14 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:16:3
✖ file: production errorDetail is "generic-message" (0.055583ms)
AssertionError [ERR_ASSERTION]: config/production.json has errorDetail = "stack-trace", worksheet row 5
+ actual - expected
+ 'stack-trace'
- 'generic-message'
(14 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:16:3
✖ file: production adminAccess is "operators-only" (0.055417ms)
AssertionError [ERR_ASSERTION]: config/production.json has adminAccess = "anyone", worksheet row 6
+ actual - expected
+ 'anyone'
- 'operators-only'
(14 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production debug route answers 404 no debug page (6.653708ms)
AssertionError [ERR_ASSERTION]: GET /debug/settings on the running production instance, worksheet row 1
+ actual - expected
+ '200 debug page shown'
- '404 no debug page'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production default account answers 401 refused (1.533792ms)
AssertionError [ERR_ASSERTION]: POST /login as the lab account on the running production instance, worksheet row 2
+ actual - expected
+ '200 signed in'
- '401 refused'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production directory listing answers 404 no listing (1.055542ms)
AssertionError [ERR_ASSERTION]: GET /files/ on the running production instance, worksheet row 3
+ actual - expected
+ '200 listing shown'
- '404 no listing'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production storage file answers 403 no file (0.992083ms)
AssertionError [ERR_ASSERTION]: GET /storage/exports/bookings.csv on the running production instance, worksheet row 4
+ actual - expected
+ '200 file returned'
- '403 no file'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production error output answers 500 no stack trace (1.156375ms)
AssertionError [ERR_ASSERTION]: GET /bookings/not-a-number on the running production instance, worksheet row 5
+ actual - expected
+ '500 stack trace in body'
- '500 no stack trace'
^
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production admin page answers 401 no admin page (0.982416ms)
AssertionError [ERR_ASSERTION]: GET /admin with no token on the running production instance, worksheet row 6
+ actual - expected
+ '200 admin page shown'
- '401 no admin page'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
Exit code: 1
Reading it: twelve of the twenty-one checks fail. Six read the production file and six ask the running production instance, and they are the same six rows. The four settings that were right pass both ways, and the operator can reach the admin page. The process exits with code 1.
Step 8. Command: node set-production.mjs careful
config/production.json now holds production-versions/careful.json
any instance already running keeps the settings it loaded when it started
Exit code: 0
Reading it: only the file changed. The production instance started in step 2 is still running.
Step 9. Command: node drift-check.mjs
EXPECTED IN PRODUCTION, from expected-production.json
row setting expected value owner
1 debugRoutes false application lead
2 defaultAccount "removed" application lead
3 directoryListing false hosting lead
4 storageAccess "private" hosting lead
5 errorDetail "generic-message" application lead
6 adminAccess "operators-only" application lead
7 traceMethod false hosting lead
8 statusEndpoint "off" hosting lead
9 sourceMaps false application lead
10 securityHeaders "every-response" hosting lead
development, from config/development.json
1 debugRoutes true accepted: developers read the running settings while building
2 defaultAccount "enabled" accepted: a fresh local install signs in with the setup account
3 directoryListing true accepted: a quick look at which files a build produced
4 storageAccess "public-read" accepted: test exports are opened straight from a browser
5 errorDetail "stack-trace" accepted: the stack trace is read in the browser while coding
6 adminAccess "anyone" accepted: admin screens are built without signing in each time
7 traceMethod true accepted: used to see what a local proxy adds to a request
8 statusEndpoint "public" accepted: watched during local load checks
9 sourceMaps true accepted: readable code in the browser debugger
10 securityHeaders "success-responses-only" accepted: error pages are still being restyled
10 of 10 settings differ: 10 accepted in writing, 0 drift
staging, from config/staging.json
8 statusEndpoint "public" accepted: the team watches staging through it during release rehearsals
1 of 10 settings differ: 1 accepted in writing, 0 drift
production, from config/production.json
0 of 10 settings differ: 0 accepted in writing, 0 drift
RESULT: no drift. Every difference from the expected production values is accepted in writing.
Exit code: 0
Reading it: with the careful version in place, the production file has no differences and the script exits with code 0. Nothing has been restarted.
Step 10. Command: node --test drift.test.mjs
✔ file: production debugRoutes is false (0.793667ms)
✔ file: production defaultAccount is "removed" (0.050375ms)
✔ file: production directoryListing is false (0.041625ms)
✔ file: production storageAccess is "private" (0.037333ms)
✔ file: production errorDetail is "generic-message" (0.039417ms)
✔ file: production adminAccess is "operators-only" (0.039792ms)
✔ file: production traceMethod is false (0.040167ms)
✔ file: production statusEndpoint is "off" (0.033208ms)
✔ file: production sourceMaps is false (0.044667ms)
✔ file: production securityHeaders is "every-response" (0.06775ms)
✖ running: production debug route answers 404 no debug page (6.62475ms)
✖ running: production default account answers 401 refused (1.907084ms)
✖ running: production directory listing answers 404 no listing (1.301875ms)
✖ running: production storage file answers 403 no file (1.000791ms)
✖ running: production error output answers 500 no stack trace (0.953791ms)
✖ running: production admin page answers 401 no admin page (1.0015ms)
✔ running: production TRACE method answers 405 not echoed (0.932334ms)
✔ running: production status endpoint answers 404 no status data (0.689208ms)
✔ running: production source map answers 404 no source map (0.8445ms)
✔ running: production header on a 404 answers 404 nosniff sent (0.930375ms)
✔ running: production admin page opens for an operator who sends the token (0.717083ms)
ℹ tests 21
ℹ suites 0
ℹ pass 15
ℹ fail 6
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 128.539958
✖ failing tests:
test at drift.test.mjs:24:3
✖ running: production debug route answers 404 no debug page (6.62475ms)
AssertionError [ERR_ASSERTION]: GET /debug/settings on the running production instance, worksheet row 1
+ actual - expected
+ '200 debug page shown'
- '404 no debug page'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production default account answers 401 refused (1.907084ms)
AssertionError [ERR_ASSERTION]: POST /login as the lab account on the running production instance, worksheet row 2
+ actual - expected
+ '200 signed in'
- '401 refused'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production directory listing answers 404 no listing (1.301875ms)
AssertionError [ERR_ASSERTION]: GET /files/ on the running production instance, worksheet row 3
+ actual - expected
+ '200 listing shown'
- '404 no listing'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production storage file answers 403 no file (1.000791ms)
AssertionError [ERR_ASSERTION]: GET /storage/exports/bookings.csv on the running production instance, worksheet row 4
+ actual - expected
+ '200 file returned'
- '403 no file'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production error output answers 500 no stack trace (0.953791ms)
AssertionError [ERR_ASSERTION]: GET /bookings/not-a-number on the running production instance, worksheet row 5
+ actual - expected
+ '500 stack trace in body'
- '500 no stack trace'
^
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
test at drift.test.mjs:24:3
✖ running: production admin page answers 401 no admin page (1.0015ms)
AssertionError [ERR_ASSERTION]: GET /admin with no token on the running production instance, worksheet row 6
+ actual - expected
+ '200 admin page shown'
- '401 no admin page'
(11 lines cut here: the stack trace, whose first line holds a local file path, and the properties of the error)
Exit code: 1
Reading it: this is the result to remember. All ten file checks pass, and six checks against the running instance still fail, because the instance loaded its settings when it started in step 2 and nothing has told it to read them again. The file is fixed and production is not. A review that stopped at the file would have passed a system that was still serving its debug page.
Step 11. Command: node instances.mjs restart production
production stopped, pid 87199
production started from config/production.json on 127.0.0.1, pid 87736
Exit code: 0
Reading it: the production instance is stopped by its recorded process id and started again, so it reads the file as it is now.
Step 12. Command: node probe.mjs production
PROBE OF THE RUNNING INSTANCES, every request to 127.0.0.1
row looked at request answer against intended production
production instance
1 debug route GET /debug/settings 404 no debug page as intended
2 default account POST /login as the lab account 401 refused as intended
3 directory listing GET /files/ 404 no listing as intended
4 storage file GET /storage/exports/bookings.csv 403 no file as intended
5 error output GET /bookings/not-a-number 500 no stack trace as intended
6 admin page GET /admin with no token 401 no admin page as intended
7 TRACE method TRACE / 405 not echoed as intended
8 status endpoint GET /status 404 no status data as intended
9 source map GET /assets/app.js.map 404 no source map as intended
10 header on a 404 GET /no-such-page 404 nosniff sent as intended
0 of 10 answers differ from the intended production answer
Exit code: 0
Reading it: after the restart, all ten production answers are the intended ones.
Step 13. Command: node show-response.mjs production /bookings/not-a-number
production instance, GET /bookings/not-a-number
HTTP 500
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
Something went wrong. Reference: dbd66e64
Exit code: 0
Reading it: the same fault and the same status, in one line. The stack trace went to lab-state/production-errors.log on a line that starts with the same reference, which is how the team finds it.
Step 14. Command: node --test drift.test.mjs
✔ file: production debugRoutes is false (0.741583ms)
✔ file: production defaultAccount is "removed" (0.043708ms)
✔ file: production directoryListing is false (0.037125ms)
✔ file: production storageAccess is "private" (0.034959ms)
✔ file: production errorDetail is "generic-message" (0.047042ms)
✔ file: production adminAccess is "operators-only" (0.044958ms)
✔ file: production traceMethod is false (0.039625ms)
✔ file: production statusEndpoint is "off" (0.027208ms)
✔ file: production sourceMaps is false (0.044792ms)
✔ file: production securityHeaders is "every-response" (0.066875ms)
✔ running: production debug route answers 404 no debug page (5.569125ms)
✔ running: production default account answers 401 refused (1.033166ms)
✔ running: production directory listing answers 404 no listing (0.744166ms)
✔ running: production storage file answers 403 no file (0.865334ms)
✔ running: production error output answers 500 no stack trace (1.041916ms)
✔ running: production admin page answers 401 no admin page (0.614083ms)
✔ running: production TRACE method answers 405 not echoed (0.67375ms)
✔ running: production status endpoint answers 404 no status data (0.5275ms)
✔ running: production source map answers 404 no source map (0.590208ms)
✔ running: production header on a 404 answers 404 nosniff sent (0.71875ms)
✔ running: production admin page opens for an operator who sends the token (0.578833ms)
ℹ tests 21
ℹ suites 0
ℹ pass 21
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 129.258541
Exit code: 0
Reading it: all twenty-one checks pass and the process exits with code 0, which a pipeline step that treats a non-zero exit code as a failure counts as a pass.
Step 15. Command: node instances.mjs stop
development stopped, pid 87196
staging stopped, pid 87198
production stopped, pid 87736
Exit code: 0
Reading it: each instance is stopped by the process id it recorded, and the script waits until that process has gone.
================================================================
PART 4: THE SAME CHECKS ON YOUR OWN APPLICATION
================================================================
Run these steps only on systems you own or are authorised in writing to test.
Write down what production should be
[ ] Fill in the expected value and the owner of every worksheet row before you look at any environment.
[ ] Add a row for each setting of your own that changes what a stranger can reach, such as a feature flag that opens a preview or a rule that exempts a path from sign-in.
[ ] Keep the expected values in one file that goes through review, the way the lab keeps expected-production.json.
Compare the configuration
[ ] Collect each environment's real configuration: settings files, the environment variables each process was started with, web server and CDN rules, and storage permissions.
[ ] Compare each with the expected values. In development and staging, accept a difference only with a written reason and a name. In production, treat every difference as drift.
[ ] For each default you rely on, note the product version and the documentation page that states it.
Look from outside
[ ] Run the worksheet's outside check for each row against each of your hostnames, staging included.
[ ] Read the body as well as the status code, and keep the request, the answer and the date as evidence.
[ ] Keep the default-account check on a test installation unless the owner of production has agreed to it.
Fix, then prove
[ ] Change the setting in the one reviewed place, not only on the server.
[ ] Restart or redeploy whatever reads the setting, then repeat the outside check. A fixed file with a running process that has not read it is not a fix.
Keep it checked
[ ] Put the comparison and the outside checks in the release pipeline, like drift.test.mjs, so a release stops when either fails.
[ ] After any incident in which production was changed directly, run both before the incident is closed.
[ ] Review the rows again when a host, CDN, framework or server version changes, because a default can change with it.What a security misconfiguration is
A security misconfiguration is a weakness that lives in a setting rather than in the code.
The software does what it was built to do, and a switch, a permission, a leftover account or a forgotten file leaves it open: debug mode still on, a folder that lists its own contents, an admin page anyone can load, a storage bucket shared with the whole internet. Nothing has to be rewritten to fix it. A setting changes, an account is removed, a port is closed.
The OWASP Top 10:2025 gives it a category of its own, A02 Security Misconfiguration, and defines it as a system, application or cloud service that is set up incorrectly from a security perspective, creating vulnerabilities. The same page says the category moved up from fifth place in the previous edition, and that 100% of the applications tested were found to have some form of misconfiguration, with an average incidence rate of 3.00%.
Its explanation is brief: with more shifts into highly configurable software, it is not surprising to see this category moving up.
A02 lists eight signs that an application might be vulnerable. They include unnecessary features that are enabled or installed, for which it gives unnecessary ports, services, pages, accounts, testing frameworks and privileges as examples; default accounts and their passwords still enabled and unchanged; error handling that reveals stack traces or other overly informative error messages to users; improperly configured permissions on cloud services; and a server that does not send security headers or directives, or does not set them to secure values.
After the list, the description adds a sentence worth keeping in view: without a concerted, repeatable application security configuration hardening process, systems are at a higher risk.
The category is wide because settings are everywhere. A02 maps sixteen CWE weaknesses to it, and several have guides of their own in this library: CWE-614, Sensitive Cookie in HTTPS Session Without 'Secure' Attribute; CWE-1004, Sensitive Cookie Without 'HttpOnly' Flag; CWE-942, Permissive Cross-domain Policy with Untrusted Domains; CWE-611, Improper Restriction of XML External Entity Reference; and CWE-776, Improper Restriction of Recursive Entity References in DTDs ('XML Entity Expansion').
On this page's reading, each is a setting someone left more open than the application needed. This page takes the idea they share, and the cases no other guide owns: the gap between the settings a team tested and the settings production is running, default accounts and sample content, debug and diagnostic routes, directory listings, verbose errors, admin interfaces and services reachable from the internet, and storage that is public by setting.
How OWASP's testing guide and ASVS cover configuration
Two OWASP documents turn the category into things a team can check.
Version 4.2 of the Web Security Testing Guide (WSTG) has a chapter of eleven tests, 4.2 Configuration and Deployment Management Testing. Version 5.0 of the Application Security Verification Standard (ASVS) has a chapter of requirements, V13 Configuration, whose control objective opens with one sentence: the application's default configuration must be secure for use on the Internet.
These are the tests this page draws on, each with the id and name version 4.2 gives it.
- WSTG-CONF-01, Test Network Infrastructure Configuration. Among its steps: a list of defined ports which are required for the application should be maintained and kept under change control.
- WSTG-CONF-02, Test Application Platform Configuration. Its objectives are to ensure that defaults and known files have been removed, to validate that no debugging code or extensions are left in the production environments, and to review the logging mechanisms set in place for the application.
- WSTG-CONF-05, Enumerate Infrastructure and Application Admin Interfaces. Its objective is to identify hidden administrator interfaces and functionality.
- WSTG-CONF-06, Test HTTP Methods. Its objectives are to enumerate supported HTTP methods, test for access control bypass, test XST vulnerabilities and test HTTP method overriding techniques.
- WSTG-CONF-11, Test Cloud Storage. Its objective is to assess that the access control configuration for the storage services is properly in place.
- Two tests from other chapters belong beside them: WSTG-ATHN-02, Testing for Default Credentials, and WSTG-ERRH-01, Testing for Improper Error Handling, whose objectives are to identify existing error output and analyse the different output returned.
- The chapter's other six tests are 4.2.3 Test File Extensions Handling for Sensitive Information, 4.2.4 Review Old Backup and Unreferenced Files for Sensitive Information, 4.2.7 Test HTTP Strict Transport Security, 4.2.8 Test RIA Cross Domain Policy, 4.2.9 Test File Permission and 4.2.10 Test for Subdomain Takeover.
Section V13.4 holds seven requirements, each with a level from 1 to 3. The first, 13.4.1 at Level 1, concerns source control folders such as .git. The other six are these.
- 13.4.2, Level 2: debug modes are disabled for all components in production environments, to prevent exposure of debugging features and information leakage.
- 13.4.3, Level 2: web servers do not expose directory listings to clients unless explicitly intended.
- 13.4.4, Level 2: the HTTP TRACE method is not supported in production environments, to avoid potential information leakage.
- 13.4.5, Level 2: documentation, such as for internal APIs, and monitoring endpoints are not exposed unless explicitly intended.
- 13.4.6, Level 3: the application does not expose detailed version information of backend components.
- 13.4.7, Level 3: the web tier is configured to only serve files with specific file extensions, to prevent unintentional information, configuration and source code leakage.
The standard is candid about that. V13.4 says many of these issues are rarely rated as significant risks but are often chained with other vulnerabilities, and that if they are not present by default, it raises the bar for attacking an application. It gives two examples of the limit: hiding the version of server-side components does not eliminate the need to patch all components, and disabling folder listing does not remove the need to use authorisation controls or keep files away from the public folder, but it raises the bar.
A02's first attack scenario shows the chaining. An application server ships with sample applications that were never removed from the production server, and they have known security flaws. Suppose, the scenario says, one of them is the admin console and the default accounts were not changed: the attacker logs in with the default password and takes over. Three things left as they were installed, none of them dramatic alone.
Why misconfiguration happens between environments
Take an application that runs in three places: a developer's machine, a staging copy where changes are tried, and production.
Each place has its own copy of the settings. Environment drift is the gap between those copies, and above all between the settings the team tested and the settings production is running.
Drift has two ordinary sources. The first is convenience. Development settings exist to make building easier, and the frameworks say so themselves. Django 6.1's documentation gives the default of its DEBUG setting as False and says never to deploy a site into production with DEBUG turned on, then notes that the default settings.py file created by django-admin startproject sets DEBUG = True for convenience.
Its deployment checklist describes some of Django's security features as optional because they are not always appropriate, or because they are inconvenient for development, and says the checklist includes settings that are expected to be different in each environment.
Express documents the same split from the other side. The Express 5.x API reference gives the default of its env setting as the NODE_ENV environment variable, or "development" if NODE_ENV is not set, and tells readers to be sure to set it to "production" in a production environment.
On this page's reading, a production server whose host never set that variable is running an application that believes it is on a developer's machine.
The testing guide names the mechanism. In its guidance on reviewing a server's configuration, WSTG-CONF-02 says to make sure that application errors are not returned to the end user and that no code is leaked through them, and adds that it is actually very common to forget this point since developers do need this information in pre-production environments.
The second source is a change made under pressure. During an outage someone turns on verbose errors to see what is failing, opens an admin port to reach a server, or makes a storage bucket public so one file can be fetched, and the incident ends before the setting is put back.
Nothing records that production now differs from what was tested, and the next release ships on top of it.
The first item in A02's prevention list is a repeatable hardening process. It says development, QA and production environments should all be configured identically, with different credentials used in each, and that the process should be automated to minimise the effort required to set up a new secure environment.
The same list includes an automated process to verify the effectiveness of the configurations and settings in all environments. Where environments do differ, each difference should be a decision that someone made and wrote down. The lab on this page works that way: its development file differs from the intended production values in all ten settings, each with a written reason, its staging file differs in one, and its careless production file differs in six, with no reason for any of them.
Two gaps a file comparison cannot see
The first is between the file and the running process. An application that reads its settings when it starts keeps them until it starts again. In the lab, replacing the careless production file with the careful one made the file comparison pass at once, while the instance that was already running went on serving its debug page, its listing and its open admin page until it was restarted.
The second is between one layer and another. A request can be answered by a CDN, a web server or the application, and a setting applied in one layer is absent when another layer answers. nginx's documentation gives a concrete case. Its add_header directive adds a field only when the response code is one of the ten it lists, from 200 to 308, unless the always parameter is given.
Its add_header directives are also inherited from the previous configuration level if and only if there are none defined on the current level, a rule the add_header_inherit directive, from nginx 1.29.3, can change.
On this page's reading, a header set once at the top of a configuration can be missing from an error page, or from a location that sets one header of its own.
Security misconfiguration examples, and what each one exposes
Each example below is one row of the worksheet on this page.
Where a product's default is given, it comes from that product's own documentation as it read on 14 November 2026, and it says nothing about any other product. The version is named where the documentation page gives one.
Two of the pages do not say which version they describe: nginx's page for its autoindex module and the Amazon S3 User Guide page on blocking public access. Those two defaults carry only that date.
Debug mode is a framework's promise to tell the developer everything, and it keeps that promise to whoever sends the request. Django 6.1's documentation says that when an app raises an exception with DEBUG set to True, Django displays a detailed traceback, including a lot of metadata about the environment, such as all the currently defined Django settings.
It says Django leaves out settings that might be sensitive, by excluding any setting whose name includes API, KEY, PASS, SECRET, SIGNATURE or TOKEN, and then warns that there are always going to be sections of the debug output that are inappropriate for public consumption: file paths, configuration options and the like all give attackers extra information about the server.
Its deployment checklist is blunter.
You must never enable debug in production, it says, because it leaks lots of information about the project, such as excerpts of source code, local variables, settings and libraries used.
ASVS 5.0 requirement 13.4.2 says "all components", and a site is a stack of them, each with its own switch. WordPress's documentation, for one, says it is not recommended to use WP_DEBUG or the other debug tools on live sites, and that WP_DEBUG_LOG saves errors to a debug.log file in the content directory, usually wp-content/debug.log. The Top 10:2025 lists CWE-489, Active Debug Code, among the weaknesses it maps to A02.
A debug route is the same exposure by another road: a path the team added to print settings, environment values or the state of a queue, meant for development and never removed. The lab's app has one at /debug/settings. Started from the careless production file, it answered 200 and handed over every running setting, which also told the reader which other doors were open.
A product may arrive with an account already in it, so that someone can sign in and finish the installation, and its documentation may give that account's credential. WSTG-ATHN-02 says such applications are often not properly configured once installed, with the default credentials provided for initial authentication and configuration never changed, and that these default credentials are well known by penetration testers and, unfortunately, also by malicious attackers.
For checking that the known usernames and passwords for an application do not result in successful authentication, it says a tester can consult the manufacturer's documentation, among other ways.
It says the root cause of the problem can be identified as four things: inexperienced IT personnel who are unaware of the importance of changing default passwords on installed infrastructure components, or who leave the password as default for ease of maintenance; programmers who leave back doors to easily access and test their application and later forget to remove them; applications with built-in, non-removable default accounts with a preset username and password; and applications that do not force the user to change the default credentials after the first log in.
ASVS 5.0 covers two kinds of account. Requirement 6.3.2, at Level 1, asks that default user accounts are not present in the application or are disabled. Requirement 13.2.3, at Level 2, covers the accounts that components use to reach each other: if a credential has to be used for service authentication, the credential the consumer uses is not a default credential.
Check this from the inside first. WSTG-ATHN-02's steps for a review with inside knowledge include asking whether default passwords are changed and default user accounts are disabled, and examining the user database for default credentials and empty password fields. If you also try a first-run account from outside, try only the one your product's own installation guide names, once, on your own installation: the same page notes that multiple password guess attempts with a known username may cause the account to be locked.
Sample content is the same mistake in file form. WSTG-CONF-02 says the typical web and application server installation contains a lot of functionality, such as application examples, documentation and test pages, and that what is not essential should be removed before deployment to avoid post-install exploitation.
A directory listing is a web server's answer to a request for a folder that has no index page: instead of an error, a list of every file in it. nginx's documentation for its autoindex module says the module processes requests ending with the slash character and produces a directory listing, and gives the default as autoindex off.
Apache HTTP Server 2.4's documentation says that with the Indexes option, a request for a URL that maps to a directory with no DirectoryIndex file, such as index.html, gets a formatted listing of the directory from mod_autoindex. It gives the default as Options FollowSymlinks, records that the default was changed from All to FollowSymlinks in version 2.3.11, and defines All as all options except MultiViews.
On this page's reading, a configuration that sets Options All or Indexes itself, perhaps because it was written before that change and carried forward, still lists folders.
A listing matters for what it leads to. In A02's second scenario, directory listing is not disabled on the server, an attacker lists directories, finds and downloads the compiled Java classes, decompiles them to view the code, and then finds a severe access control flaw in the application.
Turning listings off, as ASVS 5.0 requirement 13.4.3 asks unless a listing is explicitly intended, removes the index. It does not remove the files, and a file with a guessable name is still served to anyone who asks for it by name.
WSTG-ERRH-01 lists stack traces among the forms an application's errors take. What a visitor sees when one happens is a setting. The Express 5.x error handling guide says that an error passed to next() and not handled in a custom error handler is handled by the built-in error handler and written to the client with the stack trace, that the stack trace is not included in the production environment, and that the app runs in production mode when the environment variable NODE_ENV is set to production.
Put that beside the default from the previous section.
On this page's reading of the two documents together, an Express app that relies on the built-in handler, on a host where NODE_ENV was never set, writes its stack traces to visitors.
Next.js draws the same line inside the framework. Its documentation for the error file says that during development the Error object forwarded to the client is serialised and includes the message of the original error for easier debugging, and that the behaviour is different in production, to avoid leaking potentially sensitive details: errors forwarded from Server Components show a generic message with an identifier, which can be used to match the corresponding server-side logs.
That is the shape ASVS 5.0 asks for. Requirement 16.5.1, at Level 2, is that a generic message is returned to the consumer when an unexpected or security-sensitive error occurs, with no exposure of sensitive internal system data such as stack traces, queries, secret keys and tokens.
Requirement 16.5.4, at Level 3, adds a "last resort" error handler that catches all unhandled exceptions, both to avoid losing error details that must go to log files and so that an error does not take down the entire application process.
A02's third scenario is an application server whose configuration allows detailed error messages, such as stack traces, to be returned to users, which it says potentially exposes sensitive information or underlying flaws, such as component versions that are known to be vulnerable.
The lab's app has a real fault on one route: an unknown booking id makes it read a property of undefined. With errorDetail set to stack-trace, the answer was the error and six lines of stack trace, three of them naming functions, files and line numbers in the application.
With generic-message, the same fault returned one line with a reference, and the stack trace went to a log under that reference. The fault was identical both times. Only the setting differed.
An admin interface is where accounts are created, content is changed and settings are edited. WSTG-CONF-05 says that in many instances such interfaces do not have sufficient controls to protect them from unauthorised access. For a review with inside knowledge, it describes hardening as administrator pages that are not accessible to everyone, through the use of IP filtering or other controls, and adds, where applicable, verifying that components do not use default credentials or configurations.
Whether an interface can be reached at all can come down to one argument. Node.js v26.13.1's documentation for server.listen() says that if the host is omitted, the server accepts connections on the unspecified IPv6 address when IPv6 is available, or the unspecified IPv4 address otherwise.
On this page's reading, an admin tool or internal dashboard started that way on a server with a public address is listening on that address too, and only a firewall or the host's network rules stand between it and the internet.
Keep two questions apart in the worksheet: who can reach the page, and who can use it once they have. The lab's careful production file answers a request for /admin with 401 unless the request carries the operator's token, and the regression test also confirms that an operator who sends the token still gets the page, so the restriction has not simply locked everyone out.
Anything that is running and not needed is surface that nobody is watching. A02's prevention list asks for a minimal platform without any unnecessary features, components, documentation or samples: remove or do not install unused features and frameworks. WSTG-CONF-01 says a list of defined ports which are required for the application should be maintained and kept under change control.
WSTG-CONF-02 says to enable only the server modules that are needed for the application, which it says reduces the attack surface and keeps vulnerabilities that might appear in the vendor's software from affecting the site if they are only present in modules that have already been disabled.
ASVS 5.0 asks for the same kind of record at the level of the whole application: requirement 13.1.1, at Level 2, is that all communication needs for the application are documented, including the external services which the application relies upon.
HTTP methods are services too. WSTG-CONF-06 says most web applications only need to respond to GET and POST requests, and describes TRACE as a method intended for testing and debugging that instructs the web server to reflect the received message back to the client.
ASVS 5.0 requirement 13.4.4 asks that it is not supported in production. Apache HTTP Server 2.4's documentation gives the default as TraceEnable on and says TraceEnable off makes the core server and mod_proxy return a 405 (Method not allowed) error to the client.
The sources do not agree on how much TRACE matters. A note in Apache's documentation says that, despite claims to the contrary, enabling the TRACE method does not expose any security vulnerability in Apache httpd, and that the TRACE method is defined by the HTTP/1.1 specification and implementations are expected to support it.
WSTG-CONF-06 says the method, while apparently harmless, can be successfully leveraged in some scenarios to steal legitimate users' credentials. On the attack itself, cross-site tracing, it says that in older browsers attacks were pulled using XHR technology, which leaked the headers the server reflected and bypassed security measures such as the HttpOnly attribute, and that this attack can be pulled in recent browsers only if the application integrates with technologies similar to Flash.
The worksheet records the ASVS value as the expected one and leaves the decision, with its reason, to the row's owner.
Status pages, metrics endpoints and API documentation are built for the team, and ASVS 5.0 requirement 13.4.5 asks that they are not exposed unless explicitly intended. Apache's mod_status shows what such a page holds. Among the details its documentation lists are the number of workers serving requests, the time the server was started and, with ExtendedStatus on, the current hosts and requests being processed.
The documentation's own example enables the page inside a Location block with a Require host rule, so that only browsers from one domain receive status reports.
WSTG-CONF-02, discussing sensitive information in logs, gives the well-known server-status misconfiguration in Apache-based HTTP servers as an example of how an attacker might obtain the logs.
MDN's glossary describes a source map as a JSON file format that maps between minified or transformed code received by the browser and its original unmodified form, allowing the original code to be reconstructed and used when debugging. Next.js's documentation, in the version its site labelled Latest (v16.4.6) on 14 November 2026, says source maps are enabled by default during development and disabled during production builds, to prevent you leaking your source on the client, unless you opt in with the productionBrowserSourceMaps configuration flag.
With the flag enabled, it says, the source maps are output in the same directory as the JavaScript files and Next.js serves them automatically when requested.
The lab's map carries the original file with its comments, which the built file did not. This row of the worksheet asks only whether a map is served, and whether that was a decision.
Cloud storage has no folder on a web server to forget about. Whether the whole internet can read it is a permission. A02 lists improperly configured permissions on cloud services among its signs, tells teams to review cloud storage permissions, with S3 bucket permissions as its example, and describes in its fourth scenario a cloud service provider that defaults to having sharing permissions open to the internet, which allows sensitive data stored within cloud storage to be accessed.
WSTG-CONF-11 says improper access control configuration may result in sensitive information exposure, data being tampered with, or unauthorised access.
For one provider the default points the other way, which shows where the exposure comes from. Amazon's S3 User Guide says that by default, new buckets, access points and objects do not allow public access, but that users can modify bucket policies, access point policies or object permissions to allow it.
Its Block Public Access feature provides four settings that override those policies and permissions, each of which can be applied to an access point, a bucket or an entire AWS account, and Amazon recommends turning on all four for the account to help ensure that public access is blocked.
It additionally recommends turning on all four for each bucket, to comply with AWS Security Hub Foundational Security Best Practices control S3.8. On this page's reading, an S3 bucket created under those defaults is public because someone changed a policy or a permission: for a launch, a test or a one-off file transfer.
That is drift, and the worksheet treats it as such. This describes Amazon S3 only. Read your own provider's documentation for its defaults.
The lab's storage folder stands in for a bucket. With storageAccess set to public-read, a request with no credentials received the bookings export. With private, the same request received 403.
A02's last sign is a server that does not send security headers or directives, or does not set them to secure values. The drift version is a header that is set, but by one layer only, so it is missing whenever another layer answers.
ASVS 5.0 is explicit about the scope in requirement 3.4.4, at Level 2: all HTTP responses contain an X-Content-Type-Options: nosniff header field. Apache HTTP Server 2.4's mod_headers documentation draws the same line in its own terms: the Header directive's condition is onsuccess, the default, or always, and when a header is added to a locally generated non-success response, such as a redirect, only the always table is used in the final response.
The lab uses that one header as a stand-in for the rest. Its development file sets the header on successful responses only, and the probe's request for a page that does not exist came back without it.
How to find drift: compare what you intended with what is running
Drift is a difference, so finding it takes two things to compare.
The running system is one. The other is a written statement of what production is supposed to be, and that is the one to create first.
- Write down the intended production value of every setting that changes what a stranger can reach. The worksheet's ten rows are a starting list. In the lab this is one file, expected-production.json, with a value and an owner for each setting.
- Compare each environment's configuration with it. The lab's drift-check.mjs does this for its three files and reports every difference. On the careless production file it reported six, each with the owner to ask.
- Decide each difference. In development and staging, a difference can be accepted in writing, with a reason. In production it is drift by definition, because the expected values describe production. A difference nobody can explain is a finding.
- Look from outside. Request the observable items from the running system and compare the answers with what the intended settings would give. The lab's probe.mjs does this for all three instances.
- Fix the setting where it is defined, restart or redeploy whatever read it, and look from outside again.
Why the last step is not a formality
In the recorded run, the production file was replaced with the careful version and the file comparison reported no drift. The regression test, run straight afterwards, still failed six checks, all of them against the running instance: it had loaded the careless settings when it started and was still serving them.
Only after the instance was restarted did the outside checks pass. A review that had stopped at the file would have passed a production system that still had a public debug page.
What an accepted difference costs
An accepted difference in staging is a behaviour that staging can no longer vouch for. The lab's staging file keeps its status endpoint public, with a written reason, so nothing tested there says whether production's status endpoint is closed. Only the production check does. Keep the list of accepted differences short for that reason, and read it before trusting a result from staging.
Keep each setting in one reviewed place
A value that lives in a dashboard, in an environment variable on one server, in a line of a deploy script and in a default in the code has no single answer to the question of what it is supposed to be, and no moment at which a second person sees it change.
This is the page's own advice rather than a quotation: give every setting that affects exposure one home that goes through review, such as a configuration file in the repository or an infrastructure definition, and have each environment's value come from it.
Two framework documents show a production value kept in a file. Django's deployment checklist describes publishing suitable settings for development and using a private settings module for production as a common practice when a project's source code is released, and says to run its automated check, the check --deploy option, against the production settings file.
Express's production guidance says environment variables are typically set in an interactive shell in development, but that in general you should not do that on a production server and should use the operating system's init system instead; its example puts NODE_ENV=production in a systemd unit file.
On this page's reading, a value kept in a file that way can be read, compared and reviewed.
- Secrets are the exception to "in the repository": the value stays in the host's secrets store, and the reviewed file only names it. A02's prevention list ends with a related item: use identity federation, short-lived credentials or role-based access mechanisms provided by the underlying platform instead of embedding static keys or secrets in code, configuration files or pipelines.
- Give each setting an owner, by role. The lab's expected-production.json names one for every setting, and the drift report prints it in its first table and again beside each difference that has no written acceptance.
- Send emergency changes through the same file afterwards. If production was changed directly during an incident, the incident is not closed until the file says the same thing or production has been changed back.
- Have the application refuse to guess. The lab's app stops when it starts if a setting is missing or has a value it does not know. In two separate trials, a file with a setting left out and a file with an unknown value each ended with an error naming the setting and exit code 1. Those two trials are not part of the recorded run the asset shows. A typing error in a setting's name then cannot quietly become a permissive default.
Check from outside as well as from the configuration
A configuration review reads what the settings say.
An outside check reads what the system does. They fail in different ways, so use both: the file can be right while the process is stale, a proxy or CDN in front can answer instead of the application, and a layer nobody thought to read can override the setting.
Run these checks only against hostnames you own or are authorised in writing to test, one request at a time, from a private browser window or a command-line HTTP client. Each line gives the answer a correctly configured server returns. The list is for checking your own property. It is not a method for finding other people's systems.
- A debug or diagnostic path that your developer names: an error such as 404, with no settings, environment values or version details in the body.
- A folder URL with no index page, such as an uploads or assets folder, ending in a slash: an error such as 403 or 404, and no list of file names.
- A URL with a malformed value, such as letters where the application expects a number: a plain error page, with no stack trace, file path, query text or framework name.
- Each admin path, requested from a network that is not your office or VPN, such as a phone on mobile data: no answer at all, or a sign-in page and nothing else.
- The address of a stored file that should be private, opened while signed out: an access-denied error, not the file.
- Your status, metrics and API documentation paths: an error, or only what you decided to publish.
- The address of your main JavaScript file with .map added: an error such as 404, unless you chose to publish source maps.
- A page that exists, a page that does not and an address that redirects, on each hostname: the same security headers on all three.
Read the body, and know what the check cannot tell you
Read the body as well as the status code. A page can answer 200 and show an error, and a custom error page can hide what the server underneath would have said. Keep each request, its answer and the date, because that record is the evidence column of the worksheet.
An outside check sees only the paths you tried, on the day you tried them, from the network you were on. It says nothing about a path nobody thought of or a setting that changes tomorrow, which is why the configuration comparison and the release check sit beside it.
Keep it checked after every release
A setting that was right at launch stays right only until the next change.
A02 asks for an automated process to verify the effectiveness of the configurations and settings in all environments, and says that where these verifications are not automated, they should still be carried out at least once a year.
The cheapest automation is a test that runs in the release pipeline. The lab's drift.test.mjs has twenty-one checks: ten read the production file against the expected values, ten ask the running production instance for the observable items, and one confirms that an operator can still reach the admin page.
Node.js's documentation says that if any tests fail, the process exit code is set to 1. A pipeline step that treats a non-zero exit code as a failure then stops the release.
On the careless configuration, twelve checks failed. After the file was fixed, six still failed until the instance was restarted. Then all twenty-one passed.
- Before a release: the file comparison, against the production values the release will ship with.
- After a release: the outside checks, against the live hostnames, once the new version is the one answering.
- After any incident in which production was changed directly: both, before the incident is closed.
- When a host, CDN, framework or server version changes: the defaults you rely on, because a default can change between versions. Apache's Options default did, in 2.3.11.
- Where the framework has a check of its own, run it too. Django's documentation says some of its deployment checks can be automated with the check --deploy option, run against the production settings file.
What a test like this cannot do
It proves the settings it knows about. It does not find the setting nobody listed, which is why the worksheet has an owner for every row and why a new feature that changes what a stranger can reach adds a row before it ships.
Running the drift lab on your own machine
The lab on this page is an illustration: one invented application, Fixture Bookings, started three ways from three configuration files, with ten settings that follow the worksheet's ten rows.
It shows how to compare settings and how to look from outside. It does not show how any real framework behaves, and its debug page, listing and error output are the lab's own.
Apart from each other, the scripts import only modules whose names begin with node: and the lab installs no packages. Every instance is an HTTP server that listens on 127.0.0.1 and asks for port 0. Node.js's documentation says the HTTP server's listen() is identical to the one in its net module, where port 0 makes the operating system assign an arbitrary unused port.
The one account in the lab, setup-admin, has an invented password that is no product's default. The recorded run was made on Node.js 26.0.0 on macOS, the only version and the only system it was run on.
- Steps 1 and 2 put the careless version in place as the production file and start three instances.
- Step 3, the file comparison: ten accepted differences in development, one in staging and six with no acceptance in production, so the script exits with code 1.
- Step 4, the probe: development answers differ from the intended production answer in all ten rows, staging in one and production in six.
- Steps 5 and 6 print two production answers in full: the debug page, which lists every running setting, and the stack trace from the faulty route, with three lines cut on this page because they hold local file paths.
- Step 7, the regression test: twelve of twenty-one checks fail.
- Steps 8 to 10 replace the production file with the careful version. The file comparison passes and the test still fails six checks, because the running instance has not been restarted.
- Steps 11 to 14 restart the production instance. All ten of its answers are then the intended ones, the faulty route returns one line with a reference, and all twenty-one checks pass.
- Step 15 stops each instance by the process id it recorded when it started.
Pointing it at your own application
The files are small enough to adapt. Replace expected-production.json with your worksheet's rows, have drift-check.mjs read your own configuration files or an export of your host's environment settings, and rewrite observations.mjs so that each request goes to a hostname you own and each answer is read for the sign that matters on your stack. Keep the default-account observation pointed at a test installation, not at production.
Neighbouring guides, and where a Clever Ops check fits
Five pages in this library take the questions next to this one.
The sensitive data exposure guide covers personal and business data that a page, an API response, an export or a log gives to the wrong person. The secrets exposure guide covers API keys and other credentials in source, history, browser bundles and logs, and environment files or .git folders that a web server hands out.
The subdomain takeover guide covers DNS records left pointing at services you no longer hold.
The cookie security guide covers each Set-Cookie attribute and how to choose it. The website security audit page sets out the twelve checks Clever Ops runs on a live site from outside.
Clever Ops does not monitor sites and does not respond to incidents. If a misconfiguration has already been used against you, start with an incident response specialist. What Clever Ops offers is a check at a point in time, and each report records what was checked, on which hostnames and on which dates. A setting changed the day after is outside what the report can speak to.
- The website security check looks from outside, without signing in. Among its twelve checks are hidden administrator interfaces and staging copies, old, backup and unreferenced files at paths the server will serve, the software versions a site reveals, the headers each hostname sends, and what error pages and debug output give away. It finds login screens but does not sign in or guess passwords, so default accounts are a check to make from the inside.
- A web application and API penetration test adds the signed-in view. With read-only access to the code, its review can include checking production settings for debug modes against ASVS 5.0 requirement 13.4.2.
- Internal networks are outside these services, and Clever Ops refers that work to a network specialist.
- If Clever Ops built or hosts the site, the work is a security review rather than an independent test, and the report says who built it and who hosts it.
Frequently asked questions
It is a weakness that comes from a setting rather than from the code: debug mode left on, a default account still active, a folder that lists its files, or an admin page or storage bucket open to everyone. OWASP's Top 10:2025 defines it as a system, application or cloud service that is set up incorrectly from a security perspective, and lists it as A02, the second of its ten categories.
This guide works through ten: debug mode and debug routes, default accounts and sample content, directory listings, storage that is public by setting, verbose error output, admin interfaces reachable from the internet, unneeded services and HTTP methods, exposed monitoring or documentation endpoints, source maps served in production, and security headers set in one layer only. Each is a row in the worksheet on this page.
Because debug mode tells whoever makes the request what it was built to tell the developer. Django's documentation says its debug page shows a detailed traceback and metadata such as the currently defined settings, and that file paths, configuration options and the like all give attackers extra information about the server. ASVS 5.0 requirement 13.4.2 asks that debug modes are disabled for all components in production environments.
Start from the inside: compare the user list of each admin interface and database with the built-in accounts the product's documentation names, and look for empty password fields. If you also test from outside, try only the first-run account your product's own installation guide names, once, on your own installation. The OWASP testing guide warns that repeated guesses against a known user name may lock the account.
Anything enabled or listening that the application does not need: an open port, a server module, a sample application, a status page or an HTTP method such as TRACE. The OWASP testing guide says a list of the ports the application requires should be maintained and kept under change control, which gives you something to compare the running system with.
It is a cloud service or its storage set up so that more people can reach it than you intended. OWASP's Top 10:2025 lists improperly configured permissions on cloud services among the signs that an application might be vulnerable under A02, Security Misconfiguration. Amazon's S3 User Guide says new buckets, access points and objects do not allow public access by default, but that users can modify policies or permissions to allow it, and Amazon recommends turning on all four Block Public Access settings for the account. Check from outside by opening a private file's address while signed out.
On every release, by a test that fails the release when a production setting differs from its intended value, and again from outside once the release is live. OWASP's Top 10:2025 asks for an automated process to verify configurations and settings in all environments, and says that where the verification is not automated it should still be done at least once a year.
It finds what shows from outside without signing in: admin screens and staging copies, leftover files at paths the server serves, visible software versions, the headers each hostname sends and what error pages reveal. It does not sign in or guess passwords, and it works with no source code and no admin access, so default accounts, storage policies and server settings still need the inside comparison this guide describes.
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.