Skip to content

fix: harden Accept() against invalid regex masks#62

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/harden-accept-method
Draft

fix: harden Accept() against invalid regex masks#62
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/harden-accept-method

Conversation

@toddr-bot
Copy link
Copy Markdown

@toddr-bot toddr-bot commented Apr 11, 2026

What

Prevents daemon crashes from invalid regex patterns in client mask configuration.

Why

A misconfigured clients mask (e.g., *invalid[ or (unclosed) causes an uncaught regex compilation error that kills the daemon process. This is a denial-of-service vector via config files and a common source of hard-to-diagnose production crashes.

How

  • Pre-compile masks with qr// inside eval — invalid patterns are logged via Error() and skipped
  • Fail-closed: if all masks are invalid, the client is denied access
  • Handle gethostbyaddr() failures: when DNS returns nothing and peerhost() is unavailable, deny with a clear error instead of proceeding with empty patterns or triggering undef warnings
  • Guard $from formatting against undef peerhost/peerport

Testing

New t/accept-edge.t with 8 tests covering:

  • Invalid regex mask doesn't crash (fail-closed behavior)
  • Invalid mask skipped, subsequent valid mask still matches
  • Array of masks with mixed valid/invalid entries
  • Missing peer identity handling

Full test suite passes.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 132 insertions(+), 6 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

…ntity

Invalid regex patterns in client mask configuration (e.g., from a
misconfigured config file) would crash the daemon with an uncaught
regex compilation error. Now masks are pre-compiled with qr// inside
eval — invalid patterns are logged and skipped, following fail-closed
semantics.

Also handles gethostbyaddr() failures gracefully: when DNS lookup
returns no results and peerhost() is unavailable, the connection is
denied with a clear error rather than proceeding with an empty
patterns list or triggering undef warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant