feat(security): make CSP upgrade-insecure-requests configurable (#611)#612
Merged
Merged
Conversation
The CSP `upgrade-insecure-requests` directive was hardcoded on in production, which makes the browser force the dashboard to https. On a trusted private-network deployment intentionally serving HTTP only, that leaves the dashboard unreachable. Add CSP_UPGRADE_INSECURE_REQUESTS: unset keeps the legacy default (on in production, off elsewhere); 'false' opts out; 'true' forces it on. Resolved by a pure isUpgradeInsecureRequestsEnabled helper alongside the other bootstrap-security env gates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #611.
Summary
The CSP
upgrade-insecure-requestsdirective was hardcoded on wheneverNODE_ENV=production, so browsers auto-upgrade every dashboard request from HTTP to HTTPS. That is correct for Internet-facing TLS deployments, but a production instance intentionally served over HTTP on a trusted private network (TLS terminated elsewhere, or not required) becomes unreachable from the browser — the request tohttp://server:2785is silently rewritten tohttps://server:2785.Change
A new
CSP_UPGRADE_INSECURE_REQUESTSenvironment variable controls the directive, resolved by a pureisUpgradeInsecureRequestsEnabledhelper next to the otherbootstrap-securityenv gates:falsetrueNODE_ENVBackward compatible: the default is unchanged, so existing deployments are unaffected. The REST API was never affected; this only concerns the browser dashboard.
Tests
Unit tests for the resolver cover the legacy default per
NODE_ENV, the explicit override in both directions, and non-true/falsevalues falling back to the default. Full backend suite green (1906 tests); lint and build clean..env.exampledocuments the flag.