Skip to content

Real client IP, Apple proxy detection, one eligibility query, expiring temp passwords - #20

Merged
op-techy merged 1 commit into
mainfrom
fix/minor-audit-items
Dec 4, 2026
Merged

op-techy merged 1 commit into
mainfrom
fix/minor-audit-items

Conversation

@op-techy

@op-techy op-techy commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Fixes the last batch of audit findings (the minor items).

Problems

  1. The tracking IP could be faked. TrackingService.extractIp used the first entry of X-Forwarded-For, which any client can set, so the recorded IP and location were whatever the client said.
  2. Apple Mail Privacy Protection was never detected. The check looked for "Apple" and "Mail" in the User-Agent, but Apple's proxy fetches with a generic Mozilla/5.0 User-Agent.
  3. Sending ran one suppression query per recipient. collectEligibleRecipients checked each list member separately, so a 100k-recipient campaign made 100k queries before queuing anything.
  4. Temporary passwords were weak and never expired. Invites and admin resets used "Tmp-" + 8 hex characters (32 bits), valid forever.

Changes

  • Client IP:
    • Tracking uses request.getRemoteAddr(). Tomcat's RemoteIpValve (forward-headers-strategy: native) already sets it from X-Forwarded-For, trusting the header only from internal proxy addresses.
    • The manual header parsing is gone.
  • Apple proxy:
    • An open is flagged when the client IP is in 17.0.0.0/8, which Apple owns outright. The IP comes from the change above, so it can't be faked.
    • The flag is stored on each open; analytics doesn't read it yet (the entity comment and README now say so).
  • Eligibility query:
    • RecipientRepository.findEligibleForCampaign returns, in one query, the active recipients of the campaign's lists whose address isn't suppressed.
    • Each address appears once, even across lists or with different case (the lowest id wins), ordered by id.
    • CampaignSendingService drops three dependencies it no longer needs.
  • Temporary passwords:
    • New TemporaryPasswords: 16 SecureRandom characters from an alphabet without look-alikes (about 93 bits).
    • Migration V4__temp_password_expiry.sql adds users.temp_password_expires_at. Invites set it to 7 days, admin resets to 24 hours; null means no expiry, which covers the seeded admin.
    • Login refuses an expired temporary password with 401 "Temporary password has expired. Ask an administrator for a new one." It's checked only after the password matches, and doesn't count as a failed attempt.
    • Change-password and reset-password clear the expiry.
    • The invite and reset emails say how long the password lasts.
  • README: documents the expiry, the Apple flag, and the proxy note below.

Deploy notes

  • V4 runs at startup.
  • If your reverse proxy or load balancer reaches the app from a public IP, Tomcat won't trust its X-Forwarded-For, and opens and clicks will be recorded with the proxy's IP. Add the proxy's address to server.tomcat.remoteip.internal-proxies.

Testing

  • ./gradlew test integrationTest scaleTest pass locally (474 tests).
  • Unit tests:
    • Apple detection: addresses in and at the edges of 17.0.0.0/8 are flagged; neighbours, IPv6, null and malformed input aren't.
    • Temporary passwords: length, alphabet, no repeats, and the validity text for the emails.
    • Login: an expired temporary password is refused without a failed attempt, a wrong one still gets the generic message, an unexpired one and one with no expiry log in.
    • Invite and admin reset set the new format and the right expiry; change and reset clear it.
  • Integration tests:
    • One send across two lists: a recipient in both is queued once; a suppressed one (case differs from the suppression entry) and an unsubscribed one are left out; of two spellings of one address, the older is queued.
    • An open with a forged X-Forwarded-For records the connection's IP; an open from 17.58.63.1 is flagged as the Apple proxy.

…xpiring temp passwords

- Tracking records request.getRemoteAddr() (resolved by Tomcat's RemoteIpValve) instead of
  reading X-Forwarded-For, which anyone could forge.
- Apple Mail Privacy Protection opens are flagged by Apple's network, 17.0.0.0/8; the
  User-Agent check never matched Apple's proxy.
- Sending collects eligible recipients in one query instead of one suppression lookup per
  list member.
- Temporary passwords are 16 SecureRandom characters and expire (V4): 7 days for invites,
  24 hours for admin resets. Login refuses expired ones; changing or resetting clears it.
@op-techy
op-techy merged commit a1c9b7b into main Dec 4, 2026
2 checks passed
@op-techy
op-techy deleted the fix/minor-audit-items branch December 4, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant