How AI Coding Assistants Leak Developer Emails Through Network Requests and Script Execution: Causes and Mitigations

    AI coding assistants increasingly browse the web, call APIs, and run local scripts. When sensitive account data sits in the model's context, it can end up in outbound requests—sometimes as far as the User-Agent header. This article breaks down a real-world email leak incident, explains the three conditions that make such leaks possible, and outlines practical defenses including context minimization, unified egress sanitization, header allowlists, and script review.

    Background: Agents Now Reach Outside the Developer’s Machine

    More and more AI coding assistants no longer just generate code—they actively fetch web pages, call APIs, and run local scripts. These capabilities make the tools behave more like hands-on agents, and they also create a path for information that used to stay on the developer’s machine to flow outward. Account emails, organization names, and local file paths typically live in the session context. Once the model reads this information, it may reuse it in requests it generates later.

    What Happened: An Email Ended Up in a Request Header

    In early November, a developer reported in a public issue tracker that an AI coding tool they used had written the email address bound to their account into the User-Agent field of HTTP request headers when accessing external websites. The site’s server-side access logs therefore recorded the real email address, and the developer subsequently received a flood of phishing emails.

    The tool vendor’s explanation offered a key clue: this was not an intended feature. The model read the email obtained through authorized login from the session context, and in scenarios where a website asked a script client to “provide contact information,” the model independently filled the email into the request header. The starting point of the problem, then, was not a buggy line of code—it was the model seeing data that should never have participated in its decisions.

    Root Cause Analysis: Three Conditions, All Required

    A leak occurs only when three conditions hold simultaneously:

    1. Data visibility: sensitive fields enter the context the model can read;
    2. Behavior generation: the model, guided by task semantics, autonomously decides to write those fields into some output;
    3. Egress approval: that output is sent externally through a network call or script execution interface, with no unified check in between.

    Most teams focus only on the third condition and often overlook the first. Once context contains sensitive data, any generation step can carry it out—via request headers, query parameters, form fields, log text, or temporary scripts.

    Why Point Filtering Doesn’t Fix the Problem

    Community testing has shown that some ad-hoc interception measures cover only certain call patterns. For web scraping, search APIs, external protocol calls, and “write to a file first, then execute the script” paths, interception is incomplete. This reflects the typical limitations of rule-based filters:

    • Rules depend on how commands are written; a different phrasing can bypass them.
    • Rules target known call channels; any new channel creates a blind spot.
    • Rules can only block—they cannot guarantee the model never touches sensitive data again.

    Filtering is therefore a last line of defense, not a root solution. The fundamental fix is to reduce opportunities for sensitive data to enter the model in the first place, and to enforce unified constraints at the egress point.

    Practical Defenses

    5.1 Context Minimization

    Before handing session information to the model, strip identity fields unrelated to the current task. Account emails, phone numbers, and internal domain names should appear only when genuinely necessary, and ideally as aliases or placeholders.

    5.2 Unified Egress Sanitization

    All outbound requests should pass through a single egress layer that uniformly inspects headers, URLs, request bodies, and logs. The following pseudocode illustrates the basic approach:

    1. EMAIL_PATTERN = regex matching common email formats
    2. function redact(text):
    3. return EMAIL_PATTERN.replace(text, "[REDACTED]")
    4. function build_outbound_headers(client_name, contact_hint):
    5. headers = {}
    6. headers["User-Agent"] = redact(client_name)
    7. if contact_hint is not None:
    8. headers["From"] = use_project_alias(contact_hint) // Use a project alias, not a personal email
    9. return headers

    Regex-based redaction alone is not enough. It can miss obfuscated forms—such as spaces inserted into the address or full-width characters—so it should be combined with an allowlist mechanism.

    5.3 Request Header Allowlist

    Outbound requests should carry only pre-approved fields. The User-Agent should use a fixed tool identifier plus version number, containing no user information. When contact information is genuinely required, always use a team-maintained project alias.

    5.4 Script and Artifact Review

    Statically review scripts generated and executed by the model before running them, scanning for sensitive patterns. Apply the same scanning to temporary files written to disk, so that “write first, run later” cannot bypass egress checks.

    5.5 Logging and Auditing

    Log the target domains, header field names, and invocation times of outbound requests to enable post-incident tracing. The logs themselves must also be sanitized—otherwise your audit data becomes a new leak source.

    Actionable Checklist for Individuals and Teams

    • Register a dedicated project email or alias for external services; never use your primary personal email.
    • In development environments, avoid writing production credentials or personal contact details into session content and configuration files.
    • Regularly review the release notes of the tools you use to check whether their handling of context and request headers has changed.
    • Configure network access allowlists for agent tools, restricting the domains they can reach.
    • If a leak occurs, first replace the affected contact information, then report it to the tool vendor, and retain relevant logs as evidence.