Repository navigation
fix(proxy): redirect to HTTPS on the host of OC_URL - #4120
Conversation
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
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 1 high |
🟢 Metrics 16 complexity
Metric Results Complexity 16
🟢 Coverage 100.00% diff coverage
Metric Results Coverage variation Report missing for f4ab6191 Diff coverage ✅ 100.00% diff coverage 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
left a comment
There was a problem hiding this comment.
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?
|
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. |
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 theHostheader 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:%2Fin a file name stays as it is)OC_URLcan't be parsed or has no host, requests are passed on without a redirect, and the proxy logs why at startupBehaviour 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 onOC_URL, such setups should not be affected in practice.How Has This Been Tested?
services/proxy/pkg/middleware/https_redirect_test.go): redirect target, port, escaped paths,#in the path, missingHostheader, absolute request URLs with user info, and the cases without a redirectgo test ./services/proxy/pkg/middleware/ ./services/proxy/pkg/command/Types of changes
This change was written with the help of Claude Code (an AI coding agent), and reviewed by me.