Skip to content

fix(email-utils): guard against invalid URL in List-Unsubscribe parsing#2084

Closed
devteamaegis wants to merge 1 commit into
Mail-0:stagingfrom
devteamaegis:fix/list-unsubscribe-invalid-url
Closed

fix(email-utils): guard against invalid URL in List-Unsubscribe parsing#2084
devteamaegis wants to merge 1 commit into
Mail-0:stagingfrom
devteamaegis:fix/list-unsubscribe-invalid-url

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

getListUnsubscribeAction in apps/server/src/lib/email-utils.ts throws TypeError: Invalid URL on a malformed List-Unsubscribe header. The primary URL-parse path has no try/catch, while the fallback path already guards the same new URL(...) call — so a malformed header crashes instead of degrading gracefully.

Why it happens

The primary branch calls new URL(...) on the extracted header value without catching the exception that an invalid URL throws; only the fallback branch was wrapped.

Fix

Wrap the primary new URL(...) parse in the same try/catch the fallback uses, so a malformed List-Unsubscribe value is handled (falls through) instead of throwing.

Test

Processing a malformed List-Unsubscribe header no longer throws and returns a safe result; a valid header still parses. Fails before, passes after.

…ashing

getListUnsubscribeAction threw "TypeError: Invalid URL" when the first
angle-bracketed value in a List-Unsubscribe header was not a valid URL
(e.g. a leftover placeholder like <here> or human-readable text). The
fallback branch already guarded new URL() with try/catch, but the primary
branch did not. Wrap it the same way so an unparseable value returns null
instead of throwing. Adds a regression test.
@adamghaida

Copy link
Copy Markdown
Member

Thanks for your interest in Mail0; however, this repository is no longer accepting pull request.

@adamghaida adamghaida closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants