Skip to content

fix: apply configured security headers to specification routes - #141

Merged
stevehu merged 2 commits into
masterfrom
fix/specification-security-headers
Oct 28, 2026
Merged

stevehu merged 2 commits into
masterfrom
fix/specification-security-headers

Conversation

@stevehu

@stevehu stevehu commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The packaged HeaderHandler was bypassed by seven direct-response routes and the admin chain. Put header first in the packaged default/admin chains and the favicon, specification, Swagger UI, health and module routes so configured policies reach these responses.

Add an opt-in HSTS overlay for a dedicated HTTPS ingress instance. Its root-prefix response rule applies at send time, after proxy backend headers are copied, enforcing one max-age=31536000 value, no-store/nosniff and removal of X-Powered-By. It does not replace handler chains or change the packaged comma-string header settings. No includeSubDomains or preload is added.

The overlay disables HTTP, including normal sidecar egress on localhost:9080. The guide explicitly prohibits applying it to the usual co-located sidecar and recommends a separate ingress instance or trusted TLS edge. Generic HeaderHandler cannot provide TLS-only HSTS in a single dual-listener process. Defaults retain plaintext egress and do not enable HSTS.

Validation: mvn -q clean test, followed by mvn -q test after adding listener-policy/default-admin assertions: 34 tests, 0 failures, 0 errors, 9 existing skips. Five regression tests load classpath copies of the production values and overlay, initialize actual Handler/OrchestrationHandler pipelines in isolated JVMs, and load header.yml through values substitution. Existing test keystores are reused. Coverage includes favicon bytes/content type, health/spec/Swagger/admin responses, proxied success/redirect/404/500 with conflicting backend headers, default plaintext proxy access and header-first coverage of every packaged route. External authentication/token integrations are disabled only in the fixture. git diff --check passes. This is loopback handler-pipeline qualification, not a live deployment test.

Companion light-rest-4j #452 documents the consuming configuration and parses an isolated example without changing module-wide test configuration. Public response verification and partner scan closure still require deployment of the reviewed policy.

Assessment: https://github.com/networknt/networknt-doc/blob/master/src/security/partner-checkmarx-assessment-2026-10-28.md#a02

@stevehu

stevehu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Review

The core change (header on the seven direct routes plus an opt-in HTTPS-only overlay) is sound. Findings below. I read the diffs and did not run the tests or the remote builds.

Worth addressing

  • Admin-chain routes still skip header (src/main/resources/config/values.yml, ~187). /adm/server/info, /adm/logger, /adm/logger/content, /adm/shutdown, /adm/cache/{name} and both /adm/chaosmonkey routes use the admin chain, which has no header in the packaged config. Without the overlay, /adm/server/info is served without Cache-Control: no-store or nosniff. This is the same bypass class the PR fixes for the other seven routes, and /adm/modules now differs from its neighbours.
  • Overlay duplicates the full chains (config/hsts/values-overlay.yml:7). It re-declares the whole default and admin chains only to move header first. The README says they match the packaged defaults, but nothing enforces it, and merging replaces the whole handler.chains map. A later change to the packaged chains would silently drop or resurrect handlers (security, limit, sanitizer). Putting header first in the packaged chains (it is already enabled) would shrink the overlay to the server flags and the HSTS value. Failing that, add a test that the overlay chains equal the packaged chains with header moved.
  • Overlay disables plaintext HTTP (values-overlay.yml:3). The co-located app normally reaches the sidecar over the plaintext port (sidecar-http, 9080). After merging, those calls fail with connection refused, while the tcpSocket probes on the HTTPS port stay green. Please say so in the README, or keep a loopback-only HTTP listener.

Tests

  • SpecificationHstsConfigurationTest:61 puts a hand-built map into the config cache instead of loading header.yml through values. The overlay also changes header.response.update from the packaged comma string to a YAML map (the HeaderConfig deserializer does accept it), so the real substitution path is never exercised here. header.response.remove is not carried into the test config either.
  • Nothing exercises the real handler chains or a proxied response. HeaderHandler sets headers up front with put, and the proxy copies the backend's response headers over the exchange's. A backend that returns its own Strict-Transport-Security would replace the sidecar's value on the /* chain. The README defers "proxy-generated responses", but the PR text claims normal responses are covered.
  • SpecificationHstsConfigurationTest:56 reads src/main/resources/... and config/hsts/... relative to the working directory. Use basedir or the classpath.
  • The ~70-line keytool/TLS harness (:181) is copied verbatim from light-rest-4j #452, and a subprocess keytool is used although the repo ships test keystores. Consider reusing a checked-in keystore.

@stevehu

stevehu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up review of 4d99cd4. I read the diff and code; I did not run the tests or the remote builds.

Fixed

  • Admin routes: header is now first in both the default and admin chains, and the direct routes keep it explicitly.
  • Overlay no longer duplicates handler.chains; it carries only a root header.pathPrefixHeader response rule, which applies after the proxy copies backend headers.
  • Tests now run real handler pipelines in isolated JVMs and cover favicon bytes, admin routes, proxied 200/302/500/404 responses with conflicting backend headers, and a default-profile control. Config comes from the classpath, so the relative-path dependency is gone.

Skipped

  • The overlay still sets server.enableHttp: false. It is now documented as dedicated-HTTPS-ingress only, which I accept, but it remains a footgun if merged into a co-located sidecar.

Not verified

  • I did not read HstsApplicationFixture, so I have not confirmed it loads header.yml through values substitution as the README states.

@stevehu
stevehu merged commit f54c5c2 into master Oct 28, 2026
3 checks passed
@stevehu
stevehu deleted the fix/specification-security-headers branch October 28, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant