Skip to content

fix(proxy): redirect to HTTPS on the host of OC_URL - #4120

Merged
pbleser-oc merged 1 commit into
opencloud-eu:mainfrom
pbleser-oc:fix/867-https-redirect-trusted-host
Nov 25, 2026
Merged

pbleser-oc merged 1 commit into
opencloud-eu:mainfrom
pbleser-oc:fix/867-https-redirect-trusted-host

Conversation

@pbleser-oc

Copy link
Copy Markdown
Member

Description

The proxy redirects requests that a reverse proxy forwards as plain HTTP (X-Forwarded-Proto: http) to HTTPS. Until now, it built the redirect target from the Host header of the request. The client controls that header, so the redirect could send users to any other site (open redirect).

The redirect now always uses the host of OC_URL, the URL where OpenCloud is reachable for users:

  • the path and the query are taken from the request as the client escaped them (e.g. %2F in a file name stays as it is)
  • the host and any user info in the request URL are never used
  • if OC_URL can't be parsed or has no host, requests are passed on without a redirect, and the proxy logs why at startup

Behaviour change: on a server that is reachable under more than one host name, a request over plain HTTP is now redirected to the host of OC_URL, not to the name the user typed. Since OIDC and the web client already rely on OC_URL, such setups should not be affected in practice.

How Has This Been Tested?

  • new unit tests for the middleware (services/proxy/pkg/middleware/https_redirect_test.go): redirect target, port, escaped paths, # in the path, missing Host header, absolute request URLs with user info, and the cases without a redirect
  • go test ./services/proxy/pkg/middleware/ ./services/proxy/pkg/command/

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

This change was written with the help of Claude Code (an AI coding agent), and reviewed by me.

The proxy redirected requests forwarded as plain HTTP to https:// plus
the Host header of the request. The client controls that header, so the
redirect could send users to any other site (open redirect).

The redirect now uses the host of OC_URL, the URL where OpenCloud is
reachable for users, and keeps the path and query of the request as the
client escaped them. If OC_URL can't be parsed or has no host, requests
are passed on without a redirect, and the proxy logs why at startup.

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

codacy-production Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Security 1 high

View in Codacy

🟢 Metrics 16 complexity

Metric Results
Complexity 16

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for f4ab6191
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f4ab619) Report Missing Report Missing Report Missing
Head commit (153c046) 95250 29618 31.10%

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 (#4120) 44 44 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%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

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.

@asaah262 asaah262 left a comment

Copy link
Copy Markdown
Contributor

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!
Codacy flags http.Redirect at line 56 as an open redirect (Semgrep open-redirect). As far as I can see it's a false positive: scheme and host are fixed, only path and query come from the request, and the //evil.example.org/x test shows the host can't be changed. Shall we mark it as a false positive in Codacy, or add a // nosemgrep comment with the reason, like in services/notifications/pkg/email/html.go:224?

@pbleser-oc

Copy link
Copy Markdown
Member Author

Thanks for the review. Agreed, it's a false positive: scheme and host are fixed, only path and query come from the request. I'd rather not add a comment for it and run the whole CI again, so I tried to mark it as a false positive in Codacy, but my account isn't allowed to ignore issues there. Since Codacy doesn't block, I'm leaving it as it is.

@pbleser-oc
pbleser-oc merged commit a6806bb into opencloud-eu:main Nov 25, 2026
61 of 62 checks passed
@pbleser-oc
pbleser-oc deleted the fix/867-https-redirect-trusted-host branch November 25, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants