Spam filter: check the links in QR codes in a message's images #463

Merged
jcoffey-dev merged 1 commits from feat/401-qr-urls into main 2026-11-18 23:47:33 +00:00
Owner

Fixes #401 (requested in community t/292).

New dependencies image and rqrr (plus 16 small crates they bring, all permissive) and the setting being off by default were both agreed by John. Rebased on main after #462 (schema regenerated).

With scanQrCodes on (Settings → Spam Filter → Images, "Check links in QR codes"), the URL analysis reads QR codes in a message's images and checks each web link the way it checks the message's other links, at location qr_code. A message with one gets QR_CODE_URL (0.0 in the bundled rules, 3.0.2-inbuxa.2): a QR code alone isn't a spam sign.

Caps: PNG/JPEG/GIF/WebP sniffed from the bytes (image parts of any declared type, and data: images in HTML); at most 4 images, each 4 MB / 16 MP / at least 64 px a side, read from the header before decoding; scanned at 1600 px at most; 1 s per message; 10 links, http(s) only; decoded on a blocking thread.

Cost (release build, one core, on a busy machine):

Image Time
QR code alone, 300 px PNG ~4 ms
QR on an 800x1000 flyer (JPEG or PNG) ~16-18 ms
1600x1200 JPEG, no code ~32 ms
3000x4000 phone photo (scaled to 1600) ~130 ms

So a message with images costs from a few ms up to about 0.5 s of CPU at worst (4 photos), within the 1 s budget. Messages without images cost nothing.

Not covered: QR codes in PDFs, and codes drawn with HTML tables or Unicode blocks.

Checks run locally: cargo fmt --check, cargo test --workspace --locked --no-run, the spam-filter qr unit tests, registry stored-version test, the antispam test (all of it, with the new url cases), spam_rules tests, and every fork-check script plus their tests.

Fixes #401 (requested in community t/292). New dependencies image and rqrr (plus 16 small crates they bring, all permissive) and the setting being **off by default** were both agreed by John. Rebased on main after #462 (schema regenerated). With `scanQrCodes` on (Settings → Spam Filter → Images, "Check links in QR codes"), the URL analysis reads QR codes in a message's images and checks each web link the way it checks the message's other links, at location `qr_code`. A message with one gets `QR_CODE_URL` (0.0 in the bundled rules, 3.0.2-inbuxa.2): a QR code alone isn't a spam sign. **Caps:** PNG/JPEG/GIF/WebP sniffed from the bytes (image parts of any declared type, and `data:` images in HTML); at most 4 images, each 4 MB / 16 MP / at least 64 px a side, read from the header before decoding; scanned at 1600 px at most; 1 s per message; 10 links, http(s) only; decoded on a blocking thread. **Cost** (release build, one core, on a busy machine): | Image | Time | |---|---| | QR code alone, 300 px PNG | ~4 ms | | QR on an 800x1000 flyer (JPEG or PNG) | ~16-18 ms | | 1600x1200 JPEG, no code | ~32 ms | | 3000x4000 phone photo (scaled to 1600) | ~130 ms | So a message with images costs from a few ms up to about 0.5 s of CPU at worst (4 photos), within the 1 s budget. Messages without images cost nothing. **Not covered:** QR codes in PDFs, and codes drawn with HTML tables or Unicode blocks. Checks run locally: `cargo fmt --check`, `cargo test --workspace --locked --no-run`, the spam-filter qr unit tests, registry stored-version test, the antispam test (all of it, with the new url cases), spam_rules tests, and every fork-check script plus their tests.
jcoffey-dev added 1 commit 2026-11-18 23:37:05 +00:00
Spam filter: check the links in QR codes in a message's images
ci / fork-checks (pull_request) Skipped
ci / build (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 10m6s
e806515cb4
A phishing message can carry its link only as a QR code in an image
("quishing"), where the URL checks never look: they read the subject and
text parts. Requested in community t/292.

With the new x:SpamSettings scanQrCodes setting on (off by default), the
URL analysis reads QR codes in the message's images and puts each web link
it finds through the same checks as the message's other links (DNSBLs,
redirectors, homographs, IP hosts, URL rules), at a new location qr_code,
so a rule can tell a link came from a QR code. A message with such a link
gets QR_CODE_URL, scored 0.0 in the bundled rules (3.0.2-inbuxa.2): a QR
code alone isn't a spam sign, and an administrator can give it a score.

What's read (crates/spam-filter/src/analysis/qr.rs):
- image parts, whatever their declared type, and data: images in HTML,
  sniffed from the bytes as PNG, JPEG, GIF or WebP; nothing else
- at most 4 images per message, each at most 4 MB and 16 megapixels (the
  size comes from the header, before anything is decoded) and at least
  64 px a side; decoding has image's allocation limits set
- images over 1600 px are scaled down before they're scanned
- no image is started after 1 s; at most 10 links, http and https only
- decoding runs on a blocking thread

New dependencies: image 0.25 (png, jpeg, gif, webp only; no default
features) and rqrr 0.11 (no default features, fed greyscale pixels).
Both are permissive ((MIT OR Apache-2.0); rqrr also ISC), as are the 16
crates they bring.

SpamSettings is stored at version 1 with the setting after every existing
field; settings stored before read back with scanning off.

Test: qr.rs unit tests (a link read from a PNG and from a JPEG flyer, none
from a JPEG with no code, a data: URL, the size and format caps, only web
links kept, links kept once); the antispam url test reads a code in an
image part, in an octet-stream attachment and in a data: URL, each giving
QR_CODE_URL plus SUSPICIOUS_URL from the IP link's URL check, and nothing
for a photo with no code; a registry test for the stored versions.

Fixes #401
jcoffey-dev force-pushed feat/401-qr-urls from dd0b42340a to e806515cb4 2026-11-18 23:37:05 +00:00 Compare
jcoffey-dev merged commit 96130a6211 into main 2026-11-18 23:47:33 +00:00
jcoffey-dev deleted branch feat/401-qr-urls 2026-11-18 23:47:33 +00:00
Sign in to join this conversation.