Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nodemailer/nodemailer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.0.7
Choose a base ref
...
head repository: nodemailer/nodemailer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.0.8
Choose a head ref
  • 3 commits
  • 11 files changed
  • 3 contributors

Commits on May 23, 2026

  1. fix: enforce strict TLS for OAuth2 and Ethereal credential requests (#…

    …1818)
    
    * fix: enforce strict TLS validation for OAuth2 token requests
    
    lib/fetch is intentionally lax (rejectUnauthorized: false) because most
    fetch calls in nodemailer target attachment hosts that are often
    internal or self-signed. OAuth2 token endpoints are different: they
    carry credentials, and a MITM that intercepts the token refresh can
    silently exfiltrate the bearer token. Google's accounts.google.com
    default endpoint has a perfectly valid cert, so the lax default was
    opening a real attack surface for no benefit.
    
    xoauth2's postRequest now opts back into strict cert validation when
    the access URL is HTTPS, by passing tls.rejectUnauthorized: true to
    nmfetch. The user's options.tls is layered on top so self-hosted OAuth
    providers running on a private CA can still opt out with
    new XOAuth2({ ..., tls: { rejectUnauthorized: false } }).
    
    HTTP access URLs are unaffected (no TLS code path is even touched).
    That includes the existing xoauth2 test suite, which uses an HTTP
    localhost mock server.
    
    Adds test/xoauth2/xoauth2-tls-test.js with a self-signed HTTPS server:
    one test asserts the default refuses the bad cert, the second asserts
    the options.tls override accepts it.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    * fix: enforce strict TLS validation for createTestAccount
    
    Mirror the previous OAuth2 token-request fix: the call to the Ethereal
    API in createTestAccount also routes through lib/fetch, which defaults
    to rejectUnauthorized:false. The api.nodemailer.com endpoint has a
    real cert, so the lax default was a free attack surface against a
    credential-bearing endpoint.
    
    Opt back into strict cert validation when the API URL is HTTPS. The
    apiUrl argument can still point at HTTP for local dev/CI scenarios,
    which is unaffected. There is no per-call tls escape hatch — anyone
    needing to point at an HTTPS dev server with a private CA can set
    NODE_TLS_REJECT_UNAUTHORIZED=0 at the process level, the standard
    Node dev pattern.
    
    Adds test/nodemailer/ethereal-tls-test.js with a self-signed HTTPS
    mock server. Placed under a subdirectory because the top-level npm
    test glob (test/**/*-test.js) doesn't recurse without globstar — a
    pre-existing quirk that already silently skips test/ethereal-test.js;
    this new test is in test/nodemailer/ so CI actually runs it.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    * test: fix npm test glob so top-level test files are picked up
    
    The test and test:coverage scripts used the pattern test/**/*-test.js
    (plus the .test.js variant), but /bin/sh and bash without globstar
    treat ** as a single * — so the pattern silently degraded to
    test/*/*-test.js and only matched files exactly one directory deep.
    Top-level files like test/ethereal-test.js were never running under
    npm test.
    
    Switches the scripts to a find-based recursion that does the right
    thing across /bin/sh, /bin/bash, and dash. The find expression is
    quoted so npm-run-scripts hand it intact to the shell for command
    substitution.
    
    Also gates test/ethereal-test.js on NODEMAILER_INTEGRATION_TESTS=1
    because those tests hit api.nodemailer.com and send through real
    Ethereal SMTP — they were never meant to run unattended in CI. The
    suite shows up as SKIP in normal runs and runs in full when the env
    var is set.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
    andris9 and claude authored May 23, 2026
    Configuration menu
    Copy the full SHA
    833d6e5 View commit details
    Browse the repository at this point in the history
  2. fix: four listener/stream leaks in SMTP transport, connection, pool (#…

    …1817)
    
    * fix: clean up per-call OAuth2 listeners on all send/verify exit paths
    
    When mail.data.auth is set on send(), getAuth() builds a throwaway
    XOAuth2 instance with 'token' / 'error' listeners. Previously the
    listeners were only removed inside the connection.login() callback,
    so if SMTPConnection emitted 'error' or 'end' during login() before
    the login callback fired (server drops the socket mid-AUTH, for
    example), the per-call OAuth2 was retained, keeping the mailer alive
    through closures.
    
    verify() had the same class of bug, plus a worse variant: it always
    called getAuth with an empty object instead of undefined, so the
    short-circuit at the top of getAuth never fired and a fresh OAuth2
    was built every verify() call and never cleaned up at all.
    
    Both paths now hoist the per-call auth into a shared closure and call
    an idempotent cleanupPerCallAuth from every exit: once('error'),
    once('end'), the login callback, sendMessage's send-success path, and
    finalize in verify. The per-call OAuth2 is nulled after the first
    cleanup so subsequent calls are no-ops.
    
    Adds test/smtp-transport/oauth2-listener-leak-test.js which spins up
    a raw net server that drops the socket on AUTH XOAUTH2 and asserts
    listenerCount('token') and listenerCount('error') are 0 after send's
    callback fires.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    * fix: remove plain-socket listeners on STARTTLS handshake failure
    
    _upgradeConnection wraps tls.connect in try/catch because tls.connect
    can throw synchronously. Previously the catch path only called
    callback(err) without removing the plain socket's close/end/error
    listeners, leaving them attached on a socket that will never be used
    again — defence-in-depth issue, since later events were absorbed by
    the _destroyed guard.
    
    Centralizes the listener removal in a local removePlainSocketListeners
    helper and calls it from both the TLS-success callback and the catch
    branch.
    
    No new test — synchronous tls.connect throws are hard to trigger
    reliably without mocking the tls module and the existing TLS suite
    has no infrastructure for that.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    * fix: unpipe in-flight DATA stream on SMTP connection close
    
    _createSendStream pipes the message DataStream into the socket with
    { end: false } and never tracked the in-flight stream. If close() ran
    mid-DATA (for example a pool resource being closed during a send),
    the socket was end()/destroy()-ed but the source DataStream stayed
    piped to a dead destination until GC. Pool requeue keeps delivery
    correct, so this was a handle leak rather than a delivery bug.
    
    Tracks the active DataStream on the connection as _currentDataStream:
    set just before the pipe() call in _createSendStream, cleared in
    the stream's 'end' handler, and unpiped in close() before the socket
    teardown runs.
    
    No test added — reproducing requires racing close() against an
    in-flight DATA stream with deterministic timing, which the existing
    pool-resource tests do not have infrastructure for. The change is
    defensive and exercised by all normal send/close pathways.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    * fix: use socket.end() in _onEnd after FIN instead of destroy()
    
    _onEnd was calling this._socket.destroy() after the remote sent FIN.
    destroy() is semantically rude after a clean FIN — end() is the polite
    shape and matches the rest of the close path, where close() also picks
    'end' for non-init stages. _onClose still fires and the _destroyed
    guard makes the whole sequence idempotent, so this is cosmetic, but it
    removes a small inconsistency.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
    andris9 and claude authored May 23, 2026
    Configuration menu
    Copy the full SHA
    850bb91 View commit details
    Browse the repository at this point in the history
  3. chore(master): release 8.0.8 (#1819)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored May 23, 2026
    Configuration menu
    Copy the full SHA
    15138a8 View commit details
    Browse the repository at this point in the history
Loading