Skip to content

Fix SOA RNAME email local-part encoding#46

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/soa-rname-email-encoding
May 19, 2026
Merged

Fix SOA RNAME email local-part encoding#46
ChiragAgg5k merged 3 commits into
mainfrom
fix/soa-rname-email-encoding

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

@ChiragAgg5k ChiragAgg5k commented May 19, 2026

Summary

  • Encode SOA RNAME values supplied in email form, e.g. hostmaster@example.com.
  • Preserve dots in the email local part as part of the mailbox label, e.g. first.last@example.com.
  • Keep generic Domain::encode() behavior unchanged so the PR only touches the SOA production regression path.

Testing

  • ./vendor/bin/phpunit --configuration phpunit.xml --filter 'RecordTest|FileTest'
  • php -d memory_limit=512M ./vendor/bin/phpstan analyse --level max -c phpstan.neon src tests
  • ./vendor/bin/pint --test --config pint.json

Note: Pint passed, but PHP 8.5 emitted deprecation noise from Pint/Laravel Zero dependencies.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 19, 2026

Greptile Summary

This PR fixes SOA RNAME encoding for email-form inputs (e.g. hostmaster@example.com and first.last@example.com) by introducing a dedicated encodeSoaRname helper that splits on @, validates both parts, and encodes the full local part as a single raw DNS label followed by the domain portion encoded via Domain::encode. The change preserves existing behaviour for non-email RNAME values and correctly handles FQDN-terminated domain parts.

  • encodeSoaRname correctly embeds the local part (including any dots) as a single length-prefixed label in wire format, consistent with RFC 1035 mailbox encoding, and includes guards for empty parts, multiple @ signs, oversized local-part labels, and total length overflow.
  • Two new RecordTest cases and one FileTest integration case exercise the happy paths; both RecordTest methods use assertStringContainsString rather than the full-frame assertSame assertion used by the existing SOA test.

Confidence Score: 5/5

The encoding logic is correct for all common email-form RNAME inputs and backward-compatible with existing DNS-notation RNAME values; the change is safe to merge.

The new encodeSoaRname helper implements RFC 1035 mailbox wire-format encoding faithfully: the local part is placed as a single raw label, length guards match those in Domain::encode, and RDLENGTH is computed dynamically from actual encoded bytes. No logic bugs were found.

The two new RecordTest methods use weaker assertions (assertStringContainsString) than the existing SOA test; they pass but do not verify the complete wire frame.

Important Files Changed

Filename Overview
src/DNS/Message/Record.php Adds encodeSoaRname helper that converts email-form RNAME to wire format: splits on @, validates both parts, encodes the local part as a single raw label, then calls Domain::encode for the domain portion. Logic is correct for the common cases; length guards are in place.
tests/unit/DNS/Message/RecordTest.php Adds two new SOA encoding tests; both use assertStringContainsString (weaker than the existing assertSame full-frame assertion). Test name for the dotted-local-part case is misleading.
tests/unit/DNS/Zone/FileTest.php Adds an integration test that imports a zone file with an email-form SOA RNAME and verifies the wire encoding contains the expected byte sequence. Covers the FQDN-dot-terminated domain case correctly.

Reviews (3): Last reviewed commit: "Narrow SOA RNAME email encoding fix" | Re-trigger Greptile

Comment thread src/DNS/Message/Record.php Outdated
- Make Domain::encode preprocessing escape-aware (no more rtrim corrupting
  escaped dots, no more str_ends_with('..') false-positives).
- Reject dangling trailing backslashes and unknown \X escape sequences in
  splitLabels so silent behavior changes surface loudly.
- Validate SOA RNAME up-front: exactly one @, non-empty local part and
  domain, no trailing backslash in the local part.
- Document encode/decode asymmetry on Domain::decode.
- Add regression tests covering escaped-dot edge cases, dangling and
  unknown escapes, SOA wire round-trip, multi-@, empty local part / domain,
  pre-escaped RNAME, single-label RNAME, and over-long local part.
@ChiragAgg5k ChiragAgg5k changed the title Fix SOA RNAME email encoding Fix SOA RNAME email local-part encoding May 19, 2026
@ChiragAgg5k ChiragAgg5k merged commit 0b1dd9b into main May 19, 2026
5 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/soa-rname-email-encoding branch May 19, 2026 14:44
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