Email for professionals and teams
fix(security): verify SPF/DKIM/DMARC on self-hosted SMTP and refuse unknown recipient domains (#215)
Hieu Nguyen (Jack)36b3bed8ea4d
diff --git a/docs/security.md b/docs/security.mdindex 5bdfd72..fad69b9 100644--- a/docs/security.md+++ b/docs/security.md@@ -16,12 +16,14 @@ or its mailbox is disabled; they also expire on their own.header Cloudflare writes (authserv-id `mx.cloudflare.net`). A failure in any such clausewins over a pass.* SES and Resend receiving: the provider's own verdicts are used.-* Self-hosted SMTP: the listener verifies nothing, so no authentication signal exists and- the DMARC/SPF/DKIM policy does not apply. Put a verifying filter in front of it or receive- through a provider.+* Self-hosted SMTP: the listener verifies SPF, DKIM and DMARC itself (with `mailauth`,+ using the connecting IP and the envelope sender) and feeds the results to the same+ policy. If DNS cannot answer within 10 seconds the mail carries no authentication+ signal and is delivered as before.Sender-written `Authentication-Results`, `Received-SPF` and `Received` headers are never-trusted on the SMTP path.+trusted on the SMTP path. The listener also refuses recipients on domains Mailflare does not+manage before accepting DATA.## Webhooksdiff --git a/package-lock.json b/package-lock.jsonindex 35f9ae7..70888a9 100644--- a/package-lock.json+++ b/package-lock.json@@ -36,6 +36,7 @@"dayjs": "^1.11.20","dompurify": "^3.4.16","drizzle-orm": "^0.45.2",+ "mailauth": "^4.13.3","mimetext": "^3.0.28","mysql2": "^3.24.6","nanoid": "^5.1.16",@@ -597,7 +598,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -614,7 +614,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -631,7 +630,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -648,7 +646,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -665,7 +662,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -2111,6 +2107,54 @@"version": "0.2.11","license": "MIT"},+ "node_modules/@hapi/address": {+ "version": "5.1.1",+ "resolved": "https://registry.npmjs.org/@hapi/address/-/address-5.1.1.tgz",+ "integrity": "sha512-A+po2d/dVoY7cYajycYI43ZbYMXukuopIsqCjh5QzsBCipDtdofHntljDlpccMjIfTy6UOkg+5KPriwYch2bXA==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "@hapi/hoek": "^11.0.2"+ },+ "engines": {+ "node": ">=14.0.0"+ }+ },+ "node_modules/@hapi/formula": {+ "version": "3.0.2",+ "resolved": "https://registry.npmjs.org/@hapi/formula/-/formula-3.0.2.tgz",+ "integrity": "sha512-hY5YPNXzw1He7s0iqkRQi+uMGh383CGdyyIGYtB+W5N3KHPXoqychklvHhKCC9M3Xtv0OCs/IHw+r4dcHtBYWw==",+ "license": "BSD-3-Clause"+ },+ "node_modules/@hapi/hoek": {+ "version": "11.0.7",+ "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-11.0.7.tgz",+ "integrity": "sha512-HV5undWkKzcB4RZUusqOpcgxOaq6VOAH7zhhIr2g3G8NF/MlFO75SjOr2NfuSx0Mh40+1FqCkagKLJRykUWoFQ==",+ "license": "BSD-3-Clause"+ },+ "node_modules/@hapi/pinpoint": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/@hapi/pinpoint/-/pinpoint-2.0.1.tgz",+ "integrity": "sha512-EKQmr16tM8s16vTT3cA5L0kZZcTMU5DUOZTuvpnY738m+jyP3JIUj+Mm1xc1rsLkGBQ/gVnfKYPwOmPg1tUR4Q==",+ "license": "BSD-3-Clause"+ },+ "node_modules/@hapi/tlds": {+ "version": "1.1.7",+ "resolved": "https://registry.npmjs.org/@hapi/tlds/-/tlds-1.1.7.tgz",+ "integrity": "sha512-MgNjRwy9Ti92yVAixLmDc8dd1bJIKwO9qlWCfFQRwRmUEDPQHYn4G6hwPFvFGUTzAa0FsS+inMjLin7GnyBRhA==",+ "license": "BSD-3-Clause",+ "engines": {+ "node": ">=14.0.0"+ }+ },+ "node_modules/@hapi/topo": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-6.0.2.tgz",+ "integrity": "sha512-KR3rD5inZbGMrHmgPxsJ9dbi6zEK+C3ZwUwTa+eMwWLz7oijWUTWD2pMSNNYJAU6Qq+65NkxXjqHr/7LM2Xkqg==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "@hapi/hoek": "^11.0.2"+ }+ },"node_modules/@hugeicons/core-free-icons": {"version": "4.3.5","resolved": "https://registry.npmjs.org/@hugeicons/core-free-icons/-/core-free-icons-4.3.5.tgz",@@ -3116,6 +3160,18 @@"node": ">= 10"}},+ "node_modules/@nodable/entities": {+ "version": "2.2.0",+ "resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-2.2.0.tgz",+ "integrity": "sha512-9uGyhaQavEUMC8AIddIjau4NsnsXhou+j5sBAGojCM1oxmQpVKTWR/9JxABD6UAv12vpIms55fPZKFQEhG6uBg==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/nodable"+ }+ ],+ "license": "MIT"+ },"node_modules/@nodelib/fs.scandir": {"version": "2.1.5","resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",@@ -4194,6 +4250,41 @@"license": "MIT","optional": true},+ "node_modules/@peculiar/asn1-schema": {+ "version": "2.6.0",+ "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.6.0.tgz",+ "integrity": "sha512-xNLYLBFTBKkCzEZIw842BxytQQATQv+lDTCEMZ8C196iJcJJMBUZxrhSTxLaohMyKK8QlzRNTRkUmanucnDSqg==",+ "license": "MIT",+ "dependencies": {+ "asn1js": "^3.0.6",+ "pvtsutils": "^1.3.6",+ "tslib": "^2.8.1"+ }+ },+ "node_modules/@peculiar/asn1-x509": {+ "version": "2.6.1",+ "resolved": "https://registry.npmjs.org/@peculiar/asn1-x509/-/asn1-x509-2.6.1.tgz",+ "integrity": "sha512-O9jT5F1A2+t3r7C4VT7LYGXqkGLK7Kj1xFpz7U0isPrubwU5PbDoyYtx6MiGst29yq7pXN5vZbQFKRCP+lLZlA==",+ "license": "MIT",+ "dependencies": {+ "@peculiar/asn1-schema": "^2.6.0",+ "asn1js": "^3.0.6",+ "pvtsutils": "^1.3.6",+ "tslib": "^2.8.1"+ }+ },+ "node_modules/@peculiar/asn1-x509-logotype": {+ "version": "2.6.1",+ "resolved": "https://registry.npmjs.org/@peculiar/asn1-x509-logotype/-/asn1-x509-logotype-2.6.1.tgz",+ "integrity": "sha512-VJV5Azg0M8TMAZfE5pB9eQOLXxc/9sGS08kVJhMQYv7dB2YBwiasp/GRZIuit+0t4Sr9FnoEpwwXAHXOlLdMnA==",+ "license": "MIT",+ "dependencies": {+ "@peculiar/asn1-schema": "^2.6.0",+ "@peculiar/asn1-x509": "^2.6.1",+ "asn1js": "^3.0.6",+ "tslib": "^2.8.1"+ }+ },"node_modules/@planetscale/database": {"version": "2.0.0","resolved": "https://registry.npmjs.org/@planetscale/database/-/database-2.0.0.tgz",@@ -4239,6 +4330,17 @@"devOptional": true,"license": "MIT"},+ "node_modules/@postalsys/vmc": {+ "version": "1.1.4",+ "resolved": "https://registry.npmjs.org/@postalsys/vmc/-/vmc-1.1.4.tgz",+ "integrity": "sha512-nz7xaISzluVKjmiDVFIPP8A0IVo6exjRuJ5QXeBnl5UiaRnIBQlw56PHYDNJ6xnsHSfb+iaLb6V2F/CEhJLdPA==",+ "license": "MIT",+ "dependencies": {+ "@peculiar/asn1-schema": "2.6.0",+ "@peculiar/asn1-x509": "2.6.1",+ "@peculiar/asn1-x509-logotype": "2.6.1"+ }+ },"node_modules/@radix-ui/number": {"version": "1.1.1","license": "MIT"@@ -6984,6 +7086,18 @@"url": "https://github.com/chalk/ansi-styles?sponsor=1"}},+ "node_modules/anynum": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.1.tgz",+ "integrity": "sha512-N6//FLET/tXYNM/F6ABca1oH6fWB+KlTt909Le28WMDBk8oaT4vY17DCrwg2MvmuqUKt3Ni4N5dGJ/EoBgcO6A==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT"+ },"node_modules/argparse": {"version": "2.0.1","resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",@@ -7141,6 +7255,20 @@"url": "https://github.com/sponsors/ljharb"}},+ "node_modules/asn1js": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.1.0.tgz",+ "integrity": "sha512-HWYi1THkOqguCiO+vwj09ZkQFD2kKEsejYHAYCtX0D80WVdoDnvRc9IukXX/jeb0T9NRWJnRtqwdbHltnFjwXA==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "pvtsutils": "^1.3.6",+ "pvutils": "^1.2.0",+ "tslib": "^2.8.1"+ },+ "engines": {+ "node": ">=12.0.0"+ }+ },"node_modules/assertion-error": {"version": "2.0.1","resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",@@ -7522,6 +7650,20 @@"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==","license": "MIT"},+ "node_modules/cliui": {+ "version": "8.0.1",+ "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",+ "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",+ "license": "ISC",+ "dependencies": {+ "string-width": "^4.2.0",+ "strip-ansi": "^6.0.1",+ "wrap-ansi": "^7.0.0"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/clsx": {"version": "2.1.1","resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",@@ -8568,6 +8710,12 @@"version": "1.5.416","license": "ISC"},+ "node_modules/emoji-regex": {+ "version": "8.0.0",+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",+ "license": "MIT"+ },"node_modules/emoji-regex-xs": {"version": "2.0.1","resolved": "https://registry.npmjs.org/emoji-regex-xs/-/emoji-regex-xs-2.0.1.tgz",@@ -8577,6 +8725,15 @@"node": ">=10.0.0"}},+ "node_modules/encoding-japanese": {+ "version": "2.2.0",+ "resolved": "https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-2.2.0.tgz",+ "integrity": "sha512-EuJWwlHPZ1LbADuKTClvHtwbaFn4rOD+dRAbWysqEOXRc2Uui0hJInNJrsdH0c+OhJA4nrCBdSkW4DD5YxAo6A==",+ "license": "MIT",+ "engines": {+ "node": ">=8.10.0"+ }+ },"node_modules/enhanced-resolve": {"version": "5.25.1","resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.25.1.tgz",@@ -9232,6 +9389,43 @@"license": "BSD-3-Clause","peer": true},+ "node_modules/fast-xml-builder": {+ "version": "1.3.1",+ "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.3.1.tgz",+ "integrity": "sha512-pIM/1n3ntFXKYrUZwW7QCK0gAW7XY+wzj1YMIV3tLDvPj/V+zTGJK5e3/4WJfwj0qWw2ElNXiTixda/R+3YSug==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT",+ "dependencies": {+ "path-expression-matcher": "^1.6.2",+ "xml-naming": "^0.3.0"+ }+ },+ "node_modules/fast-xml-parser": {+ "version": "5.7.3",+ "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.7.3.tgz",+ "integrity": "sha512-C0AaNuC+mscy6vrAQKAc/rMq+zAPHodfHGZu4sGVehvAQt/JLG1O5zEcYcXSY5zSqr4YVgxsB+pHXTq0i7eDlg==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT",+ "dependencies": {+ "@nodable/entities": "^2.1.0",+ "fast-xml-builder": "^1.1.7",+ "path-expression-matcher": "^1.5.0",+ "strnum": "^2.2.3"+ },+ "bin": {+ "fxparser": "src/cli/cli.js"+ }+ },"node_modules/fastq": {"version": "1.20.3","resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz",@@ -9853,6 +10047,15 @@"node": ">= 0.4"}},+ "node_modules/ipaddr.js": {+ "version": "2.4.0",+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.4.0.tgz",+ "integrity": "sha512-9VGk3HGanVE6JoZXHiCpnGy5X0jYDnN4EA4lntFPj+1vIWlFhIylq2CrrCOJH9EAhc5CYhq18F2Av2tgoAPsYQ==",+ "license": "MIT",+ "engines": {+ "node": ">= 10"+ }+ },"node_modules/ipv6-normalize": {"version": "1.0.1","resolved": "https://registry.npmjs.org/ipv6-normalize/-/ipv6-normalize-1.0.1.tgz",@@ -10390,6 +10593,24 @@"jiti": "lib/jiti-cli.mjs"}},+ "node_modules/joi": {+ "version": "18.2.1",+ "resolved": "https://registry.npmjs.org/joi/-/joi-18.2.1.tgz",+ "integrity": "sha512-2/OKlogiESf2Nh3TFCrRjrr9z1DRHeW0I+KReF67+4J0Ns+8hBtHRmoWAZ2OFU6I5+TWLEe6sVlSdXPjHm5UbQ==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "@hapi/address": "^5.1.1",+ "@hapi/formula": "^3.0.2",+ "@hapi/hoek": "^11.0.7",+ "@hapi/pinpoint": "^2.0.1",+ "@hapi/tlds": "^1.1.1",+ "@hapi/topo": "^6.0.2",+ "@standard-schema/spec": "^1.1.0"+ },+ "engines": {+ "node": ">= 20"+ }+ },"node_modules/js-base64": {"version": "3.7.8","license": "BSD-3-Clause"@@ -10585,6 +10806,46 @@"node": ">= 0.8.0"}},+ "node_modules/libbase64": {+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/libbase64/-/libbase64-1.3.0.tgz",+ "integrity": "sha512-GgOXd0Eo6phYgh0DJtjQ2tO8dc0IVINtZJeARPeiIJqge+HdsWSuaDTe8ztQ7j/cONByDZ3zeB325AHiv5O0dg==",+ "license": "MIT"+ },+ "node_modules/libmime": {+ "version": "5.3.8",+ "resolved": "https://registry.npmjs.org/libmime/-/libmime-5.3.8.tgz",+ "integrity": "sha512-ZrCY+Q66mPvasAfjsQ/IgahzoBvfE1VdtGRpo1hwRB1oK3wJKxhKA3GOcd2a6j7AH5eMFccxK9fBoCpRZTf8ng==",+ "license": "MIT",+ "dependencies": {+ "encoding-japanese": "2.2.0",+ "iconv-lite": "0.7.2",+ "libbase64": "1.3.0",+ "libqp": "2.1.1"+ }+ },+ "node_modules/libmime/node_modules/iconv-lite": {+ "version": "0.7.2",+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",+ "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",+ "license": "MIT",+ "dependencies": {+ "safer-buffer": ">= 2.1.2 < 3.0.0"+ },+ "engines": {+ "node": ">=0.10.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/express"+ }+ },+ "node_modules/libqp": {+ "version": "2.1.1",+ "resolved": "https://registry.npmjs.org/libqp/-/libqp-2.1.1.tgz",+ "integrity": "sha512-0Wd+GPz1O134cP62YU2GTOPNA7Qgl09XwCqM5zpBv87ERCXdfDtyKXvV7c9U22yWJh44QZqBocFnXN11K96qow==",+ "license": "MIT"+ },"node_modules/libsql": {"version": "0.5.29","resolved": "https://registry.npmjs.org/libsql/-/libsql-0.5.29.tgz",@@ -10993,6 +11254,60 @@"@jridgewell/sourcemap-codec": "^1.5.5"}},+ "node_modules/mailauth": {+ "version": "4.13.3",+ "resolved": "https://registry.npmjs.org/mailauth/-/mailauth-4.13.3.tgz",+ "integrity": "sha512-OdusE4urklIQn4eIie7+B7KMenp5y98SCx97TaK+UmMgjwYmy3G+yihJ/b2GSRlOT5cdUqS4SZYhqByzGRbv+A==",+ "license": "MIT",+ "dependencies": {+ "@postalsys/vmc": "1.1.4",+ "fast-xml-parser": "5.7.3",+ "ipaddr.js": "2.4.0",+ "joi": "18.2.1",+ "libmime": "5.3.8",+ "nodemailer": "8.0.7",+ "punycode.js": "2.3.1",+ "tldts": "7.0.30",+ "undici": "7.25.0",+ "yargs": "17.7.2"+ },+ "bin": {+ "mailauth": "bin/mailauth.js"+ },+ "engines": {+ "node": ">=20.18.1"+ }+ },+ "node_modules/mailauth/node_modules/nodemailer": {+ "version": "8.0.7",+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.7.tgz",+ "integrity": "sha512-pkjE4mkBzQjdJT4/UmlKl3pX0rC9fZmjh7c6C9o7lv66Ac6w9WCnzPzhbPNxwZAzlF4mdq4CSWB5+FbK6FWCow==",+ "license": "MIT-0",+ "engines": {+ "node": ">=6.0.0"+ }+ },+ "node_modules/mailauth/node_modules/tldts": {+ "version": "7.0.30",+ "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.0.30.tgz",+ "integrity": "sha512-ELrFxuqsDdHUwoh0XxDbxuLD3Wnz49Z57IFvTtvWy1hJdcMZjXLIuonjilCiWHlT2GbE4Wlv1wKVTzDFnXH1aw==",+ "license": "MIT",+ "dependencies": {+ "tldts-core": "^7.0.30"+ },+ "bin": {+ "tldts": "bin/cli.js"+ }+ },+ "node_modules/mailauth/node_modules/undici": {+ "version": "7.25.0",+ "resolved": "https://registry.npmjs.org/undici/-/undici-7.25.0.tgz",+ "integrity": "sha512-xXnp4kTyor2Zq+J1FfPI6Eq3ew5h6Vl0F/8d9XU5zZQf1tX9s2Su1/3PiMmUANFULpmksxkClamIZcaUqryHsQ==",+ "license": "MIT",+ "engines": {+ "node": ">=20.18.1"+ }+ },"node_modules/markdown-table": {"version": "3.0.4","resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-3.0.4.tgz",@@ -11977,7 +12292,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12000,7 +12314,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12020,7 +12333,6 @@"version": "0.35.4","resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.4.tgz","integrity": "sha512-lIsKw/BU+kjB4eZjxrYrZmwOJYi3Ajrv66iAlBmUPyKc3HpnloevB1g3wxGD9P/5BbQ1brBGl65VRRrCvQDEqA==",- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12043,7 +12355,6 @@"cpu": ["arm64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12060,7 +12371,6 @@"cpu": ["x64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12077,7 +12387,6 @@"cpu": ["arm"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12094,7 +12403,6 @@"cpu": ["arm64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12111,7 +12419,6 @@"cpu": ["ppc64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12128,7 +12435,6 @@"cpu": ["riscv64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12145,7 +12451,6 @@"cpu": ["s390x"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12162,7 +12467,6 @@"cpu": ["x64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12179,7 +12483,6 @@"cpu": ["arm64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12196,7 +12499,6 @@"cpu": ["x64"],- "dev": true,"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -12213,7 +12515,6 @@"cpu": ["arm"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12236,7 +12537,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12259,7 +12559,6 @@"cpu": ["ppc64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12282,7 +12581,6 @@"cpu": ["riscv64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12305,7 +12603,6 @@"cpu": ["s390x"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12328,7 +12625,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12351,7 +12647,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12374,7 +12669,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0","optional": true,"os": [@@ -12394,7 +12688,6 @@"version": "0.35.4","resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.4.tgz","integrity": "sha512-zQnl4Kwp7Q6NHsENtU2T/00Zi+w3AQNwz3+UaTyVBy2FpXrzXzGjndpK61onhZjRtRpQXxCTeqw19bVyXOh7jA==",- "dev": true,"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT","optional": true,"dependencies": {@@ -12414,7 +12707,6 @@"cpu": ["wasm32"],- "dev": true,"license": "Apache-2.0","optional": true,"dependencies": {@@ -12434,7 +12726,6 @@"cpu": ["arm64"],- "dev": true,"license": "Apache-2.0 AND LGPL-3.0-or-later","optional": true,"os": [@@ -12454,7 +12745,6 @@"cpu": ["ia32"],- "dev": true,"license": "Apache-2.0 AND LGPL-3.0-or-later","optional": true,"os": [@@ -12474,7 +12764,6 @@"cpu": ["x64"],- "dev": true,"license": "Apache-2.0 AND LGPL-3.0-or-later","optional": true,"os": [@@ -13133,6 +13422,21 @@"node": ">=8"}},+ "node_modules/path-expression-matcher": {+ "version": "1.6.2",+ "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.6.2.tgz",+ "integrity": "sha512-enSlaiat05iasnzmgNxRj8reFdj3puY2QpNgP1aPIaVfT6nn9ICuPoFlKHk8EN22HcwewshO+mN2DGbkCEOtqQ==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT",+ "engines": {+ "node": ">=14.0.0"+ }+ },"node_modules/path-key": {"version": "3.1.1","resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",@@ -13484,6 +13788,24 @@"node": ">=6"}},+ "node_modules/pvtsutils": {+ "version": "1.3.6",+ "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.6.tgz",+ "integrity": "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==",+ "license": "MIT",+ "dependencies": {+ "tslib": "^2.8.1"+ }+ },+ "node_modules/pvutils": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.2.0.tgz",+ "integrity": "sha512-BbubeCEyTuQjVMakvJQ/Sxbc93F2pwmbsxONT/ZRrwU7Ua38d8unYTwXpTVLAKJ4BDuH9IGztCjQcd/N/39Dvg==",+ "license": "MIT",+ "engines": {+ "node": ">=16.0.0"+ }+ },"node_modules/qrcode": {"version": "1.5.4","resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",@@ -13527,12 +13849,6 @@"wrap-ansi": "^6.2.0"}},- "node_modules/qrcode/node_modules/emoji-regex": {- "version": "8.0.0",- "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",- "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",- "license": "MIT"- },"node_modules/qrcode/node_modules/find-up": {"version": "4.1.0","resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",@@ -13585,20 +13901,6 @@"node": ">=8"}},- "node_modules/qrcode/node_modules/string-width": {- "version": "4.2.3",- "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",- "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",- "license": "MIT",- "dependencies": {- "emoji-regex": "^8.0.0",- "is-fullwidth-code-point": "^3.0.0",- "strip-ansi": "^6.0.1"- },- "engines": {- "node": ">=8"- }- },"node_modules/qrcode/node_modules/wrap-ansi": {"version": "6.2.0","resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",@@ -14607,6 +14909,20 @@"node": ">= 0.4"}},+ "node_modules/string-width": {+ "version": "4.2.3",+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",+ "license": "MIT",+ "dependencies": {+ "emoji-regex": "^8.0.0",+ "is-fullwidth-code-point": "^3.0.0",+ "strip-ansi": "^6.0.1"+ },+ "engines": {+ "node": ">=8"+ }+ },"node_modules/string.prototype.codepointat": {"version": "0.2.1","resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.1.tgz",@@ -14766,6 +15082,21 @@"devOptional": true,"license": "MIT"},+ "node_modules/strnum": {+ "version": "2.5.1",+ "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.5.1.tgz",+ "integrity": "sha512-UM4nTLWzQiDBseVxUGxN0wJzIk0UU89Qi7pKXz9qISo+lhviJikTuikBsK/oFRlpvYHvSdz0TVoLyQ+sEpYwxA==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT",+ "dependencies": {+ "anynum": "^1.0.1"+ }+ },"node_modules/style-to-js": {"version": "1.1.21","resolved": "https://registry.npmjs.org/style-to-js/-/style-to-js-1.1.21.tgz",@@ -14966,7 +15297,6 @@"version": "7.4.16","resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.4.16.tgz","integrity": "sha512-MDolfaSJtlSK5Y0A1xl3277ekubZwobpBjugknDizI9O5Rm60a1m8k4ICK+MRsCDzPygT81mp3BBf5RKDlFRfA==",- "dev": true,"license": "MIT"},"node_modules/to-regex-range": {@@ -15710,18 +16040,6 @@}}},- "node_modules/vite-plus/node_modules/@types/node": {- "version": "26.6.5",- "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.5.tgz",- "integrity": "sha512-uMzsv9stDdofIZBx4UGh4Z9ZgXnGC9seRDscilBcTHAeOFk67MZg/k9bWVfO+bk4qZmG+l52hRnLwUiH2LnJTg==",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true,- "dependencies": {- "undici-types": "~8.9.0"- }- },"node_modules/vite-plus/node_modules/@vitest/browser": {"version": "5.0.1","resolved": "https://registry.npmjs.org/@vitest/browser/-/browser-5.0.1.tgz",@@ -15927,15 +16245,6 @@"node": ">=14.19.0"}},- "node_modules/vite-plus/node_modules/undici-types": {- "version": "8.9.0",- "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz",- "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true- },"node_modules/vite-plus/node_modules/vitest": {"version": "5.0.1","resolved": "https://registry.npmjs.org/vitest/-/vitest-5.0.1.tgz",@@ -16681,7 +16990,6 @@"cpu": ["ppc64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16698,7 +17006,6 @@"cpu": ["arm"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16715,7 +17022,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16732,7 +17038,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16749,7 +17054,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16766,7 +17070,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16783,7 +17086,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16800,7 +17102,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16817,7 +17118,6 @@"cpu": ["arm"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16834,7 +17134,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16851,7 +17150,6 @@"cpu": ["ia32"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16868,7 +17166,6 @@"cpu": ["loong64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16885,7 +17182,6 @@"cpu": ["mips64el"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16902,7 +17198,6 @@"cpu": ["ppc64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16919,7 +17214,6 @@"cpu": ["riscv64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16936,7 +17230,6 @@"cpu": ["s390x"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16953,7 +17246,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16970,7 +17262,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -16987,7 +17278,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17004,7 +17294,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17021,7 +17310,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17038,7 +17326,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17055,7 +17342,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17072,7 +17358,6 @@"cpu": ["arm64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17089,7 +17374,6 @@"cpu": ["ia32"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17106,7 +17390,6 @@"cpu": ["x64"],- "dev": true,"license": "MIT","optional": true,"os": [@@ -17158,6 +17441,38 @@"@esbuild/win32-x64": "0.28.1"}},+ "node_modules/wrap-ansi": {+ "version": "7.0.0",+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",+ "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",+ "license": "MIT",+ "dependencies": {+ "ansi-styles": "^4.0.0",+ "string-width": "^4.1.0",+ "strip-ansi": "^6.0.0"+ },+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/chalk/wrap-ansi?sponsor=1"+ }+ },+ "node_modules/wrap-ansi/node_modules/ansi-styles": {+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",+ "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",+ "license": "MIT",+ "dependencies": {+ "color-convert": "^2.0.1"+ },+ "engines": {+ "node": ">=8"+ },+ "funding": {+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"+ }+ },"node_modules/ws": {"version": "8.21.0","resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",@@ -17189,6 +17504,21 @@"node": ">=18"}},+ "node_modules/xml-naming": {+ "version": "0.3.0",+ "resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.3.0.tgz",+ "integrity": "sha512-ghig2TBE/H11aOVgmahA3MhimvkBr6JIYknH/Dhdk10nXwdbIqBJsbfMxpvFPG8bAw77gN29aQWvKpmVoPlvPQ==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/NaturalIntelligence"+ }+ ],+ "license": "MIT",+ "engines": {+ "node": ">=16.0.0"+ }+ },"node_modules/xmlchars": {"version": "2.2.0","resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",@@ -17205,6 +17535,15 @@"node": ">=0.4"}},+ "node_modules/y18n": {+ "version": "5.0.8",+ "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",+ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",+ "license": "ISC",+ "engines": {+ "node": ">=10"+ }+ },"node_modules/yallist": {"version": "3.1.1","resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",@@ -17212,6 +17551,33 @@"dev": true,"license": "ISC"},+ "node_modules/yargs": {+ "version": "17.7.2",+ "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",+ "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",+ "license": "MIT",+ "dependencies": {+ "cliui": "^8.0.1",+ "escalade": "^3.1.1",+ "get-caller-file": "^2.0.5",+ "require-directory": "^2.1.1",+ "string-width": "^4.2.3",+ "y18n": "^5.0.5",+ "yargs-parser": "^21.1.1"+ },+ "engines": {+ "node": ">=12"+ }+ },+ "node_modules/yargs-parser": {+ "version": "21.1.1",+ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",+ "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",+ "license": "ISC",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/yocto-queue": {"version": "0.1.0","resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",diff --git a/package.json b/package.jsonindex a1fe163..7eb4e97 100644--- a/package.json+++ b/package.json@@ -88,6 +88,7 @@"dayjs": "^1.11.20","dompurify": "^3.4.16","drizzle-orm": "^0.45.2",+ "mailauth": "^4.13.3","mimetext": "^3.0.28","mysql2": "^3.24.6","nanoid": "^5.1.16",diff --git a/scripts/build-server.mjs b/scripts/build-server.mjsindex 8359f9c..ae49833 100644--- a/scripts/build-server.mjs+++ b/scripts/build-server.mjs@@ -13,7 +13,7 @@ await build({sourcemap: true,tsconfig: "tsconfig.json",external: [- "next", "better-sqlite3", "nodemailer", "smtp-server", "ws", "react", "react-dom",+ "next", "better-sqlite3", "nodemailer", "smtp-server", "mailauth", "ws", "react", "react-dom",// Database drivers, loaded only when DATABASE_URL selects them."pg", "postgres", "mysql2", "@libsql/client", "@neondatabase/serverless", "@planetscale/database", "@electric-sql/pglite",],diff --git a/server/runtime/smtp-auth.ts b/server/runtime/smtp-auth.tsnew file mode 100644index 0000000..361ea36--- /dev/null+++ b/server/runtime/smtp-auth.ts@@ -0,0 +1,41 @@+import type { ProviderVerdicts } from "@/lib/spam/types";++const AUTH_TIMEOUT_MS = 10_000;++type Result = { status?: { result?: string } } | false | undefined;++function verdict(result: string | undefined): string | undefined {+ if (result === "pass") return "PASS";+ if (result === "fail") return "FAIL";+ return undefined;+}++/**+ * SPF, DKIM and DMARC verified locally for mail that arrived on the SMTP listener, which has no+ * upstream provider to vouch for it. Returns nothing when verification cannot finish, so a DNS+ * outage adds no signal rather than blocking mail.+ */+export async function verifySmtpAuthentication(+ raw: Buffer,+ connection: { ip: string; helo?: string; sender: string; mta?: string },+): Promise<ProviderVerdicts | undefined> {+ try {+ const { authenticate } = await import("mailauth");+ const result = await Promise.race([+ authenticate(raw, { ip: connection.ip, helo: connection.helo, sender: connection.sender, mta: connection.mta, disableArc: true, disableBimi: true }),+ new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Authentication timed out")), AUTH_TIMEOUT_MS)),+ ]);+ const dkimResults = ((result.dkim as { results?: { status?: { result?: string } }[] } | undefined)?.results ?? []).map((entry) => entry.status?.result);+ const dkim = dkimResults.includes("pass") ? "PASS" : dkimResults.includes("fail") ? "FAIL" : undefined;+ const verdicts: ProviderVerdicts = {};+ const spf = verdict((result.spf as Result) ? (result.spf as { status?: { result?: string } }).status?.result : undefined);+ const dmarc = verdict((result.dmarc as Result) ? (result.dmarc as { status?: { result?: string } }).status?.result : undefined);+ if (spf) verdicts.spf = spf;+ if (dkim) verdicts.dkim = dkim;+ if (dmarc) verdicts.dmarc = dmarc;+ return Object.keys(verdicts).length ? verdicts : undefined;+ } catch (error) {+ console.warn("SMTP authentication check failed", error);+ return undefined;+ }+}diff --git a/server/runtime/smtp.ts b/server/runtime/smtp.tsindex 5e54888..025ae56 100644--- a/server/runtime/smtp.ts+++ b/server/runtime/smtp.ts@@ -4,6 +4,10 @@ import type { SMTPServerSession } from "smtp-server";import { intakeIncomingMail } from "@/lib/email/intake";import { inboundAttachmentLimitReasonFromRaw } from "@/lib/email/inbound-attachments";import { isPublicIpv4 } from "@/lib/spam/domain-utils";+import { getDb } from "@/db";+import { domains } from "@/db/schema";+import { eq } from "drizzle-orm";+import { verifySmtpAuthentication } from "./smtp-auth";import type { Mailer } from "./mailer";const MAX_CLIENTS = 100;@@ -57,7 +61,15 @@ export function startSmtpListener(callback(Object.assign(new Error("Too many recipients"), { responseCode: 452 }));return;}- callback();+ // Refuse unknown domains before DATA so nothing is buffered for mail we would drop anyway.+ const hostname = address.address.slice(address.address.lastIndexOf("@") + 1).toLowerCase();+ getDb(env).select({ id: domains.id }).from(domains).where(eq(domains.hostname, hostname)).limit(1).then(+ ([domain]) => callback(domain ? undefined : Object.assign(new Error("Relay access denied"), { responseCode: 550 })),+ (error) => {+ console.error("SMTP recipient lookup failed", error);+ callback(Object.assign(new Error("Temporary failure, try again later"), { responseCode: 451 }));+ },+ );},name: options.hostname,authOptional: true,@@ -98,11 +110,17 @@ export function startSmtpListener(// No SPF/DKIM/DMARC verification happens here, so anything the sender wrote is untrusted.for (const name of UNTRUSTED_HEADERS) delete headers[name];const senderIp = isPublicIpv4(session.remoteAddress) ? session.remoteAddress : undefined;+ const verdicts = await verifySmtpAuthentication(raw, {+ ip: session.remoteAddress,+ helo: session.hostNameAppearsAs,+ sender: from,+ mta: options.hostname,+ });let rejectReason: string | null = null;for (const recipient of session.envelope.rcptTo) {const result = await intakeIncomingMail(env,- { from, to: recipient.address, raw: toArrayBuffer(raw), headers, senderIp },+ { from, to: recipient.address, raw: toArrayBuffer(raw), headers, senderIp, verdicts },{reject: (reason) => {rejectReason = reason;diff --git a/src/lib/spam/analyzers/authentication.ts b/src/lib/spam/analyzers/authentication.tsindex 6b21fe8..833d888 100644--- a/src/lib/spam/analyzers/authentication.ts+++ b/src/lib/spam/analyzers/authentication.ts@@ -14,8 +14,8 @@ function methodSignal(method: (typeof METHODS)[number], result: string | undefin/*** SPF, DKIM and DMARC results. Verdicts from the receiving provider (SES) win; otherwise only an- * Authentication-Results clause written by Cloudflare is read. Self-hosted SMTP verifies nothing, so- * mail received there carries no authentication signal and the authentication policy never fires.+ * Authentication-Results clause written by Cloudflare is read. Self-hosted SMTP verifies SPF, DKIM+ * and DMARC itself (server/runtime/smtp-auth.ts) and passes the outcome in as verdicts.*/export function analyzeAuthentication(headers?: Record<string, string>, verdicts?: ProviderVerdicts): SpamSignal[] {const signals: SpamSignal[] = [];