Fraud Prevention Headers


HMRC fraud-prevention headers are assembled for outbound requests by buildFraudPreventionHeaders. Browser observations are validated at the same-origin route boundary; network and identity values are derived server-side.


Client headers

client/fraud/clientData.ts collects browser observations for:

  • Gov-Client-Connection-Method
  • Gov-Client-Browser-JS-User-Agent
  • Gov-Client-Device-ID
  • Gov-Client-Screens
  • Gov-Client-Timezone
  • Gov-Client-Window-Size

The same-origin routes validate browser observations against an allowlist and reject extra fields, malformed values, and header-injection characters. The server sets Gov-Client-Connection-Method to WEB_APP_VIA_SERVER rather than accepting the browser's value. Gov-Client-User-IDs is built from the login email (when present) and Auth0 subject in the server session; browser-submitted identities are rejected. Gov-Client-Multi-Factor is not accepted from the browser because it describes authentication performed by the application; it remains omitted until the app can derive the factor evidence from a trusted authentication event.



Vendor headers

The application is intended to receive inbound traffic through the Raspberry Pi reverse proxy. The code does not assume Vercel headers or trust arbitrary X-Forwarded-For/X-Real-IP values. It reads the client IP and public port only from the header names explicitly configured as HMRC_CLIENT_PUBLIC_IP_HEADER and HMRC_CLIENT_PUBLIC_PORT_HEADER. Configure these only after verifying that the Pi proxy overwrites those headers with the actual originating values; do not use a client-supplied or append-only forwarded value. The IP is syntax-checked, the public port is range-checked and excludes 80/443, and the timestamp is generated server-side. If the names are unset or the values are invalid, the corresponding headers are omitted rather than replaced with browser data or placeholders.

SERVER_PUBLIC_IP must be set to the public IP address of the Pi endpoint that receives the browser connection. Given the stated single reverse-proxy ingress, the helper reports one vendor hop (by=<Pi public IP>&for=<client public IP>). Confirm that there are no other vendor-controlled TLS-terminating hops before relying on this chain. The helper does not use a public IP lookup service as a substitute for the configured ingress address. The IP diagnostic endpoint's IP-lookup result is reference information only; it is not used as an HMRC header value.

The server helper adds:

  • Gov-Vendor-Forwarded and Gov-Vendor-Public-IP, based on the configured Pi public IP and the proxy-derived client IP.
  • Gov-Vendor-License-IDs, built from the configured application name and licence key.
  • Gov-Vendor-Product-Name and Gov-Vendor-Version, built from the configured application name.

Unset proxy-header settings intentionally cause network-derived headers to be omitted. This is safe against spoofing but is not evidence that the resulting request satisfies HMRC's fraud-prevention requirements. HMRC says that missing required data should be discussed with HMRC; do not use this configuration in Production without verifying the Pi header behavior, setting the deployment values, and checking all resulting Sandbox header feedback.



Validation and safeguards

POST /api/hmrc/fraud/test sends the generated headers to HMRC Sandbox's GET /test/fraud-prevention-headers/validate endpoint. It validates the fraud-prevention headers attached to that same request. Use its feedback during integration, but treat it as a test of the submitted request, not a general compliance certification. This Sandbox support endpoint does not establish Production compliance.

The current implementation and its tests guard against client-submitted network addresses, ports, timestamps, and user IDs. The operator confirmed the Pi app listens on 127.0.0.1:3000, port 3000 router forwarding is removed, NGINX sets X-Real-IP to $remote_addr, and the configured server IP matches the current public WAN IP. On the reported Pi test, the client IP matched and the Sandbox validator reported a missing client public port and an MFA warning. This validates only that request; it does not verify each outbound operation or establish Production compliance. Do not log access tokens or unnecessary taxpayer data.

Remaining Raspberry Pi and Sandbox checks

  1. Keep the confirmed loopback binding, disabled port 3000 forwarding, and NGINX X-Real-IP configuration in place. Recheck them when the deployment or proxy path changes.
  2. Keep SERVER_PUBLIC_IP synchronized with the Pi's public ingress IP. Updating DNS alone does not update the application environment. Review the PM2 deployment configuration after any address change; restart or reload it according to that configuration and confirm the application is healthy.
  3. Do not set HMRC_CLIENT_PUBLIC_PORT_HEADER to a guessed, fixed, browser-local, or destination port. The earlier hotspot comparison did not establish whether source-port translation occurred. Investigate the actual path and discuss the missing header with HMRC if a trustworthy public client port cannot be obtained.
  4. On an allowlisted test account, use Validate fraud-prevention headers on the testing page through the public HTTPS address. Inspect both the response body and the header diagnostics: HTTP 200 alone does not mean the headers are valid. Do not share the header table publicly; it can contain personal and network information.
  5. Test the actual supported HMRC Sandbox operations and use HMRC's Test Fraud Prevention Headers API validation-feedback endpoint for feedback on the last request to each endpoint. The app currently exposes the single-request validator, not a validation-feedback screen. Resolve errors and review warnings with HMRC. HMRC says not to send it logs from this API; it can inspect the most recent Sandbox submissions.

MFA is omitted until trusted authentication evidence is available. The previously reported single-factor arrangement and HMRC discussion do not establish that an empty or fabricated MFA value should be sent.

Please select your cookie options:

For more information regarding the cookies we use, please see our Cookie Policy.