QR codes
QR code phishing, sometimes called quishing, hides the link of a phishing message inside a QR code. The text of the message carries no link at all, only an image and an instruction to scan it, typically to re-enrol in multi-factor authentication, sign a document, listen to a voicemail or check a payslip. Filters that only read the text of a message have nothing to check, and the recipient who scans the code opens the link on a phone, outside the protections of the desktop mail client.
The spam filter answers this by decoding the QR codes it finds in a message. Each decoded link joins the other links of the message and goes through the same checks, so a code that leads to a known phishing site is caught in the same way as a written link to it. The filter also adds tags of its own that describe the code and its context.
Scanned content
Section titled “Scanned content”The filter looks for QR codes in two kinds of content: images, and codes drawn without an image.
Images
Section titled “Images”Three sources of images are scanned:
- Image parts. Every MIME part of the message with an
image/*orapplication/octet-streamcontent type, whether it is an attachment or an image embedded in the HTML body through acid:reference. The type declared by the sender only selects the candidates: the filter identifies the actual format from the content, and scans PNG, JPEG, GIF, WebP and BMP images. A part in any other format, or an exact copy of a part already selected, is skipped. - Data URIs. Images embedded directly in the HTML body as
<img src="data:image/...;base64,...">. They are checked for format in the same way as image parts. - Remote images. Images that the HTML body references by URL. These are downloaded only when remote images are enabled, which they are not by default.
PDF attachments are not scanned, so a QR code inside a PDF document is not found.
Drawn codes
Section titled “Drawn codes”An image is not the only way to show a QR code. A QR code is a square grid of dark and light squares, called modules, and some phishing messages draw that grid with text or HTML, so that a filter scanning images sees none. The filter recognises two such techniques in the body of the message:
- HTML tables. A table in which each cell is one module, coloured through its
bgcolorattribute or abackgroundorbackground-colordeclaration in itsstyleattribute. The filter classifies each colour as dark or light by its brightness, and honourscolspan, which drawn codes use to merge runs of modules of the same colour. Tables nested up to 16 levels deep are examined. - Unicode block characters. Consecutive lines made of the characters
█,▀and▄and spaces, in a plain-text body or in the text of an HTML body. Each character draws two modules, one above the other, so each line holds two rows of the grid.
A grid qualifies when it is between 21 and 200 modules on each side, the range of QR code sizes, and roughly square. The filter renders each qualifying grid as an image and decodes it like any other. At most four drawn codes are examined per message.
Decoded links
Section titled “Decoded links”A QR code carries text, and most codes in mail carry a link. A decoded text that starts with https://, http:// or www. becomes a link of the message, located in qr_code. Text longer than 4096 characters is truncated first.
From then on, the link is treated like a link written in the message. It is skipped when its domain is trusted, followed when it points to a URL redirector, checked for look-alike characters and other disguises, and queried in the domain and URL DNS blocklists. The rules of the Url variant evaluate it too, which includes the phishing feeds, and they can tell it apart through the location variable, which is qr_code for these links. The AI classifier, when enabled, receives the link along with the others. A link that also appears in the text of the message keeps the location where it was written.
Phishing links often carry the address of the recipient, so that the fake sign-in page shows it already filled in and looks expected. The filter therefore compares each decoded link with the recipient addresses, from the envelope and from the headers, and looks for each address written as is, with @ encoded as %40, or encoded in Base64. A link that contains one receives QR_RCPT_IN_URL. This check covers up to 16 distinct addresses.
A decoded text that is not a link, such as plain text, contact details or Wi-Fi credentials, is not checked further, and receives the informational tag QR_CODE_NON_URL.
A QR code in itself proves little, since legitimate mail carries many of them: tickets, boarding passes, payment slips. The tags therefore score the code lightly, and give most of their weight to the circumstances that distinguish a phishing attempt. The scores below are those of the rule set, and can be changed like any other tag score.
| Tag | Score | Finding |
|---|---|---|
HAS_QR_CODE | 0.5 | At least one QR code was decoded. |
QR_CODE_HTML | 3.0 | A decoded code was drawn with an HTML table or block characters. Legitimate senders use images; a drawn code exists to escape image scanning. |
QR_RCPT_IN_URL | 4.0 | A decoded link contains the address of a recipient. |
QR_CODE_SHORT_BODY | 2.0 | The message has a QR code and little else: its HTML body is a single large image with almost no text (HTML_IMAGE_ONLY), its HTML text is short (HTML_SHORT_1), or it consists of one short part (SINGLE_SHORT_PART). |
QR_CODE_LURE | 2.5 | The message has a QR code, and its body or subject uses the vocabulary of common QR code lures, such as MFA, 2FA, scan, DocuSign, payroll or voicemail. |
QR_CODE_NON_URL | 0.0 | A decoded code contains something other than a link. |
The built-in analysis adds HAS_QR_CODE, QR_CODE_HTML, QR_RCPT_IN_URL and QR_CODE_NON_URL. The other two come from the rules STWT_QR_CODE_SHORT_BODY and STWT_QR_CODE_LURE of the rule set, which can be customised like any other rule.
HTML_IMAGE_ONLY (2.0) is added independently of QR code scanning. It marks an HTML body made of a large image, one that declares its width or height, measures at least 400 pixels in width plus height and is not inside a link, with fewer than 50 characters of text. Image-only messages are a common way of keeping the text away from content filters, whether the image holds a QR code or not.
The tags of the checks that the decoded links go through, such as DBL_PHISH or PHISHED_OPENPHISH, are added on top of these.
Settings
Section titled “Settings”QR code scanning is configured with four fields of the SpamSettings singleton, found in the WebUI under Settings › Spam Filter › General, in the QR Codes section:
| Field | Default | Effect |
|---|---|---|
qrCodeScan | enabled | Turns QR code scanning on or off. |
qrCodeMaxImages | 4 | Maximum number of images decoded per message, from 0 to 64. 0 disables scanning. |
qrCodeMaxImageSize | 2 MiB | Images larger than this are not decoded. |
qrCodeFetchRemote | disabled | Downloads the remote images referenced by HTML bodies, as described in Remote images. |
The image limit applies to image parts, data URIs and remote images together. Image parts are selected first, then the data URIs and remote images in the order the HTML body references them, until the limit is reached. Drawn codes do not count towards it, since they have their own limit of four per message.
Remote images
Section titled “Remote images”Many messages reference their images by URL rather than embedding them, and a phishing message can do the same to keep its QR code out of reach of attachment scanning. Scanning such an image means downloading it from a server that the sender chooses, which has consequences beyond the time it takes.
The sender learns from the request that the message was received and processed. Image URLs are often unique to each recipient, precisely so that a request confirms which address is valid and active, and the request also reveals the IP address of the mail server. This happens even when the message is then classified as spam and never opened. For this reason qrCodeFetchRemote is disabled by default, and should be enabled only where catching QR codes in remote images is worth confirming addresses to spammers.
When the setting is enabled, the downloads follow the same restrictions as the resolution of URL redirectors:
- Only
https://images are downloaded, and only from servers with public addresses. - Redirections are not followed.
- Each download is limited by
redirectTimeout. The response must declare an image orapplication/octet-streamcontent type, and the download stops as soon as the image exceedsqrCodeMaxImageSize. - An image whose
widthorheightattribute is below 64 pixels is not downloaded, since it is too small to hold a readable code; this excludes most tracking pixels and icons. - No image is downloaded while training the classifier.
The images of a message are downloaded in parallel. The decoded result of each URL, or the absence of a code, is kept in the spam lookup cache for redirectCacheTtl, so an image sent to many recipients is downloaded and decoded once. A download that fails is remembered for the cache’s negativeTtl.
Performance limits
Section titled “Performance limits”Decoding images costs far more processor time than the rest of the analysis, and the images come from the sender, who may craft them to make the decoder work as hard as possible. Scanning is therefore bounded at each stage.
Before decoding an image, the filter reads its dimensions from the file header, and skips images smaller than 40 or larger than 8192 pixels on either side, or larger than 16 million pixels in total. The decoder itself may allocate at most 64 MiB. A decoded image is converted to grayscale and, when larger than one million pixels, scaled down to that size by averaging. A QR code in a message is large relative to its image, so the reduction keeps it readable, while every image costs at most the same to scan.
Each image goes first to a fast detector, which is tried a second time on the inverted image to find light-on-dark codes, and only then to a slower and more thorough decoder. An image with many shapes that resemble the corner markers of a QR code is abandoned early instead of going to the slow decoder. A decoder failure on a malformed image is contained, and only that image is lost.
Scanning runs outside the threads that handle connections, and the number of messages scanned at the same time is limited to half the processor cores, rounded up. A message waits at most five seconds for its turn. When the wait runs out, the message is filtered without its QR codes rather than delayed further: scanning fails open, so a burst of image-heavy messages cannot hold up delivery, at the cost of missing the QR code tags on some messages while the server is under that load.