Skip to content

fix: harden clip server bind defaults - #21

Merged
Luqueee merged 4 commits into
mainfrom
codex/harden-clip-bind
Sep 4, 2026
Merged

Luqueee merged 4 commits into
mainfrom
codex/harden-clip-bind

Conversation

@Luqueee

@Luqueee Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary\n- bind the unauthenticated clip server to loopback by default and warn on broad binds\n- make mole init derive a coherent private listen address from clip_url, while preserving explicit flags, environment values, and existing YAML settings\n- document Tailscale/WireGuard setup and add regression coverage\n\n## Validation\n- go test ./...\n- go test -race ./...\n- go vet ./...\n- git diff --check\n- CodeRabbit review: no findings\n\nFixes #17

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 813d926e-3a3a-46e4-8e8e-ec6742d1ee3b

📥 Commits

Reviewing files that changed from the base of the PR and between a6883bc and e4e7ba5.

📒 Files selected for processing (4)
  • cmd/mole/init.go
  • cmd/mole/init_test.go
  • internal/config/config.go
  • internal/config/config_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Clipboard sharing now defaults to the local-only address 127.0.0.1:7777.
    • Clipboard listen addresses can be derived from configured URLs, while explicit settings remain authoritative.
    • Private Tailscale and WireGuard links can be used for remote clipboard access.
  • Bug Fixes

    • Broad network bindings now display warnings with safer address guidance.
    • Invalid clipboard URLs and out-of-range ports are rejected with configuration feedback.
  • Documentation

    • Clarified endpoint behavior, private-network access, unauthenticated sharing, and security considerations.
    • Added configuration examples for optional sharing settings.

Walkthrough

Clipboard serving now defaults to 127.0.0.1:7777. Configuration derives listen addresses from clipboard URLs when needed. Broad bindings emit warnings. Documentation and examples describe private Tailscale or WireGuard access.

Changes

Clipboard networking

Layer / File(s) Summary
Configuration listen resolution
internal/config/config.go, internal/config/config_test.go
DefaultClipListen sets the loopback default. Load derives clip_listen from clip_url when no explicit value exists. Tests cover defaults, precedence, malformed URLs, port ranges, and protected error messages.
Initialization and prompt wiring
cmd/mole/init.go, cmd/mole/init_test.go
Initialization resolves listen addresses from environment variables, clipboard URLs, defaults, and interactive input. Tests cover URL parsing, precedence, invalid ports, protected error messages, and prompt behavior.
Serving, warnings, and documentation
cmd/mole/clip.go, cmd/mole/clip_test.go, README.md, examples/mole.yaml, internal/clip/client.go, internal/clip/server.go
clip serve uses the loopback default and warns for empty, wildcard, or unspecified broad bindings. Documentation and examples describe private Tailscale or WireGuard endpoints and unauthenticated clipboard behavior.

Merge Risk: 🟡 Moderate · up to e4e7b

This change improves clipboard binding defaults, but unresolved URL and listen-address normalization cases can leave clipboard sharing misconfigured or unavailable. Resolve these configuration behaviors before merging.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required Conventional Commit format with the fix: prefix and accurately summarizes the binding-default security change.
Description check ✅ Passed The description directly covers the binding changes, initialization behavior, documentation, tests, and validation in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 codex/harden-clip-bind

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: e002e3d9-3c71-4052-ab04-2377d6b8b38a

📥 Commits

Reviewing files that changed from the base of the PR and between 88118a5 and 26d899f.

📒 Files selected for processing (10)
  • README.md
  • cmd/mole/clip.go
  • cmd/mole/clip_test.go
  • cmd/mole/init.go
  • cmd/mole/init_test.go
  • examples/mole.yaml
  • internal/clip/client.go
  • internal/clip/server.go
  • internal/config/config.go
  • internal/config/config_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread cmd/mole/clip.go Outdated
Comment thread cmd/mole/init.go
Comment thread internal/config/config.go Outdated
@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully\n\nApplied the three approved CodeRabbit findings.\n\nChanges:\n- warnings now use the effective listener address, including empty broad binds\n- mole init --help documents clipboard flags and supported environment variables\n- malformed clip_url values are rejected with a useful error\n\nFiles modified:\n- cmd/mole/clip.go\n- cmd/mole/clip_test.go\n- cmd/mole/init.go\n- cmd/mole/init_test.go\n- internal/config/config.go\n- internal/config/config_test.go\n\nCommit: f9680a3\n\nValidation passed: 159 tests, race tests, go vet, and diff checks.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 019b2e25-0d1b-406e-9d3a-0cde32da287d

📥 Commits

Reviewing files that changed from the base of the PR and between 26d899f and f9680a3.

📒 Files selected for processing (6)
  • cmd/mole/clip.go
  • cmd/mole/clip_test.go
  • cmd/mole/init.go
  • cmd/mole/init_test.go
  • internal/config/config.go
  • internal/config/config_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread internal/config/config.go Outdated
Comment thread internal/config/config.go Outdated
@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully\n\nApplied the two approved CodeRabbit findings.\n\nChanges:\n- clip_url is validated even when clip_listen is explicitly configured\n- clip URL validation errors are sanitized and do not expose URL credentials\n\nCommit: a6883bc\n\nValidation passed: 159 tests, race tests, go vet, format checks, and diff checks.

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cmd/mole/init.go (1)

257-257: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Trim ClipListen before applying the default.

When MOLE_CLIP_LISTEN contains only whitespace, line 255 classifies it as not provided, but line 256 does not treat it as empty. Line 257 therefore does not apply config.DefaultClipListen; ans.ClipListen later becomes empty.

Normalize in.ClipListen before this branch, or reject whitespace-only values.

As per path instructions, “The command and flag definitions are user-facing API.”

Source: Path instructions

internal/config/config.go (1)

231-234: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject invalid clipboard port ranges in both clipListenForURL helpers.

When the URL-derived listen address is used, port 0 makes net.Listen select an ephemeral port, while a port above 65535 fails only when runClipServe starts. Validate the parsed port as 1..65535 before calling net.JoinHostPort in internal/config/config.go and cmd/mole/init.go.

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: c3fd1a6d-4221-4d02-b775-41d9eef9ed9a

📥 Commits

Reviewing files that changed from the base of the PR and between f9680a3 and a6883bc.

📒 Files selected for processing (4)
  • cmd/mole/init.go
  • cmd/mole/init_test.go
  • internal/config/config.go
  • internal/config/config_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread internal/config/config.go
Comment on lines +203 to +204
if strings.TrimSpace(clipConfig.ClipURL) != "" {
listen, err := clipListenForURL(clipConfig.ClipURL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Store the normalized ClipURL.

strings.TrimSpace is applied only to the validation condition and the helper’s local copy. cfg.ClipURL keeps the original YAML value. A quoted URL with surrounding whitespace therefore derives ClipListen from one value while mole clip pull consumes another. A whitespace-only value also remains non-empty and bypasses validation.

Assign the trimmed value to cfg.ClipURL, or reject whitespace-only values.

As per path instructions, “Malformed or unknown configuration should fail with a useful error.”

Source: Path instructions

Comment thread internal/config/config.go
Comment on lines +228 to +229
if parsed.Hostname() == "" {
return "", errors.New("invalid clip URL: missing host")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🤖 get_repo_knowledge executed:

get_repo_knowledge Luqueee/mole /tmp/coderabbit-repo-knowledge/luqueee-mole-a4a89a3b/conventions

Length of output: 3058


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- internal/config/config.go ---'
sed -n '190,255p' internal/config/config.go

printf '%s\n' '--- cmd/mole/init.go ---'
sed -n '455,525p' cmd/mole/init.go

printf '%s\n' '--- ClipURL definitions and uses ---'
rg -n -C 3 'ClipURL|clip URL|parsed\.Hostname|ParseRequestURI|url\.Parse' --glob '*.go' .

printf '%s\n' '--- HTTP client/server bindings ---'
rg -n -C 3 'http\.(Get|Post|Client|NewRequest|ListenAndServe|Serve)|ListenAndServe|RoundTripper|Transport' --glob '*.go' .

Repository: Luqueee/mole

Length of output: 37625


🏁 Script executed:

#!/bin/bash
set -eu
sed -n '210,242p' internal/config/config.go
sed -n '480,512p' cmd/mole/init.go
rg -n -C 4 'ClipURL|parsed\.Hostname|url\.Parse|ParseRequestURI|http\.(Get|Post|NewRequest)|ListenAndServe' --glob '*.go' .

Repository: Luqueee/mole

Length of output: 35910


🤖 get_repo_knowledge executed:

get_repo_knowledge Luqueee/mole /tmp/coderabbit-repo-knowledge/luqueee-mole-a4a89a3b

Length of output: 1904


🌐 Web query:

Go net/http transport supported URL schemes http https RoundTrip documentation

💡 Result:

In the Go net/http package, the http.Transport type is an implementation of the RoundTripper interface that natively supports http and https URL schemes [1][2]. Beyond these native schemes, Transport allows for the registration of custom protocol handlers using the RegisterProtocol method [3][4]. Key details regarding supported schemes and protocols: 1. Native Support: Transport natively handles http and https requests [1][2]. By default, it manages HTTP/1.1 for these schemes and may negotiate HTTP/2 or HTTP/3 depending on configuration [1][5][6]. 2. Custom Protocols: You can extend Transport to support additional schemes (e.g., ftp://, custom RPC protocols) by using the RegisterProtocol(scheme string, rt RoundTripper) method [3][4]. This allows you to define a custom RoundTripper implementation that will be invoked whenever a request with the registered scheme is encountered [4]. 3. Proxy Schemes: When configuring a proxy, Transport explicitly supports the schemes http, https, socks5, and socks5h [1][7]. The proxy type is determined by the scheme provided in the proxy URL [1][7]. 4. HTTP/2 and HTTP/3: While often treated as transport layers for http/https, Go also provides internal mechanisms to register handlers for "http/2" and "http/3" schemes explicitly in some contexts, typically used for advanced transport configuration and testing [7][4]. For precise control over which versions of HTTP are used for native schemes, you can configure the Protocols field on the Transport (e.g., using HTTP1, HTTP2, and UnencryptedHTTP2 constants) [5][8].

Citations:


🌐 Web query:

github Luqueee/mole internal/config config.go ClipURL cmd/mole/init.go

💡 Result:

The repository github.com/Luqueee/mole is an SSH port forwarder tool designed for developer workflows [1]. It features automatic port discovery on remote hosts, auto-reconnection, and integration with SSH config aliases [1]. Regarding the specific file paths and components you mentioned: - internal/config/config.go: This path is standard in Go projects for managing application configuration [2][3]. While specific internal code for Luqueee/mole was not surfaced in external documentation, projects of this type typically use libraries like Viper to handle configuration loading from files, environment variables, or CLI flags [4][3]. ClipURL is likely a configuration parameter or utility function within this context, potentially related to handling clipboard interactions or URL parsing for SSH connections. - cmd/mole/init.go: This file is typically used in Go CLI applications to initialize the application, set up flags, or perform bootstrap logic before the main command execution [1]. It is important to distinguish this project (Luqueee/mole) from other similarly named tools: - There is a well-known, unrelated tool called mole (github.com/davrodpin/mole) used for creating resilient SSH tunnels [5]. - There is also a macOS utility named Mole (mole.fit) used for system cleanup [6][7]. You can explore the source code directly at https://github.com/Luqueee/mole to see the exact implementation details of the config handling and initialization logic [1].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- cmd/mole/clip.go ---'
sed -n '205,245p' cmd/mole/clip.go
printf '%s\n' '--- internal/clip/client.go ---'
sed -n '20,65p' internal/clip/client.go
printf '%s\n' '--- clip serve listen path ---'
sed -n '105,150p' cmd/mole/clip.go

Repository: Luqueee/mole

Length of output: 4316


Reject non-HTTP(S) ClipURL values in both clipListenForURL helpers.

ftp://host:7777 passes both helpers because url.Parse succeeds and parsed.Hostname() is non-empty. The value reaches internal/clip.Client, whose default net/http transport rejects it during Pull. Validate parsed.Scheme as http or https before deriving the listen address.

📍 Affects 2 files
  • internal/config/config.go#L228-L229 (this comment)
  • cmd/mole/init.go#L498-L499

Source: Path instructions

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully\n\nApplied the two approved CodeRabbit findings.\n\nChanges:\n- whitespace-only clipboard listen values now fall back correctly\n- URL-derived clipboard ports must be between 1 and 65535\n\nCommit: e4e7ba5\n\nValidation passed: 163 tests, race tests, go vet, format checks, and diff checks.

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

@Luqueee
Luqueee merged commit 3995291 into main Sep 4, 2026
4 checks passed
@Luqueee
Luqueee deleted the codex/harden-clip-bind branch September 4, 2026 10:40
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.

1 participant