Skip to content

fix(config): reject empty selected service sections - #16

Merged
soulteary merged 8 commits into
mainfrom
fix/reject-empty-selected-config
Sep 6, 2026
Merged

soulteary merged 8 commits into
mainfrom
fix/reject-empty-selected-config

Conversation

@soulteary

Copy link
Copy Markdown
Owner

Summary

  • fail closed when -config does not define the selected forward or proxy section
  • treat empty/comment-only and language-only legacy files as having no forward instances
  • reject explicit forward: [] and proxy: [] instead of starting built-in defaults
  • add regression coverage for missing and empty sections

Why

An explicitly supplied configuration should never silently start the default forwarder or proxy. The previous fallback was especially risky for the default forward listener because it could bind :22 when running with sufficient privileges.

Validation

  • added table-driven coverage for empty files, language-only files, missing sections, and empty lists
  • existing CI will run vet, race tests, lint, cross-build, module checks, and govulncheck

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T14:01:52.552097Z 9534601 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 571cbd3103

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread main.go
if err != nil {
return err
}
if len(topCfg.Forward) == 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject empty service objects, not just empty lists

When the selected section is written as forward: {} or forward: [{}], YAML decoding produces a list of length one containing a zero-valued config, so this check is bypassed and the later merge starts the built-in forwarder on :22. The equivalent proxy: {} case also starts the default proxy. Validate that the selected instances contain configuration fields rather than relying only on the list length.

Useful? React with 👍 / 👎.

Comment thread main.go
return err
}
if len(topCfg.Forward) == 0 {
return errors.New(i18n.T(i18n.KeyErrConfigSectionEmpty, "forward"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply the configured language before reporting missing sections

When a valid file sets a top-level language, such as lang: fr, but omits the selected service, this newly added error is formatted before the later SetLang block processes topCfg.Lang; consequently the error uses the environment/default language rather than the configuration's requested language. The same ordering affects the proxy check.

Useful? React with 👍 / 👎.

@soulteary

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c5af31c66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread main.go Outdated
return err
}
if len(topCfg.Forward) == 0 ||
(len(topCfg.Forward) == 1 && (topCfg.Forward[0] == nil || *topCfg.Forward[0] == (ForwardConfig{}))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate every instance in multi-instance sections

When a section contains two or more entries, this len(...) == 1 guard leaves empty entries unchecked. For example, forward: [{listen_port: 13001}, {}] reaches runForwardMulti, which fills the empty entry from defaultForwardOptions and starts an unintended :22 forwarder; an analogous proxy list starts the default proxy. Reject zero-valued or null entries at every list index rather than only when the list has one element.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fc1d266fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread main.go
Comment on lines +212 to +213
if len(topCfg.Forward) == 0 {
return errors.New(i18n.T(i18n.KeyErrConfigSectionEmpty, "forward"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Merge the same config snapshot that was validated

When a config manager atomically replaces the file during startup, this validates the first read but the single-instance path later reads the file again at loadForwardConfig; if that second snapshot is empty or lacks forward, merging it leaves the built-in :22 forwarder active despite this fail-closed check. The same two-read race exists in runProxy between its validation and later loadTopConfig, so retain and merge the already validated topCfg snapshot instead of reopening the path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: e492a717dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 95346019bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@soulteary
soulteary merged commit 696aec1 into main Sep 6, 2026
9 checks passed
@soulteary
soulteary deleted the fix/reject-empty-selected-config branch September 6, 2026 14:02
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