Problem: A node creates its onion service through Tor's control protocol and caches the returned private key for reconnects.
Tor reply parsing unescapes quoted values, so a control endpoint can return a private key containing a line break or space.
When the node reconnects, it inserts that key unquoted into an ADD_ONION command, where CRLF frames the remainder as a separate command and a space adds further arguments.
An unprivileged local process can exploit this by impersonating the default loopback endpoint while Tor is unavailable, seeding the cache, and releasing the port before Tor returns.
A compromised operator-configured endpoint can return the same malicious key.
The reply handler also continues after receiving an invalid service ID, logging it and caching the key before attempting to advertise the invalid address.
Fix: This PR validates the returned service ID as a Tor v3 onion address before logging it, caching the key, or advertising the service.
It accepts NEW:ED25519-V3 or an ED25519-V3 key whose Base64 payload decodes to 64 bytes.
Returned keys are validated before adoption or caching, and cached keys are validated before reuse.
A malformed cached key leaves the onion service unavailable until the operator removes the file and restarts the node, but cannot inject another command or argument.