Repository navigation
fix(privacy): read Italian certified email (PEC) whose attachment names are unquoted - #287
Open
6801318d8d wants to merge 1 commit into
Open
6801318d8d wants to merge 1 commit into
6801318d8d wants to merge 1 commit into
Conversation
… the signed raw path
Italian certified email (PEC) providers deliver every message inside an
S/MIME-signed envelope (multipart/signed, application/pkcs7-signature) that
carries the original as postacert.eml. Several senders behind it, JavaMail
based, write attachment names with spaces and parentheses unquoted, e.g.
"Content-Type: application/pdf; name=Signed decision (1).pdf".
The strict raw MIME gate only accepted a token or a quoted string as a
parameter value, so such a name made isStrictlyWellFormedRawMime return
false and classifyRawMessageEncryption return "unknown". getMessage and
rawSource then withheld these clear-signed messages ("encryption status
could not be determined"), and the read-only fallback could not recover
them either because the envelope embeds a message with base64 parts.
libmime reads an unquoted parameter value up to the next ';' and trims
trailing whitespace (nsMIMEHeaderParamImpl::DoParameterInternal), which is
what parseRawMimeHeaderValue and collectRawMimeParameterNames already do.
The gate now accepts that form for name and filename only, made of token
characters, parentheses and spaces or tabs, without quotes or backslashes,
like the quoted form it already accepts. Other parameters, RFC 2231
segments, quotes and backslashes in unquoted values are still refused, and
the protected-name and nested-encryption checks still apply to these names.
Tests: a PEC-shaped signed envelope with an embedded message, unquoted
names and an XML attachment is read through the gate, getMessage, rawSource
and reply; the same envelope with an unquoted .p7m name on an
octet-stream part is still withheld, and with an enveloped pkcs7-mime part
is still classified as encrypted; four new malformed-leaf cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
With "Allow MCP clients to read encrypted messages" off,
getMessagewithholds every message delivered through Italian certified email (PEC, posta elettronica certificata), both the body andrawSource:These messages are signed, not encrypted. The PEC provider wraps the original message in an S/MIME-signed envelope:
Many senders behind PEC (JavaMail-based protocol systems of public bodies) write attachment names with spaces and parentheses unquoted:
Cause. The strict raw MIME gate (
isStrictRawMimeStructuredValue) accepts only a token or a quoted string as a parameter value.STRICT_MIME_PARAMETER_REmatchesname=Signed, the tail check then fails ondecision (1).pdf,isStrictlyWellFormedRawMimereturnsfalseandclassifyRawMessageEncryption(raw, 0, { signedRaw: true })returns"unknown". The read-only fallback inclassifyRawMessageReadSafetycannot recover the message either, because the envelope embeds a message whose parts are base64 (embedded && nonIdentity). Running the production classifiers on a real PEC message confirmed that this rule is the only one that fires: with the gate relaxed as below, the strict classifier returns"clear".Fix. libmime reads an unquoted parameter value up to the next
;and trims trailing whitespace (nsMIMEHeaderParamImpl::DoParameterInternal, the unquoted branch), andparseRawMimeHeaderValue/collectRawMimeParameterNamesalready read it the same way. The gate now accepts that form fornameandfilenameonly, made of token characters, parentheses and spaces or tabs, the same names it already accepts in quoted form. Still refused:charset=utf-8 x), and for RFC 2231 segments (filename*0=a b);The protected-name rule and the nested-encryption checks still see these names: an unquoted
name=… .p7mon anapplication/octet-streampart stays"unknown", and anapplication/pkcs7-mimepart with an unquoted name stays"encrypted".Validation
test/privacy-messages.test.cjs:getMessage,rawSourceand reply;.p7mname on an octet-stream part (withheld) and with an envelopedpkcs7-mimepart (encrypted);npm teston Windows, Node 24: 4,990 pass, 4 fail, 16 skipped. The same 4 failures occur on unmodifiedmain(message-headers,protected-subjects,search-messages-scan:SyntaxError: Cannot use import statement outside a module; one Windows path assertion inbridge-requests).npx eslint extension/mcp_server/api.js test/privacy-messages.test.cjs: 0 errors (5 existing warnings elsewhere inapi.js).node:vmsandbox on a real PEC message from the offline store of Thunderbird 160.0, return"unknown"before and"clear"after the change. The message itself is not included.🤖 Generated with Claude Code