{"id":"CVE-2026-129301","kind":"vulnerability","aliases":["CVE-2026-129301","GHSA-8cgq-x343-p74c"],"related":[],"title":"mail-parser: One hostile attachment aborts `write_attachments()` and silently drops the rest of the batch","description":"### Impact\n\n`write_attachments()` called `_safe_attachment_filename()` and `write_sample()` inside its loop\nwith no guard, so a single crafted attachment raised out of the whole save. Every attachment\n**after** the malicious one was silently never written, with no error surfaced to a caller that\ncatches only `MailParserError`.\n\nThat is an evasion primitive as much as an availability bug: a sender puts one poisoned part\nfirst and the real payload second, and the payload never reaches the extraction directory that\na downstream scanner or sandbox reads — while it still reaches the recipient's mail client\nintact. The tool's output diverges from the bytes actually in the message, which is the same\nfailure mode as the filename-sanitizing bypass in\n[GHSA-fr3h-cpq2-9496](https://github.com/SpamScope/mail-parser/security/advisories/GHSA-fr3h-cpq2-9496).\n\nThree shapes were reachable, all from attacker-controlled MIME metadata:\n\n- **NUL smuggled through RFC 2231** — `filename*=us-ascii''evil%00.bin` decodes to a NUL in the\n  filename during parsing and raised `ValueError` out of the name check;\n- **overlong basename** — a filename longer than `NAME_MAX` (e.g. 300 characters) raised\n  `OSError: File name too long` from `open()`, *after* creating a zero-byte stub on disk;\n- **undecodable payload** — a body that is not valid base64 raised `binascii.Error` (a\n  `ValueError` subclass) from the decode performed inside the `open()` block.\n\n```python\nimport tempfile, mailparser\n\nraw = (\"Content-Type: multipart/mixed; boundary=b\\r\\n\\r\\n\"\n       \"--b\\r\\nContent-Type: application/octet-stream\\r\\n\"\n       \"Content-Disposition: attachment; filename*=us-ascii''evil%00.bin\\r\\n\\r\\nxx\\r\\n\"\n       \"--b\\r\\nContent-Type: application/octet-stream\\r\\n\"\n       \"Content-Disposition: attachment; filename=good.bin\\r\\n\\r\\nyy\\r\\n\"\n       \"--b--\\r\\n\")\n\nmp = mailparser.parse_from_string(raw)     # parse itself is fine; safe_filename is None\nmp.write_attachments(tempfile.mkdtemp())\n# 4.6.0 - 4.6.2 -> ValueError, and good.bin is never written\n# 4.6.3         -> logs \"Skipped attachment with invalid filename: 'evil\\x00.bin'\";\n#                  good.bin is written\n```\n\n`parse()` itself was never affected — it catches the `ValueError` — so only the write path was\nunguarded. The reject-paths that made this reachable were introduced with the filename\nsanitizing in 4.6.0 (PR #165).\n\n### Patches\n\nFixed in **4.6.3**. `write_attachments()` now logs and skips a single unusable attachment\ninstead of aborting the batch:\n\n- an invalid filename is caught and skipped;\n- overlong basenames are truncated to 240 UTF-8 bytes, preserving the extension, rather than\n  reaching `open()`;\n- the base64 decode moved *before* `open()`, so a failure leaves no zero-byte stub, and it now\n  repairs padding and alphabet errors the way mail clients do (matching `MIME::Base64` on 2008\n  cases) — rejecting them let a sender append one character to make an attachment vanish from\n  the extraction directory while it still reached the recipient;\n- `MailParserPathError` is deliberately **not** caught by the per-attachment handler: a\n  containment failure is not a per-attachment problem, and path-containment checks now raise\n  `MailParserPathError` instead of `ValueError` so the broader catch cannot swallow them.\n\nDeduplication was hardened in the same change: it reserves room for its own suffix marker\n(`write_sample()` sanitizes again, and the clamp there used to cut the marker back off,\ncollapsing distinct attachments onto one file), resumes from the last used suffix per stem\ninstead of rescanning from 1 (quadratic before — 16000 same-named attachments took 14 s, now\nmilliseconds), and folds case, because APFS, exFAT and SMB collapse `Invoice.pdf` and\n`invoice.pdf`.\n\n### Workarounds\n\nUpgrade to 4.6.3. If you cannot upgrade, do not call `write_attachments()` on untrusted mail;\niterate `parser.attachments` yourself and write each attachment inside its own\n`try`/`except Exception`, skipping the ones whose `safe_filename` is `None`.","summary":"mail-parser is a Python library for parsing emails. A crafted MIME attachment (bad filename or undecodable base64) makes write_attachments() stop early, so later attachments are not written and availability suffers.","severity":"medium","cvss":6.5,"epss":null,"exploited":false,"exploited_at":null,"products":[{"name":"mail-parser","fixed":["4.6.3"],"affected":">= 4.6.0, < 4.6.3","ecosystem":"pypi"}],"ecosystems":["pypi"],"tags":["cwe-248","cwe-436","email-processing","mail-parser","package","python"],"not_affected_if":["no-attachment-extraction","no-untrusted-email"],"how_to_check":"- `pip show mail-parser` or `pip freeze | grep -i mail-parser` and compare against `4.6.3`\n- Look for `write_attachments()` calls in your code that parse untrusted email","fix":"- mail-parser: upgrade to `4.6.3`","status":"open","published_at":"2026-11-16T18:17:31+00:00","first_seen_at":"2026-11-16T18:38:03+00:00","triaged_at":"2026-11-16T18:39:07+00:00","updated_at":"2026-11-16T22:27:49+00:00","category":"package","confidence":0.8,"triage":{"at":"2026-11-16T18:39:07Z","model":"claude-haiku-5-5","output":{"fix":"- mail-parser: upgrade to `4.6.3`","reach":"network","title":"mail-parser: crafted attachment names abort saving, letting later attachments slip past scanners","impact":"medium","summary":"mail-parser is a Python library for parsing emails. A crafted MIME attachment (bad filename or undecodable base64) makes write_attachments() stop early, so later attachments are not written and availability suffers.","audience":"developers","category":"package","nicknames":[],"who_cares":["python","mail-parser","email-processing"],"confidence":0.8,"fix_status":"available","needs_auth":"no","worst_case":"Later attachments go unwritten and scanners may miss a payload","analyst_note":"","how_to_check":"- `pip show mail-parser` or `pip freeze | grep -i mail-parser` and compare against `4.6.3`\n- Look for `write_attachments()` calls in your code that parse untrusted email","plain_action":"","product_name":"mail-parser","needs_analyst":false,"not_affected_if":["no-untrusted-email","no-attachment-extraction"],"who_is_affected":"Applications using mail-parser from 4.6.0 up to 4.6.3 that call write_attachments() on untrusted email. A scanner or sandbox that reads only the extraction directory can miss a payload after the crafted part. Teams that do not extract attachments from untrusted mail can skip it.","user_interaction":"no","product_ecosystem":"pypi","needs_special_setup":"yes","severity_if_unknown":"medium"},"cost_usd":0.000747,"input_tokens":4801,"output_tokens":533,"severity_before":"medium"},"analyst_status":null,"analyst_note":null,"search":"'-129301':20A,28A '-2026':19A,27A '-248':33B '-436':35B '-8':460C '/spamscope/mail-parser/security/advisories/ghsa-fr3h-cpq2-9496).':205C '00.bin':227C,327C '1':613C '14':622C '16000':616C '165':426C '2008':501C '2231':221C '240':458C '300':254C '4.6.0':373C,424C '4.6.2':374C '4.6.3':381C,430C,641C '8cgq':23A '9496':202C 'abort':7A,443C 'actual':181C 'affect':397C 'alphabet':490C 'apf':630C 'append':508C 'application/octet-stream':315C,339C 'ascii':225C,325C 'attach':6A,9A,57B,65B,70B,79C,82C,97C,105C,321C,345C,371C,384C,432C,440C,514C,535C,545C,597C,620C,650C,660C 'attack':213C 'attacker-control':212C 'avail':75B,134C 'b':305C,310C,334C,354C 'back':593C 'bad':58B 'base64':62B,281C,470C,499C 'basenam':246C,454C 'batch':17A,445C 'binascii.error':283C 'block':294C 'bodi':276C 'boundari':304C 'broader':560C 'bug':135C 'bypass':196C 'byte':180C,269C,461C,482C 'call':80C,648C 'caller':120C 'cannot':562C,644C 'case':502C,628C 'catch':122C,399C,561C 'caught':450C,530C 'chang':571C 'charact':255C,510C 'check':244C,551C 'clamp':586C 'client':171C,495C 'collaps':595C,634C 'contain':538C,550C 'content':301C,319C,343C 'content-disposit':318C,342C 'content-typ':300C 'control':214C 'cpq2':201C 'craft':55B,96C 'creat':265C 'cut':590C 'cve':18A,26A 'cwe':32B,34B 'decod':228C,289C,471C 'dedupl':565C 'deliber':528C 'directori':155C,519C 'disk':272C 'disposit':320C,344C 'distinct':596C 'diverg':177C 'downstream':158C 'drop':12A 'e.g':253C 'earli':67B 'email':37B,53B 'email-process':36B 'error':116C,491C 'evas':128C 'everi':104C 'evil':226C,326C,388C 'except':665C,666C 'exfat':631C 'extens':464C 'extract':154C,518C 'failur':189C,477C,539C 'file':258C,600C 'filenam':59B,83C,194C,222C,234C,248C,322C,346C,367C,387C,421C,448C 'filename-sanit':193C 'fine':365C 'first':142C 'fix':428C 'fold':627C 'fr3h':200C 'ghsa':22A,199C 'ghsa-8cgq-x343-p74c':21A 'ghsa-fr3h-cpq2':198C 'github.com':204C 'github.com/spamscope/mail-parser/security/advisories/ghsa-fr3h-cpq2-9496).':203C 'good.bin':347C,377C,390C 'guard':92C 'handler':536C 'harden':567C 'hostil':5A 'impact':77C 'import':296C 'insid':87C,291C,661C 'instead':441C,555C,609C 'intact':172C 'introduc':418C 'invalid':386C,447C 'invoice.pdf':635C,637C 'iter':654C 'last':604C 'later':69B 'leav':478C 'let':505C 'librari':50B 'log':382C,434C 'long':261C 'longer':249C 'loop':89C 'made':414C 'mail':2A,30A,40B,45B,170C,494C,653C 'mail-pars':1A,39B,44B 'mail-parser':29A 'mailpars':298C 'mailparser.parse':358C 'mailparsererror':124C 'mailparserpatherror':526C,554C 'make':63B,512C 'malici':108C 'marker':579C,592C 'match':497C 'max':252C 'messag':184C 'metadata':216C 'millisecond':625C 'mime':56B,215C,498C 'mode':190C 'move':472C 'mp':357C 'mp.write':370C 'much':131C 'multipart/mixed':303C 'n':307C,309C,317C,329C,333C,341C,349C,353C,356C 'name':243C,251C,259C,619C 'ncontent':313C,337C 'ncontent-typ':312C,336C 'never':112C,151C,379C,396C 'none':369C 'nul':217C,231C 'nxx':331C 'nyy':351C 'one':4A,109C,139C,509C,599C,669C 'onto':598C 'open':263C,293C,468C,474C 'oserror':257C 'output':176C 'overlong':245C,453C 'p74c':25A 'packag':42B 'pad':488C 'pars':52B,236C,362C,393C 'parser':3A,31A,41B,46B 'parser.attachments':655C 'part':141C 'patch':427C 'path':406C,412C,549C 'path-contain':548C 'payload':146C,150C,274C 'per':534C,544C,607C 'per-attach':533C,543C 'perform':290C 'poison':140C 'pr':425C 'preserv':462C 'primit':129C 'problem':546C 'process':38B 'put':138C 'python':43B,49B,295C 'quadrat':614C 'r':306C,308C,311C,316C,328C,330C,332C,335C,340C,348C,350C,352C,355C 'rais':98C,238C,256C,282C,553C 'rather':465C 'raw':299C,361C 'reach':152C,166C,467C,523C 'reachabl':209C,416C 'read':162C 'real':145C 'recipi':168C,525C 'reject':411C,503C 'reject-path':410C 'repair':487C 'rescan':611C 'reserv':573C 'rest':14A 'resum':601C 'rfc':220C 'room':574C 'sa':671C 'safe':81C,366C 'same-nam':617C 'sampl':86C,581C 'sandbox':161C 'sanit':195C,422C,582C 'save':103C 'scanner':159C 'second':147C 'sender':137C,507C 'shape':207C 'silent':11A,111C 'singl':95C,438C 'skip':383C,436C,452C,667C 'smb':633C 'smuggl':218C 'stem':608C 'still':165C,522C 'stop':66B 'string':360C 'stub':270C,483C 'subclass':286C 'suffer':76B 'suffix':578C,606C 'surfac':117C 'swallow':563C 'tempfil':297C 'tempfile.mkdtemp':372C 'three':206C 'took':621C 'tool':174C 'tri':664C 'truncat':456C 'type':302C,314C,338C 'undecod':61B,273C 'unguard':408C 'untrust':652C 'unus':439C 'upgrad':639C,645C 'us':224C,324C 'us-ascii':223C,323C 'use':588C,605C 'utf':459C 'valid':280C 'valueerror':239C,285C,375C,401C,557C 'vanish':515C 'way':493C 'whole':102C 'whose':670C 'workaround':638C 'write':8A,64B,78C,85C,405C,431C,580C,649C,658C 'written':73B,113C,380C,392C 'x00.bin':389C 'x343':24A 'zero':268C,481C 'zero-byt':267C,480C","nicknames":[],"mitigations":[],"who_affected":"Applications using mail-parser from 4.6.0 up to 4.6.3 that call write_attachments() on untrusted email. A scanner or sandbox that reads only the extraction directory can miss a payload after the crafted part. Teams that do not extract attachments from untrusted mail can skip it.","tier":"C","verified":{},"analyst_revisit_at":null,"fix_status":"available","audience":"developers","plain_action":null,"pkeys":["mailparser"],"ptokens":["mail","parser"],"labels":["cwe248","cwe436","emailprocessing","mailparser","medium","package","pypi","python"],"campaign_type":null,"search_a":"'-129301':20A,28A '-2026':19A,27A '8cgq':23A 'abort':7A 'attach':6A,9A 'batch':17A 'cve':18A,26A 'drop':12A 'ghsa':22A 'ghsa-8cgq-x343-p74c':21A 'hostil':5A 'mail':2A,30A 'mail-pars':1A 'mail-parser':29A 'one':4A 'p74c':25A 'parser':3A,31A 'rest':14A 'silent':11A 'write':8A 'x343':24A","search_b":"'-248':33B '-436':35B 'attach':57B,65B,70B 'avail':75B 'bad':58B 'base64':62B 'craft':55B 'cwe':32B,34B 'earli':67B 'email':37B,53B 'email-process':36B 'filenam':59B 'later':69B 'librari':50B 'mail':40B,45B 'mail-pars':39B,44B 'make':63B 'mime':56B 'packag':42B 'pars':52B 'parser':41B,46B 'process':38B 'python':43B,49B 'stop':66B 'suffer':76B 'undecod':61B 'write':64B 'written':73B","search_c":"'-8':460C '/spamscope/mail-parser/security/advisories/ghsa-fr3h-cpq2-9496).':205C '00.bin':227C,327C '1':613C '14':622C '16000':616C '165':426C '2008':501C '2231':221C '240':458C '300':254C '4.6.0':373C,424C '4.6.2':374C '4.6.3':381C,430C,641C '9496':202C 'abort':443C 'actual':181C 'affect':397C 'alphabet':490C 'apf':630C 'append':508C 'application/octet-stream':315C,339C 'ascii':225C,325C 'attach':79C,82C,97C,105C,321C,345C,371C,384C,432C,440C,514C,535C,545C,597C,620C,650C,660C 'attack':213C 'attacker-control':212C 'avail':134C 'b':305C,310C,334C,354C 'back':593C 'base64':281C,470C,499C 'basenam':246C,454C 'batch':445C 'binascii.error':283C 'block':294C 'bodi':276C 'boundari':304C 'broader':560C 'bug':135C 'bypass':196C 'byte':180C,269C,461C,482C 'call':80C,648C 'caller':120C 'cannot':562C,644C 'case':502C,628C 'catch':122C,399C,561C 'caught':450C,530C 'chang':571C 'charact':255C,510C 'check':244C,551C 'clamp':586C 'client':171C,495C 'collaps':595C,634C 'contain':538C,550C 'content':301C,319C,343C 'content-disposit':318C,342C 'content-typ':300C 'control':214C 'cpq2':201C 'craft':96C 'creat':265C 'cut':590C 'decod':228C,289C,471C 'dedupl':565C 'deliber':528C 'directori':155C,519C 'disk':272C 'disposit':320C,344C 'distinct':596C 'diverg':177C 'downstream':158C 'e.g':253C 'error':116C,491C 'evas':128C 'everi':104C 'evil':226C,326C,388C 'except':665C,666C 'exfat':631C 'extens':464C 'extract':154C,518C 'failur':189C,477C,539C 'file':258C,600C 'filenam':83C,194C,222C,234C,248C,322C,346C,367C,387C,421C,448C 'filename-sanit':193C 'fine':365C 'first':142C 'fix':428C 'fold':627C 'fr3h':200C 'ghsa':199C 'ghsa-fr3h-cpq2':198C 'github.com':204C 'github.com/spamscope/mail-parser/security/advisories/ghsa-fr3h-cpq2-9496).':203C 'good.bin':347C,377C,390C 'guard':92C 'handler':536C 'harden':567C 'impact':77C 'import':296C 'insid':87C,291C,661C 'instead':441C,555C,609C 'intact':172C 'introduc':418C 'invalid':386C,447C 'invoice.pdf':635C,637C 'iter':654C 'last':604C 'leav':478C 'let':505C 'log':382C,434C 'long':261C 'longer':249C 'loop':89C 'made':414C 'mail':170C,494C,653C 'mailpars':298C 'mailparser.parse':358C 'mailparsererror':124C 'mailparserpatherror':526C,554C 'make':512C 'malici':108C 'marker':579C,592C 'match':497C 'max':252C 'messag':184C 'metadata':216C 'millisecond':625C 'mime':215C,498C 'mode':190C 'move':472C 'mp':357C 'mp.write':370C 'much':131C 'multipart/mixed':303C 'n':307C,309C,317C,329C,333C,341C,349C,353C,356C 'name':243C,251C,259C,619C 'ncontent':313C,337C 'ncontent-typ':312C,336C 'never':112C,151C,379C,396C 'none':369C 'nul':217C,231C 'nxx':331C 'nyy':351C 'one':109C,139C,509C,599C,669C 'onto':598C 'open':263C,293C,468C,474C 'oserror':257C 'output':176C 'overlong':245C,453C 'pad':488C 'pars':236C,362C,393C 'parser.attachments':655C 'part':141C 'patch':427C 'path':406C,412C,549C 'path-contain':548C 'payload':146C,150C,274C 'per':534C,544C,607C 'per-attach':533C,543C 'perform':290C 'poison':140C 'pr':425C 'preserv':462C 'primit':129C 'problem':546C 'put':138C 'python':295C 'quadrat':614C 'r':306C,308C,311C,316C,328C,330C,332C,335C,340C,348C,350C,352C,355C 'rais':98C,238C,256C,282C,553C 'rather':465C 'raw':299C,361C 'reach':152C,166C,467C,523C 'reachabl':209C,416C 'read':162C 'real':145C 'recipi':168C,525C 'reject':411C,503C 'reject-path':410C 'repair':487C 'rescan':611C 'reserv':573C 'resum':601C 'rfc':220C 'room':574C 'sa':671C 'safe':81C,366C 'same-nam':617C 'sampl':86C,581C 'sandbox':161C 'sanit':195C,422C,582C 'save':103C 'scanner':159C 'second':147C 'sender':137C,507C 'shape':207C 'silent':111C 'singl':95C,438C 'skip':383C,436C,452C,667C 'smb':633C 'smuggl':218C 'stem':608C 'still':165C,522C 'string':360C 'stub':270C,483C 'subclass':286C 'suffix':578C,606C 'surfac':117C 'swallow':563C 'tempfil':297C 'tempfile.mkdtemp':372C 'three':206C 'took':621C 'tool':174C 'tri':664C 'truncat':456C 'type':302C,314C,338C 'undecod':273C 'unguard':408C 'untrust':652C 'unus':439C 'upgrad':639C,645C 'us':224C,324C 'us-ascii':223C,323C 'use':588C,605C 'utf':459C 'valid':280C 'valueerror':239C,285C,375C,401C,557C 'vanish':515C 'way':493C 'whole':102C 'whose':670C 'workaround':638C 'write':78C,85C,405C,431C,580C,649C,658C 'written':113C,380C,392C 'x00.bin':389C 'zero':268C,481C 'zero-byt':267C,480C","cause_entry":null,"cause_path":null,"disclosures_checked_at":null,"first_public_at":"2026-08-19T23:41:41+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"nvd","external_id":"CVE-2026-129301","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-129301","severity":null,"published_at":"2026-11-16T18:17:31+00:00","modified_at":"2026-11-16T18:17:31+00:00","first_seen_at":"2026-11-16T18:38:03+00:00","fetched_at":"2026-11-16T18:38:03+00:00","note":null},{"source":"ghsa","external_id":"GHSA-8cgq-x343-p74c","url":"https://github.com/advisories/GHSA-8cgq-x343-p74c","severity":"medium","published_at":"2026-11-16T22:22:13+00:00","modified_at":"2026-11-16T22:23:34+00:00","first_seen_at":"2026-11-16T22:27:49+00:00","fetched_at":"2026-11-16T22:27:49+00:00","note":null}],"documents":[{"id":171765,"url":"https://github.com/SpamScope/mail-parser/commit/11b894a0b8b3f11055a99caff118206138d1daba","title":"Patch: github.com","kind":"other","source":"nvd","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Patch: github.com"},{"id":171762,"url":"https://github.com/SpamScope/mail-parser/commit/e1d9fe6778045d6e2c44406bc8822e3464c1097f","title":"Patch: github.com","kind":"other","source":"nvd","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Patch: github.com"},{"id":171763,"url":"https://github.com/SpamScope/mail-parser/releases/tag/4.6.3","title":"Release notes: github.com","kind":"release","source":"nvd","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Release notes: github.com"},{"id":171768,"url":"https://github.com/SpamScope/mail-parser/security/advisories/GHSA-8cgq-x343-p74c","title":"Vendor advisory: github.com","kind":"vendor","source":"nvd","publisher":"vendor","text":null,"published_at":"2026-08-19T23:41:41+00:00","relation":"advisory","confidence":null,"note":"Vendor advisory: github.com"},{"id":172765,"url":"https://api.github.com/repos/SpamScope/mail-parser/security-advisories/GHSA-8cgq-x343-p74c","title":"Maintainer's advisory: api.github.com","kind":"vendor","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"advisory","confidence":null,"note":"Maintainer's advisory: api.github.com"},{"id":172729,"url":"https://github.com/SpamScope/mail-parser/pull/171","title":"Patch: github.com","kind":"other","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Patch: github.com"}],"disclosures":[],"exploit_sources":[],"notice":"Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai"}