Skip to content

Response headers, HSTS and error pages Since v0.1 ​

Header protection edits the answers the application sends. It adds the security headers the application forgot, sends HSTS on HTTPS answers, removes headers that reveal software versions, and replaces upstream error pages with a page that carries the event reference.

Before you begin ​

  • Role: operator for the application (viewer can read the settings and the posture).
  • HSTS and Secure need the application on an HTTPS listener.
  • Response bodies are read only when a protection needs them (today: error excerpts and data leak checks).

See what the application sends first ​

Turn header protection on in detect mode. Nothing changes. The Posture tab lists, per content type (html, json, other), which security headers the application sends, in what share of answers, an example value, what the policy would add or remove, and the recommended headers it never sends. Each event's trace lists what would change.

text
1. Open Applications > All applications > the application > Response checks > Response headers.
2. On the Security headers tab, set Protection mode to detect, then select Preview changes and Apply.
3. Open the Posture tab.
sh
waap headers set -app shop -m "header posture" mode=detect
waap headers posture -app shop -window 7d
yaml
# applications[].policy.headers
headers:
  mode: detect

Enforce ​

Set mode=block, or leave it empty to follow the application. The preset decides the headers added. Header entries override the preset, and a header the application already sends is kept unless the entry says always.

PresetAdds
nonenothing
baseline (default)X-Content-Type-Options, Referrer-Policy, X-Frame-Options and Cross-Origin-Opener-Policy on HTML (frame options only when the page's CSP has no frame-ancestors)
strictthe baseline plus a report-only CSP, Cross-Origin-Resource-Policy and a restrictive Permissions-Policy, and removes X-XSS-Protection
text
1. On the Security headers tab, choose the Preset (or select the recommended one from the Posture tab).
2. Set Protection mode to block.
3. Select Preview changes, then Apply.
sh
waap headers presets
waap headers set -app shop -m "enforce headers" mode=block preset=baseline
yaml
headers:
  mode: block
  preset: baseline

Add your own headers ​

Each entry has a name, a value, when to apply it and optional content types.

text
1. On the Security headers tab, open the header entries and add one: name, value, When, content types.
2. Select Preview changes, then Apply.
sh
waap headers list set -app shop -list set -f headers.yaml -m "own headers"
yaml
# policy.headers.set
- name: Permissions-Policy
  value: "camera=()"
  when: always
- name: X-Debug
  when: remove

Reserved headers

Protocol headers, cookies, CORS answers and HSTS cannot be set here: Content-Length, Content-Type, Content-Encoding, Transfer-Encoding, Connection, Keep-Alive, Upgrade, Trailer, Te, Location, Set-Cookie, Strict-Transport-Security, Date, Access-Control-Allow-Origin and Access-Control-Allow-Credentials.

Set HSTS ​

HSTS is sent on answers to HTTPS requests only. An application that sends its own keeps it.

text
1. On the Security headers tab, open the HSTS group.
2. Set Max age, Include subdomains and Preload, then select Preview changes and Apply.
sh
waap headers set -app shop -m "hsts" hsts.max_age=8760h hsts.include_subdomains=true
yaml
headers:
  hsts: {enabled: true, max_age: 8760h, include_subdomains: true}

Subdomains and preload

Turn on Include subdomains only when every subdomain serves HTTPS. Preload needs Include subdomains and a max age of at least a year, and browsers are slow to forget it.

Replace error pages ​

The upstream's error answers are replaced by the application's error page with the event reference. API clients that ask for JSON get {"error": ..., "reference": ...}. To keep the real error visible to operators, turn on Keep an excerpt: the event (rule headers.error.cloaked, one per path and status per minute) holds an excerpt of the upstream's body, in full when logging is unmasked and masked under pci.

text
1. Open Response checks > Response headers, Error pages tab.
2. Turn on Replace error pages and set Statuses, Status sent and Paths not replaced.
3. To use your own page, upload it there. Select Preview changes, then Apply.
sh
waap headers set -app shop -m "error pages" errors.enabled=true errors.statuses=5xx,404 errors.skip=/healthz
waap pages set -app shop -kind error -m "own error page" -f error.html
yaml
headers:
  errors: {enabled: true, statuses: ["5xx", "404"], skip: ["/healthz"], capture: true}

Block pages, challenge pages and error pages carry the same security headers and HSTS when header protection is in block mode. Their own Content-Security-Policy stays.

Collect CSP reports ​

With Collect CSP violation reports, the answers' CSP points at /.waap/csp-report, answered by inspection and never the upstream. Reports appear on the Posture tab: directive, blocked origin (never its path or query) and page. Use them to see what a CSP would break before you enforce it. Start with the strict preset's report-only CSP.

Control response bodies and compression ​

text
1. Open Response checks > Response headers, Response bodies tab.
2. Set Body inspected, Content types, Paths never read and Compress answers.
3. Select Preview changes, then Apply.
sh
waap response get -app shop
waap response set -app shop -m "bodies" max_body=2MiB compress=true
yaml
# applications[].policy.response
response:
  max_body: 2MiB
  skip: ["/static/*"]
  compress: true

A longer body is inspected in part, and the event says so. Compress answers lets the data plane compress answers (brotli, gzip) after inspection when the upstream did not. It turns on by itself for protections that read bodies.

Settings reference ​

General and HSTS ​

SettingWhat it doesDefaultAllowed valuesApplies in
Header protection (policy.headers.enabled)Adds headers, HSTS and removes version headers. Off keeps the settings.truetrue, falseall
Protection mode (mode)detect changes nothing and shows what would change.empty (same as the application)detect, block, emptydetect wins
Preset (preset)The built-in header set.baselinenone, baseline, strictblock mode
Collect CSP violation reports (csp_reports)Points CSP reports at inspection and shows them on the Posture tab.falsetrue, falseall
Send HSTS (hsts.enabled)Strict-Transport-Security on HTTPS answers.truetrue, falseblock mode, HTTPS
Max age (hsts.max_age)How long browsers use HTTPS only.8760h5m to 17520hHSTS on
Include subdomains (hsts.include_subdomains)Applies to every subdomain too.falsetrue, falseHSTS on
Preload (hsts.preload)Marks the host for browser preload lists.falsetrue, falseneeds include subdomains and a max age of a year or more

Removed headers and error pages ​

SettingWhat it doesDefaultAllowed valuesApplies in
Remove version headers (remove_banners)Removes Server, X-Powered-By, X-AspNet-Version, X-AspNetMvc-Version, X-Generator.truetrue, falseblock mode
Also remove (remove)More header names to remove.noneheader namesblock mode
Replace error pages (errors.enabled)Replaces the upstream's error answers.falsetrue, falseblock mode
Statuses (errors.statuses)Statuses replaced.5xx4xx, 5xx or single statuses such as 404errors on
Status sent (errors.status)The status of the replacing answer.keepkeep, 500, 502, 503errors on
Paths not replaced (errors.skip)Paths whose errors pass (health checks).noneexact or prefix ending in *errors on
Keep an excerpt (errors.capture)Reads the upstream's error body and keeps an excerpt in the event.falsetrue, falseerrors on

Header entry ​

SettingWhat it doesDefaultAllowed valuesApplies in
nameThe header.none (required)not a reserved headerall
valueThe value to send.nonetextnot with when: remove
whenmissing adds it only when absent, always replaces, remove deletes.missingmissing, always, removeblock mode
content_typesLimits the entry to these types.all typesmedia typesall

Response bodies ​

SettingWhat it doesDefaultAllowed valuesApplies in
Body inspected (policy.response.max_body)Most bytes of a body read.1MiBup to 16MiBmodules that read bodies
Content types (content_types)Types whose bodies may be read (+json matches any type ending in it).text/html, text/plain, text/csv, application/json, application/xml, text/xml, +json, +xmlmedia typesall
Paths never read (skip)Answers never read (static assets).noneexact or prefix ending in *all
Compress answers (compress)The data plane compresses answers after inspection.falsetrue, falseall; on automatically when a module reads bodies

Limits ​

LimitValue
Header entries64
Response body read1 MiB default, 16 MiB at most
CSP reports16 KiB each, 30 per client per minute
Metricswaap_response_edits_total{app,module,kind}, waap_response_bodies_total{app,result}

Troubleshooting ​

A header is not added ​

  • Cause: the mode is detect, the application already sends it (when: missing), or the entry's content type does not match.
  • Check: the event trace lists what would change.
  • Fix: set mode=block, use when: always to replace, or fix the content types.

Users cannot reach a subdomain after enabling HSTS ​

  • Cause: Include subdomains applies HTTPS-only to subdomains that do not serve HTTPS.
  • Fix: serve HTTPS everywhere, then turn it on; browsers keep HSTS until the max age ends.