Skip to content

fix(agent): validate --id as a DNS label to stop /etc/hosts injection#774

Merged
bussyjd merged 1 commit into
integration/v0.14.0-rc0from
fix/agent-id-validation
Jul 16, 2026
Merged

fix(agent): validate --id as a DNS label to stop /etc/hosts injection#774
bussyjd merged 1 commit into
integration/v0.14.0-rc0from
fix/agent-id-validation

Conversation

@bussyjd

@bussyjd bussyjd commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Full-surface audit finding (HIGH): agent --id injects lines into root-owned /etc/hosts

Found by the 2026-07-16 whole-product-surface audit (PR #770), adversarially confirmed. obol agent new --id <value> passed the raw --id (only TrimSpaced) into a hostname string that is written to /etc/hosts via sudo tee (internal/dns/resolver.go) with no character filtering. An --id containing a newline injects arbitrary /etc/hosts entries (e.g. redirect a domain to an attacker IP). The same unvalidated --id also flowed into filesystem paths and a recursive-delete target (the sibling MEDIUM finding) — both closed here.

Fix (defense in depth)

  1. Primary: --id is validated as a strict DNS label (^[a-z0-9]([-a-z0-9]*[a-z0-9])?$, bounded length) at the Onboard boundary (shared validate helper, used by both hermes and openclaw paths) — it becomes a hostname, so this is correct regardless of the injection.
  2. Belt-and-suspenders: the /etc/hosts writer skips any hostname containing a non-DNS character, so no malformed value can reach the file even from another caller.

Test: validator rejects newline/space/slash/leading-dash/empty ids, accepts normal ones; resolver skips a malformed hostname. Tests green.

https://claude.ai/code/session_014YjPMViNrZ7zBVgUQzwEKk

Root cause: agent --id was only TrimSpace'd before being embedded into a
hostname (agentruntime.Hostname) and written to /etc/hosts via
dns.EnsureHostsEntries (sudo tee), with no newline/char filtering. A
newline in --id injects arbitrary /etc/hosts lines.

Fix (defense in depth):
1. hermes.Onboard and openclaw.Onboard now validate the resolved id with
   the existing validate.Name DNS-label check (^[a-z0-9][a-z0-9-]{0,62}$)
   before it is used to build deploymentDir/namespace/hostname, rejecting
   ids with newlines, spaces, slashes, leading dashes, or empty/oversized
   values.
2. dns.EnsureHostsEntries now skips any hostname that fails a new
   isValidHostname DNS-charset check before it is written into the
   /etc/hosts managed block, so a malformed hostname can never reach the
   file even from a caller that bypasses Onboard's validation.

Confirmed Canary402 full-surface audit finding.

Claude-Session: https://claude.ai/code/session_014YjPMViNrZ7zBVgUQzwEKk
@bussyjd
bussyjd merged commit 0859b86 into integration/v0.14.0-rc0 Jul 16, 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.

1 participant