Skip to content

fix(proxy): set Secure, HttpOnly and SameSite=Strict on the policy selector cookie - #4101

Merged
asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/858-selector-cookie-flags
Nov 24, 2026
Merged

asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/858-selector-cookie-flags

Conversation

@asaah262

Copy link
Copy Markdown
Contributor

Description

With a claims or regex policy selector, the proxy sets the opencloud-selector cookie on requests with OIDC claims, so that later requests are routed to the same policy. The cookie had no Secure, HttpOnly or SameSite attribute. It now has all three:

  • Secure: the browser only sends it over HTTPS.
  • HttpOnly: scripts in the page can't read or change it. No client reads it: only the proxy does.
  • SameSite=Strict: the browser doesn't send it with requests that start on another site.

The guest session cookie of the proxy already uses the same attributes.

With the default static selector, the proxy sets no selector cookie, so nothing changes for most installations.

Related Issue

  • None

Motivation and Context

The cookie decides which backend serves a request, and the regex selector uses it before anything else. Without these attributes it was sent over plain HTTP, readable by scripts, and sent with requests from other sites.

Note for installations with a claims or regex selector:

  • On plain HTTP (except localhost), the browser drops the cookie. Requests are then routed as if there were no cookie: authenticated requests by the routing claim or the rules, unauthenticated ones by the unauthenticated policy.
  • When a user follows a link from another site, the first page load is routed the same way. Requests from that page send the cookie again.

How Has This Been Tested?

  • Test environment: macOS, Go tests.
  • New Go test services/proxy/pkg/middleware/selector_cookie_test.go, the first test of this middleware:
    • claims selector with a custom and with the default cookie name, and the regex selector: one cookie with the selected policy, Path=/, Secure, HttpOnly and SameSite=Strict. These three cases fail without the fix: the three attributes are missing.
    • unchanged behaviour: no cookie without OIDC claims, with the static selector, or without a selector; the next handler always runs.
  • go test -race ./services/proxy/... passes. 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 uses a claims or regex selector.

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.

…lector cookie

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

codacy-production Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 20 complexity

Metric Results
Complexity 20

View in Codacy

🟢 Coverage 100.00% diff coverage

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

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9afb99f) Report Missing Report Missing Report Missing
Head commit (82d6b0d) 94496 28586 30.25%

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 (#4101) 6 6 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.

@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.

Looks good to me. Same attributes as the guest session cookie, and the new test fails against the code on main, so it really covers the missing attributes. The notes on plain HTTP and cross-site navigation in the description are helpful.

The red notification pipeline is a connection reset on the settings service (cURL error 18), unrelated to this change.

@asaah262
asaah262 marked this pull request as ready for review November 24, 2026 10:19
@asaah262
asaah262 removed the request for review from micbar November 24, 2026 10:37
@asaah262
asaah262 merged commit 245bc7a into opencloud-eu:main Nov 24, 2026
64 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