Skip to content

fix(process-control): avoid sending management token to DNS-recorded stop hosts - #5086

Merged
lidge-jun merged 1 commit into
lidge-jun:devfrom
luvs01:agent/stop-dns-fence-20260919
Sep 19, 2026
Merged

lidge-jun merged 1 commit into
lidge-jun:devfrom
luvs01:agent/stop-dns-fence-20260919

Conversation

@luvs01

@luvs01 luvs01 commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A graceful-stop request POSTs /api/stop with the x-opencodex-api-key management token to the recorded runtime.hostname. When that recorded value is a DNS name rather than an IP literal, resolution can change between bind and stop — DNS rebinding or an attacker-controlled answer would receive the admin token. This is the same credential-destination class as the DNS-rebinding fence already landed for credential hostnames, on a different path.

Description

  • gracefulStopHost now follows the recorded bind hostname only when it is an IP literal (node:net isIP): IPv4 returns bare, IPv6 returns bracketed. DNS names, loopback aliases, and wildcard binds all fall back to 127.0.0.1, so the token is never sent through a DNS resolution.

Tests

  • bun test tests/lib/process-control-graceful.test.ts — new cases cover DNS names falling back to loopback and the management token never being sent to a recorded DNS hostname.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Improved graceful host shutdown routing by using the local IPv4 loopback address for DNS names, loopback aliases, and wildcard binds.
    • Preserved direct routing for valid IPv4 and IPv6 addresses.
    • Prevented management credentials from being sent to recorded DNS hosts.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 49818b1d-d34c-4ad8-b7d6-592eb82f5ff1

📥 Commits

Reviewing files that changed from the base of the PR and between 3d5efc7 and a06c3e1.

📒 Files selected for processing (2)
  • src/lib/process-control.ts
  • tests/lib/process-control-graceful.test.ts

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


📝 Walkthrough

Walkthrough

gracefulStopHost now validates recorded hostnames as IPv4 or IPv6 literals. DNS names, loopback aliases, and wildcard binds use 127.0.0.1. Tests verify DNS fallback and shutdown request completion.

Changes

Graceful shutdown routing

Layer / File(s) Summary
IP-literal routing
src/lib/process-control.ts
gracefulStopHost uses isIP to classify hostnames. IPv4 literals remain unbracketed, IPv6 literals are bracketed, and non-IP values use 127.0.0.1.
DNS fallback coverage
tests/lib/process-control-graceful.test.ts
Tests verify DNS bind names resolve to 127.0.0.1 and that shutdown requests complete with the management token configured.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: lidge-j

Merge Risk: 🔵 Low · up to a06c3

IPv6-only deployments may lose graceful draining during shutdown, though the impact is limited to those configurations.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: preventing management tokens from being sent to DNS-recorded stop hosts.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
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 unit tests (beta)
  • Create a new PR

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

@github-actions
github-actions Bot marked this pull request as ready for review September 18, 2026 21:58
@lidge-jun
lidge-jun merged commit 318f25b into lidge-jun:dev Sep 19, 2026
35 of 36 checks passed
@luvs01
luvs01 deleted the agent/stop-dns-fence-20260919 branch September 20, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants