Skip to content

fix(regex): add missing 4th octet to Email address preset for IPv4 domains#2318

Closed
terminalchai wants to merge 1 commit intogchq:masterfrom
terminalchai:fix/email-regex-ipv4-domain
Closed

fix(regex): add missing 4th octet to Email address preset for IPv4 domains#2318
terminalchai wants to merge 1 commit intogchq:masterfrom
terminalchai:fix/email-regex-ipv4-domain

Conversation

@terminalchai
Copy link
Copy Markdown

Problem

The Email address preset regex in the Regular Expression operation was missing the 4th IPv4 octet in the bracketed address form (RFC 5321 address literals).

The IPv4 bracket group matched only three octets followed by a trailing dot:
\
\[(?:(?:(octet))\.){3}\]
\\

This means:

  • ❌ \user@[1.2.3.4]\ — not matched (should be matched)
  • ✅ \user@[1.2.3.]\ — false positive match (should not match)

Fix

Add the 4th octet group before the closing bracket, matching the correct regex already used in \ExtractEmailAddresses.mjs:
\
\[(?:(?:(octet))\.){3}(?:(octet))\]
\\

Now:

  • ✅ \user@[1.2.3.4]\ — matches correctly
  • ✅ \user@[192.168.0.1]\ — matches correctly
  • ❌ \user@[1.2.3.]\ — correctly rejected

Changes

  • \src/core/operations/RegularExpression.mjs\ — fixed the Email address preset regex
  • \ ests/operations/tests/Regex.mjs\ — added regression test for IPv4-domain email addresses

Fixes #2150

The 'Email address' preset in the Regular Expression operation was
missing the 4th IPv4 octet in the bracketed address form, causing
addresses like user@[1.2.3.4] to never match.

The IPv4 bracket group ended after {3} repetitions of 'octet.':
  \\[(?:(?:(octet))\.){3}\\]

This matches [1.2.3.] (a false positive) but not [1.2.3.4].

Fix: add the 4th octet group before the closing bracket, mirroring
the correct regex already used in ExtractEmailAddresses.mjs:
  \\[(?:(?:(octet))\.){3}(?:(octet))\\]

Closes gchq#2150
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@C85297
Copy link
Copy Markdown
Member

C85297 commented Apr 13, 2026

Hi @terminalchai , thank you for your pull request! I think we are already tracking this issue and have a fix ready here: #2167 . Could you check whether the changes in that pull request would satisfy your use case, or are there any other changes we need to make?

@terminalchai
Copy link
Copy Markdown
Author

Thanks for pointing that out @C85297! Confirmed — PR #2167 was merged yesterday and fully covers the same fix (adds the 4th octet to the Email address preset regex and closes #2150). This PR is a duplicate and can be closed. Closing now.

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.

Regular Expression operation email address regex does not support IPv4 domains

3 participants