Skip to content

fix(proxy): add includeSubDomains to the Strict-Transport-Security header - #4116

Merged
asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/865-hsts-include-subdomains
Nov 25, 2026
Merged

asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/865-hsts-include-subdomains

Conversation

@asaah262

Copy link
Copy Markdown
Contributor

Description

The proxy sets the Strict-Transport-Security header on responses to HTTPS requests. It had max-age and preload, but not includeSubDomains. It now sends:

Strict-Transport-Security: max-age=315360000; includeSubDomains; preload

With includeSubDomains, a browser that has seen the header also uses only HTTPS for all subdomains of the OpenCloud host, e.g. *.cloud.example.com for cloud.example.com. Other hosts of the same domain, such as office.example.com, are not affected.

Nothing else changes:

  • Responses to plain HTTP requests still get no Strict-Transport-Security header. This includes installations with PROXY_TLS=false behind a reverse proxy: X-Forwarded-Proto is not taken into account.
  • The other values of the header stay the same.

Related Issue

  • None

Motivation and Context

Without includeSubDomains, HSTS only protects the OpenCloud host itself, and a subdomain can still be reached over plain HTTP. The preload flag asks for inclusion in the browsers' HSTS preload list, which only accepts domains whose header also contains includeSubDomains. The nginx example in the documentation already sends both.

Note for installations that serve OpenCloud with PROXY_TLS=true directly on a domain whose subdomains are still served over plain HTTP: browsers that have seen the header will only use HTTPS for those subdomains, until max-age expires.

How Has This Been Tested?

  • Test environment: macOS, Go tests.
  • New Go test TestSecurityStrictTransportSecurity in services/proxy/pkg/middleware/security_test.go:
    • HTTPS request: the header is max-age=315360000; includeSubDomains; preload. This case fails without the fix: it gets max-age=315360000; preload.
    • unchanged behaviour: no header on a plain HTTP request, with and without X-Forwarded-Proto: https.
  • go test ./services/proxy/... passes, and go test -race passes for the middleware package. go vet reports nothing new compared with main. gofmt and git diff --check are clean.
  • Not run locally: golangci-lint and the acceptance tests. No acceptance test checks this header.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added

AI assistance: Claude Code (claude-opus-5-5) wrote the first draft of the code, the tests and this description; I reviewed and adjusted them.

…ader

Assisted-by: Claude Code:claude-opus-5-5
@codacy-production

codacy-production Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity

Metric Results
Complexity 5

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a2f9b5b) 95037 29290 30.82%
Head commit (b9a39ea) 95038 (+1) 29301 (+11) 30.83% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4116) 1 1 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@pbleser-oc pbleser-oc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me. The test fails without the change, and the note in the description about subdomains still on plain HTTP is what admins need to know for the release notes.

@asaah262
asaah262 merged commit f4ab619 into opencloud-eu:main Nov 25, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants