Skip to content

Avoid mDNS advertisement response loops - #124

Open
Jim8y wants to merge 1 commit into
neoorder:masterfrom
Jim8y:fix/audit-p2-17
Open

Avoid mDNS advertisement response loops#124
Jim8y wants to merge 1 commit into
neoorder:masterfrom
Jim8y:fix/audit-p2-17

Conversation

@Jim8y

@Jim8y Jim8y commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the existing remote-debugger mDNS advertiser replying to its own announcements and other response packets.

  • Parse the DNS question section and answer only relevant service/instance/host queries with the expected class and record type.
  • Ignore responses, unrelated traffic, truncated questions and invalid/compression-loop names.
  • Preserve the existing announcement contents, service name, periodic schedule and debugger protocol. No new app API, permission flow or window-navigation behavior is added.

Validation

  • node --test tests/p2-17/mdns.test.mjs: 1 test passed, covering self-response rejection, malformed traffic, a real-shaped PTR query and truncation.
  • Android API 36 arm64 emulator: the actual production MdnsRemoteDebuggerDiscovery received the real production host advertiser and reported debugger audit-p2-17, port 32145. The native event was not injected. A local packet capture showed the guest service query followed by the actual host PTR/SRV/TXT announcement; a 45-second observation recorded two announcements with no response storm.
  • Android required a separate emulator-network instance with host-mDNS forwarding. This was test infrastructure only, not a product source change. The fixture-free product was fully rebuilt with zero warnings/errors, installed and launched to Welcome. The temporary emulator/network instance was stopped; the other running Android emulator was not changed.
  • iPhone 17 / iOS 26.5 simulator: the actual production discovery event received audit-p2-17 at 198.18.0.1:32145 after the native listener started and the unchanged production advertiser was launched. The 45-second real UDP observation recorded two announcements, no storm, and normal advertiser exit. The fixture was removed; a full product rebuild passed with zero warnings/errors and the installed product displayed Home/four tabs. The temporary product source matched the source branch after restoration.
  • Tested source diff SHA-256: c276f4d8dfec85e4983b79f15f0f54e58c457ba7b4158162cca4bf1507a65797, independently based on master@623603d634f07eaead14745da87920a356159be0.

Limits

This verifies service discovery, not debugger authentication, a wallet operation or a blockchain transaction. Earlier emulator startup and listener-timing failures were retained and were not counted as passing runs. Android's system Bluetooth process reported an unrelated HCI failure; no OneGate crash was observed.

Screenshots, temporary QA fixtures and packet captures remain outside the repository. Raw packet captures contain unrelated local-network discovery traffic and are not for public upload. No screenshot upload, hosted CI pass or maintainer approval is claimed.

Copilot AI lite review requested due to automatic review settings September 5, 2026 09:14

Copilot AI 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.

🟡 Changes recommended

The new test’s cleanup should restore the global dgram.createSocket stub even if stop() fails, and the query filter has avoidable per-packet allocations/extra work that should be tightened given the high-frequency packet path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the remote debugger mDNS advertiser so it only responds to valid discovery queries (PTR/SRV/TXT/A/ANY) for the expected service/instance/host names, preventing it from replying to its own announcements and other unrelated packets.

Changes:

  • Added DNS question parsing with compression-loop/truncation rejection, and query filtering via isDiscoveryQuery.
  • Updated the advertiser to announce only when a relevant discovery query is received (instead of substring matching).
  • Added a Node test covering self-response rejection, malformed traffic, a PTR-shaped query, and truncation; added the test to solution items.
File summaries
File Description
OneGate.Codex/onegate/skills/onegate-dapp-debug/scripts/runtime/remote-debugger-advertiser.mjs Adds DNS question parsing and gates announcements on relevant mDNS queries to avoid response loops.
tests/p2-17/mdns.test.mjs Introduces coverage for the new query-filtering behavior and basic malformed/truncated packet handling.
OneGateApp.slnx Adds the new test file under Solution Items for visibility.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/p2-17/mdns.test.mjs
Comment on lines +28 to +31
} finally {
await advertiser.stop();
dgram.createSocket = original;
}
Comment on lines +74 to +96
function isDiscoveryQuery(packet, instanceName, hostName) {
if (packet.length < 12 || (packet.readUInt16BE(2) & 0xf800) !== 0) return false;
const count = packet.readUInt16BE(4);
let offset = 12;
let relevant = false;
try {
for (let index = 0; index < count; index++) {
const question = readQuestionName(packet, offset);
offset = question.end;
if (offset + 4 > packet.length) return false;
const type = packet.readUInt16BE(offset);
const dnsClass = packet.readUInt16BE(offset + 2) & 0x7fff;
offset += 4;
if (dnsClass !== 1) continue;
relevant ||= question.name === SERVICE_NAME && (type === 12 || type === 255)
|| question.name === instanceName.toLowerCase() && [33, 16, 255].includes(type)
|| question.name === hostName.toLowerCase() && (type === 1 || type === 255);
}
return relevant;
} catch {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants