Skip to content

Close click-tracking open redirect; add rate limits; use the PRD's Bucket4j, Caffeine and MaxMind GeoIP2 - #15

Merged
op-techy merged 2 commits into
mainfrom
fix/security-and-prd-libraries
Dec 3, 2026
Merged

op-techy merged 2 commits into
mainfrom
fix/security-and-prd-libraries

Conversation

@op-techy

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

Copy link
Copy Markdown
Owner

Fixes the issues from the last review and brings the libraries in line with the PRD. Also includes the README refresh.

Security

  • Open redirect in click tracking. GET /track/click/{token}?t=… redirected to any URL encoded in t, even for unknown tokens, and fell back to mailengine.com (a domain we don't own). Anyone could make a link on our domain that lands on a phishing page, and could record fake clicks. Now the server redirects only to a link that is in that recipient's sent email; otherwise 404, with nothing recorded.
  • Rate limits on the public auth endpoints (Bucket4j, per client IP, 429 + Retry-After):
    • login: 20 per minute. The per-account lockout already stopped password guessing on one account; this stops one client trying many accounts, or keeping someone else's account locked.
    • forgot-password, reset-password, verify-email: 10 per hour.
    • In addition, at most 3 reset emails per address per hour, so an inbox can't be flooded from many IPs. The answer stays the same either way (no account enumeration).
    • The client IP is getRemoteAddr(), which Tomcat resolves from X-Forwarded-For only behind trusted proxies, so a client can't fake it.

PRD libraries

Library PRD purpose Now
Bucket4j Control how fast the worker sends The worker sends at most SEND_RATE_PER_SECOND (default 14, SES's default limit; 1 in the sandbox; 0 = off). Waiting is interruptible: on shutdown the rest of the batch is handed back.
Caffeine + cache starter Cache analytics queries @EnableCaching; the 5 campaign analytics queries and engagement scores are cached for ANALYTICS_CACHE_TTL (default 60 s), and a score refresh clears its cache.
MaxMind GeoIP2 Offline IP → location Replaces IPinfo. Reads a GeoLite2/GeoIP2 City (or Country) database from GEOIP_DATABASE_PATH. Optional: without it, events are stored without location, as before without an IPinfo token. Private addresses and host names are never looked up (no DNS).
AWS SNS / STS — The SNS SDK module is removed: SES events arrive from SNS over HTTP and SnsMessageVerifier checks them. STS stays: the default credentials chain needs it for IAM roles (web identity / EKS, role_arn profiles); a comment says so.

⚠️ To deploy

  • IPINFO_TOKEN is no longer read. For locations, download GeoLite2 City (free MaxMind account), mount it, and set GEOIP_DATABASE_PATH. The file can't be committed (MaxMind licence); geoipupdate keeps it current. See the README section "IP geolocation".
  • Set SEND_RATE_PER_SECOND to your provider's limit if it isn't 14.
  • Limits and cache are in memory, per app instance (as is the existing import recovery).

Also

  • AuthController.register javadoc no longer describes the removed account creation.
  • README brought in line with the code: Docker and CI, project structure, Postgres 15+ database setup, all tables, deletion rules, three test suites, mock email log, retry schedule, limits, cache and geolocation. .env.example lists the new settings.

Testing

  • New: AuthRateLimitFilterTest, GeoIpServiceTest (MaxMind reader mocked; GeoLite2 files need a licence key), the worker's rate cap and interrupted hand-back, the per-address reset limit, the click redirect (followed only for links in the email; 404 otherwise, no fake clicks) and the analytics cache in SweepFixesIntegrationTest.
  • Unit 366/366, integration 40/40, scale 9/9.
  • Docker image built; the end-to-end sweep passed 71/71, with new checks: unknown click token gives 404, cached analytics, a login burst gives 429. No ERROR lines in the log.

- Remove claims of Caffeine caching and Bucket4j rate limiting (neither is used).
- Add Docker and CI: Dockerfile usage, docker run, CI workflow, Docker prerequisite.
- Fix the project structure (no service/email package; security, util, worker contents).
- Database setup that works on PostgreSQL 15+ (database owned by the app user).
- Complete key tables, deletion rules (409 when in use, list uploads cascade).
- Three test suites, not two; mock email log now shows text and links.
- Correct retry schedule, analytics delivered fallback, engagement recency input.
- Document disabled /register, hashed one-time tokens, test-send validation.
- Example migration is V2 after the squash.
…eine and MaxMind GeoIP2

Security
- /track/click only redirects to a link that is in that recipient's email (the
  sent HTML is checked); unknown tokens or other URLs get 404 and record nothing.
- Per-IP rate limits (Bucket4j) on login (20/min) and forgot/reset-password and
  verify-email (10/h), answering 429 with Retry-After; at most 3 reset emails per
  address per hour.

PRD libraries
- Bucket4j caps the send worker at app.sending.rate-per-second (default 14, SES's
  default limit); an interrupted worker hands the rest of its batch back.
- Caffeine caches the analytics queries and engagement scores
  (app.analytics.cache-ttl, default 60s); a score refresh clears its cache.
- MaxMind GeoIP2 replaces IPinfo: offline lookups from a GeoLite2/GeoIP2
  database file (GEOIP_DATABASE_PATH), optional; private addresses and host
  names are never looked up.
- Drop the unused SNS SDK module; keep STS (needed by the credentials chain for
  IAM roles) with a comment saying why.

Also: register endpoint javadoc no longer describes removed account creation;
README brought in line with the code (Docker, CI, tables, limits, geolocation).
@op-techy
op-techy merged commit 83c2cf1 into main Dec 3, 2026
2 checks passed
@op-techy
op-techy deleted the fix/security-and-prd-libraries branch December 3, 2026 00:58
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