Masking email addresses in logs is not optional. It is a security requirement. Every unmasked email in logs is a leak, a liability, a compliance failure. With Mosh—the remote terminal tool for high-latency connections—the risk compounds. Logs from Mosh sessions can end up saved on multiple servers, traveling across unstable networks. If personal data slips in, the exposure is instant and irreversible.
The goal is simple: strip or obfuscate email addresses before they hit any log file. Achieve it without slowing down Mosh or dropping packets. The implementation is straightforward if done with discipline.
Identify where logs are generated.
With Mosh, server-side and client-side outputs differ. Server logs from the Mosh daemon may capture session activity, authentication attempts, or debug output. Client logs often include shell activity. Audit both code paths.
Insert a masking layer.
Use regex to match email patterns like ([\w\.-]+)@([\w\.-]+\.[a-zA-Z]{2,}). Replace matches with a placeholder: [masked-email]. Apply this before flushing data to disk or sending it to remote log aggregation.