Skip to content

feat: add security warning with confirmation prompt for non-localhost --bind#98

Merged
k1LoW merged 6 commits intomainfrom
bind-warn
Mar 10, 2026
Merged

feat: add security warning with confirmation prompt for non-localhost --bind#98
k1LoW merged 6 commits intomainfrom
bind-warn

Conversation

@k1LoW
Copy link
Copy Markdown
Owner

@k1LoW k1LoW commented Mar 10, 2026

This pull request introduces a security warning when the server is bound to a non-localhost address. If the user attempts to bind to an external address, a prominent warning is displayed with colored formatting, and the user is prompted for confirmation before proceeding. Additionally, new dependencies are added to support this feature.

Security improvements:

  • Added a runtime check in cmd/root.go to display a colored security warning and require user confirmation when binding the server to a non-localhost address, warning about lack of authentication and potential security risks.

Dependency updates:

  • Added github.com/muesli/termenv as a dependency for terminal text styling to enable colored warnings. [1] [2]
  • Updated golang.org/x/sys to v0.30.0 and added several indirect dependencies to support terminal and color features.

@k1LoW k1LoW self-assigned this Mar 10, 2026
@k1LoW k1LoW added the enhancement New feature or request label Mar 10, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a safety check to the mo CLI to warn users (and require confirmation) when binding the server to a non-loopback address, reducing the chance of accidentally exposing an unauthenticated server on the network.

Changes:

  • Added a colored security warning + confirmation prompt when --bind is not localhost/loopback.
  • Introduced termenv (and related transitive deps) to style the warning output.
  • Updated module sums and indirect dependencies (including golang.org/x/sys).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
cmd/root.go Adds the non-local bind warning and interactive confirmation prompt in run().
go.mod Adds new terminal styling dependencies and bumps golang.org/x/sys.
go.sum Records checksums for the newly added/updated dependencies.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmd/root.go Outdated
Comment thread cmd/root.go Outdated
Comment thread cmd/root.go Outdated
Comment thread go.mod Outdated
Comment thread cmd/root.go Outdated
@github-actions

This comment has been minimized.

@k1LoW
Copy link
Copy Markdown
Owner Author

k1LoW commented Mar 10, 2026

Addressed all review comments:

  1. Non-start operations blocking — Added conditions to skip the prompt for --status, --shutdown, --restart, --clear, and --unwatch.
  2. Silent exit on rejection — Added mo: canceled message and scanner.Err() handling.
  3. Narrow loopback detection — Replaced string comparisons with net.ParseIP() + IsLoopback() (plus localhost string check). Now covers 127.0.0.2 etc.
  4. go.mod indirect — Fixed via go mod tidy.
  5. Tests — Added TestIsLoopbackBind covering loopback IPs, non-loopback IPs, hostnames, and empty string.

- Skip prompt for non-start operations (--status/--shutdown/--restart/--clear/--unwatch)
- Use net.ParseIP + IsLoopback for broader loopback detection
- Return scanner.Err() on EOF
- Fix go.mod indirect annotation via go mod tidy
- Add TestIsLoopbackBind
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmd/root.go Outdated
Comment thread cmd/root_test.go
Comment thread cmd/root.go Outdated
Comment thread cmd/root.go Outdated
Comment thread cmd/root.go Outdated
- Move security prompt to just before startServer/startBackground so it
  doesn't block non-start operations or adding files to existing servers
- Use net.JoinHostPort instead of fmt.Sprintf for correct IPv6 bracket notation
- Add explicit name field to TestIsLoopbackBind for empty string case
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmd/root.go Outdated
Comment thread cmd/root.go
Comment thread cmd/root.go
@github-actions
Copy link
Copy Markdown
Contributor

Code Metrics Report

main (8d18763) #98 (6922349) +/-
Coverage 51.7% 51.5% -0.3%
Code to Test Ratio 1:0.5 1:0.5 -0.1
Test Execution Time 36s 38s +2s
Details
  |                     | main (8d18763) | #98 (6922349) |  +/-  |
  |---------------------|----------------|---------------|-------|
- | Coverage            |          51.7% |         51.5% | -0.3% |
  |   Files             |             35 |            35 |     0 |
  |   Lines             |           2784 |          2812 |   +28 |
+ |   Covered           |           1442 |          1450 |    +8 |
- | Code to Test Ratio  |          1:0.5 |         1:0.5 |  -0.1 |
  |   Code              |           4289 |          4290 |    +1 |
  |   Test              |           2526 |          2526 |     0 |
- | Test Execution Time |            36s |           38s |   +2s |

Code coverage of files in pull request scope (50.6% → 50.3%)

Files Coverage +/- Status
cmd/root.go 23.1% +0.0% modified
internal/server/server.go 71.3% +0.1% affected

Reported by octocov

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmd/root.go
Comment thread cmd/root.go
@k1LoW k1LoW merged commit 123ec79 into main Mar 10, 2026
7 checks passed
@k1LoW k1LoW deleted the bind-warn branch March 10, 2026 07:13
@github-actions github-actions Bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants