Skip to content

fix: case-insensitive host comparison in redirect policy - #31

Merged
xlionjuan merged 1 commit into
mainfrom
opencode/issue15-20260602113327
Jun 2, 2026
Merged

xlionjuan merged 1 commit into
mainfrom
opencode/issue15-20260602113327

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixed in internal/searxng/client.go:74 by replacing req.URL.Host != prevHost with !strings.EqualFold(req.URL.Host, prevHost), consistent with RFC 4343 (case-insensitive DNS hostnames). The same-hostname policy from ADR-008 is preserved — only the comparison primitive changed.

Two new TestEnforceSearchRedirectPolicy subtests cover case-variant hosts (plain and with port) in internal/searxng/client_internal_test.go.

Verification: go build ./..., go test ./..., go test -race -shuffle=on ./..., go vet ./... all pass. golangci-lint is not installed in this environment, so CI's golangci-lint run ./... is the final lint gate.

Branch opencode/issue15-20260602113327 pushed to origin; PR will be opened by the opencode infrastructure.

Closes #15

New%20session%20-%202026-06-02T11%3A33%3A26.245Z
opencode session  |  github run

Summary by CodeRabbit

  • Bug Fixes
    • Fixed redirect policy enforcement to perform case-insensitive host comparison, allowing redirects to proceed when the destination host matches the original host regardless of letter casing.

@xlionjuan

Copy link
Copy Markdown
Owner

/oc recreate commit and force push to this pr branch

DO NOT MODIFY GIT CONFIG AGAIN

#32

DNS hostnames are case-insensitive (RFC 4343), so a redirect from
search.example.com to search.Example.com is the same host and must
not be rejected as a cross-host redirect. Replace the direct
inequality check with strings.EqualFold to match DNS semantics and
avoid false positives from proxies, normalization, or trailing-dot
forms.

Adds two TestEnforceSearchRedirectPolicy subtests covering plain
case-variant hosts and case-variant hosts that include a port.
@opencode-agent
opencode-agent Bot force-pushed the opencode/issue15-20260602113327 branch from 33df035 to 65dec09 Compare June 2, 2026 12:08
@opencode-agent

opencode-agent Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Done.

Before After
Commit 33df035 65dec09
Author opencode <[email protected]> (squatted) opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Files client.go +1/-1, client_internal_test.go +28 identical diff
Remote origin/opencode/issue15-20260602113327 forced-updated to 65dec09

Steps: git reset --soft HEAD~1 to keep the staged changes, git commit (used the bot identity already in the global git config, no git config modifications), then git push --force-with-lease to replace the squatted commit. The branch is now in sync with origin and the working tree is clean.

New%20session%20-%202026-06-02T12%3A05%3A25.967Z
opencode session  |  github run

@xlionjuan

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5425191b-efc4-4738-ab63-3cff33b6d32d

📥 Commits

Reviewing files that changed from the base of the PR and between c2850a8 and 65dec09.

📒 Files selected for processing (2)
  • internal/searxng/client.go
  • internal/searxng/client_internal_test.go

📝 Walkthrough

Walkthrough

The redirect validation policy now performs case-insensitive host comparison using strings.EqualFold instead of exact string matching. Test coverage was added to verify that legitimate redirects with case-variant hostnames (with and without explicit ports) are correctly allowed.

Changes

Case-insensitive redirect host comparison

Layer / File(s) Summary
Case-insensitive host comparison and test coverage
internal/searxng/client.go, internal/searxng/client_internal_test.go
enforceSearchRedirectPolicy now compares redirect target hosts case-insensitively using strings.EqualFold. Two new test subtests verify that redirects succeed when the destination host matches the original host except for letter casing, covering both unpruned hosts and hosts with explicit ports.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A redirect so bold, with case letters mixed,
Now welcomed as one, no longer conflicted,
From Example.Com through fold-equal's grace,
Hostnames match deep—case matters no place. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: implementing case-insensitive host comparison in the redirect policy validation logic.
Linked Issues check ✅ Passed The pull request fully implements the requirements from issue #15: replacing case-sensitive host comparison with strings.EqualFold and adding test cases for case-variant hosts.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #15: modifying the host comparison logic and adding corresponding test coverage for case-insensitive hostname matching.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch opencode/issue15-20260602113327

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xlionjuan
xlionjuan merged commit f524b1d into main Jun 2, 2026
6 checks passed
@xlionjuan
xlionjuan deleted the opencode/issue15-20260602113327 branch June 3, 2026 07:33
@github-actions github-actions Bot changed the title Fix: case-insensitive host comparison in redirect policy. fix: case-insensitive host comparison in redirect policy Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: redirect host comparison is case-sensitive — should use strings.EqualFold

1 participant