From 99882bb80a1c9e5bf837aea9221160bdaeb90a97 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 21 May 2026 23:54:55 +0300 Subject: [PATCH] Restrict readerEmail to allowlisted domains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents the form being abused as an open email relay to arbitrary addresses (which is the realistic abuse vector — disk fill, server compromise, and device exploitation are all bounded already). Default allowlist: kindle.com, pbsync.com. Suffix matching so subdomains (e.g. free.kindle.com) are also accepted. Configurable via ALLOWED_READER_DOMAINS env var so the list can be extended without code changes. --- .env.example | 6 ++++++ README.md | 10 ++++++---- public/index.html | 7 ++++++- src/app.ts | 36 ++++++++++++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 930dbab..2121e02 100644 --- a/.env.example +++ b/.env.example @@ -8,3 +8,9 @@ SMTP_PORT=587 SMTP_USER=resend SMTP_PASSWORD= MAIL_FROM=send@read.atanasov.fi + +# Comma-separated list of allowed destination email domains. Anything that +# doesn't match (suffix-wise, so subdomains like free.kindle.com count) is +# rejected with a 400. This prevents the app from being abused as an open +# email relay to arbitrary addresses. +ALLOWED_READER_DOMAINS=kindle.com,pbsync.com diff --git a/README.md b/README.md index c3261ce..5e59217 100644 --- a/README.md +++ b/README.md @@ -20,15 +20,16 @@ Two ways to send something to your e-reader: ## Supported devices -Any device that accepts files via email works — the app doesn't restrict by domain. +The destination email domain is checked against an allowlist (default: `kindle.com`, `pbsync.com`) to prevent the app being used as an open email relay. Subdomains count, so `free.kindle.com` works too. | Device | Email pattern | |---|---| -| Amazon Kindle | `*@kindle.com` | +| Amazon Kindle | `*@kindle.com` (or `*.kindle.com` subdomains) | | PocketBook | `*@pbsync.com` | -| Anything else | whatever address your device gives you | -You'll need to add the **sender** address (the Gmail account this app sends from) to your device's approved-senders list — that's a one-time per-device setup. +You can extend the list via the `ALLOWED_READER_DOMAINS` env var (see below). + +You'll also need to add the **sender** address to your device's approved-senders list — one-time per device. ## Prerequisites @@ -63,6 +64,7 @@ npm run start | `SMTP_USER` | yes | — | For Resend, literally the string `resend` | | `SMTP_PASSWORD` | yes | — | For Resend, your API key (`re_…`) | | `MAIL_FROM` | yes | — | Sender address, e.g. `read@atanasov.fi`. Must be from a verified domain on your provider. | +| `ALLOWED_READER_DOMAINS` | no | `kindle.com,pbsync.com` | Comma-separated allowlist of destination email domains. Suffix-matching, so subdomains are allowed. | | `PORT` | no | `3000` | Listen port | ## Resend setup (quick) diff --git a/public/index.html b/public/index.html index 758c190..17f3a86 100644 --- a/public/index.html +++ b/public/index.html @@ -260,7 +260,12 @@

notes: