Skip to content

fix: validate base messages the same way in sm and peer - #127

Merged
gomaja merged 1 commit into
mainfrom
fix/i108c-base-validation
Oct 15, 2026
Merged

gomaja merged 1 commit into
mainfrom
fix/i108c-base-validation

Conversation

@gomaja

@gomaja gomaja commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Part 3 of the protocol contract decided in #108. The base capability,
watchdog and disconnect messages were only partly checked, by parsers
that differed between sm and peer, and the Manager ignored the optional
validation settings.

  • CER, CEA, DWR, DWA, DPR and DPA are always checked against RFC 6733
    §§3.2, 5.3.1-5.5.2 and 6.3: base header, required fields, types and
    multiplicity, Origin-Host and Origin-Realm syntax (§4.3.1), no
    Supported-Vendor-Id of zero (§5.3.6), and no Destination-Host or
    Destination-Realm in answers (§6.2). A malformed request gets one error
    answer with a single Failed-AVP (Verified Errata ID 4615); a malformed
    answer is discarded and reported.
  • A received answer may use the generic error grammar of §7.2 with a
    3xxx or 5xxx Result-Code (§§7.1.3, 7.1.5), but not with 2xxx or 4xxx
    (§7.1.4). Answers this library sends still set the E bit only for 3xxx.
  • peer.Manager honours RejectUnknownMandatoryAVPs and ValidateRequests
    with the same pipeline and order as StateMachine (advertised
    application, then unknown mandatory AVPs per §4.1, then dictionary
    validation), and routes nothing after a rejection. Both stay off by
    default.

Refs #108

Validation

  • make check passes locally for all modules: format, test (Go 1.27.2 and
    1.26.9), race, vet, lint, vuln, windows, secrets and codeql.
  • Wire tests over TCP, written to fail on main first, cover omitted and duplicated
    required fields, wrong types and flags, Application-Id, malformed identities,
    Supported-Vendor-Id zero, destination AVPs in answers, E-bit answers with each
    result class, nested unknown mandatory AVPs and every flag combination, through
    both front ends; mutating any rule fails a named test.
  • Two review rounds found that received E-bit 5xxx answers were rejected and that
    a few prohibited values passed; both are fixed.

Summary by cubic

Implements the base message validation from #108 so the six connection-level messages (CER/CEA, DWR/DWA, DPR/DPA) are checked identically in both sm and peer front ends. Previously these were only partly checked by parsers that differed between front ends, and peer.Manager ignored the optional validation settings.

  • Base messages are now always validated against RFC 6733 grammar: header, required fields, types, multiplicity, identity syntax, Supported-Vendor-Id, and destination AVPs in answers. Malformed requests get one error answer with a single Failed-AVP; malformed answers are discarded and reported.
  • peer.Manager now honors RejectUnknownMandatoryAVPs and ValidateRequests using the same pipeline and order as StateMachine; both settings stay off by default.
  • Received answers may use the generic error grammar for 3xxx or 5xxx Result-Codes, but not for 2xxx or 4xxx. Answers this library sends still set the error bit only for 3xxx.

Written for commit 36ccd0f. Summary will update on new commits.

View guided diff Turn on auto-fix

Part 3 of the protocol contract decided in #108. The base capability,
watchdog and disconnect messages were only partly checked, by parsers
that differed between sm and peer, and the Manager ignored the optional
validation settings.

- CER, CEA, DWR, DWA, DPR and DPA are always checked against RFC 6733
  §§3.2, 5.3.1-5.5.2 and 6.3: base header, required fields, types and
  multiplicity, Origin-Host and Origin-Realm syntax (§4.3.1), no
  Supported-Vendor-Id of zero (§5.3.6), and no Destination-Host or
  Destination-Realm in answers (§6.2). A malformed request gets one error
  answer with a single Failed-AVP (Verified Errata ID 4615); a malformed
  answer is discarded and reported.
- A received answer may use the generic error grammar of §7.2 with a
  3xxx or 5xxx Result-Code (§§7.1.3, 7.1.5), but not with 2xxx or 4xxx
  (§7.1.4). Answers this library sends still set the E bit only for 3xxx.
- peer.Manager honours RejectUnknownMandatoryAVPs and ValidateRequests
  with the same pipeline and order as StateMachine (advertised
  application, then unknown mandatory AVPs per §4.1, then dictionary
  validation), and routes nothing after a rejection. Both stay off by
  default.

Refs #108
Copilot AI balanced review requested due to automatic review settings October 15, 2026 05:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T05:00:19.473834Z 36ccd0f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da04a799-30e8-4c77-8f3f-626f8254bd61
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gomaja
gomaja merged commit 3d95b23 into main Oct 15, 2026
2 checks passed
@gomaja
gomaja deleted the fix/i108c-base-validation branch October 15, 2026 05:04
gomaja added a commit that referenced this pull request Oct 15, 2026
Step 2 of the plan adopted in #99. sm.StateMachine, sm.Client and
peer.Manager each decide the base protocol themselves; #108 unified their
behaviour, and this adds the single implementation they will move onto in
#110-#112. Nothing calls it yet.

diam/internal/protocol is a deterministic state machine for one
connection generation: New, Handle(Input) []Effect and an immutable
Snapshot. It owns no sockets, goroutines, timers or callbacks and depends
only on diam, diam/internal/base, diam/internal/watchdog and the
dictionary types.

- Phases PreCER, WaitCEA, Open, Closing, Closed and Retired, with the
  #108 rules: answer correlation and peer binding, base validation in the
  #127 order, the Closing admission transaction and publication boundary
  of #125, DPA handling and the in-flight 5012 (RFC 6733 §§3, 5.3-5.6, 7).
- A validated CER becomes a candidate that the caller activates, so the
  Manager can hold the CEA during election (§5.6.4) while StateMachine
  activates at once.
- Inputs carry received messages with their receipt time, local intents,
  timer expiries, allocation and write outcomes (skipped publication is
  reported apart from failure) and retirement. Effects ask the caller to
  send, admit, discard, notify, arm or stop timers, freeze admission and
  close.
- Identifiers come from an allocator the caller supplies, so the Manager
  keeps one reservation space; reservations outlive answers until every
  writer returns.
- The watchdog runs through diam/internal/watchdog with receipt-time
  decisions (RFC 3539 §3.4.1, Appendix A). The first validated DPR cause
  and a rejected CEA's parsed answer and error are kept for the front
  ends.

Tests cover every phase and input pair against the #108 record, fuzz
input sequences against an independent transition model (including
delayed allocation and write completion), and mutate each correlation,
Closing and watchdog rule.

Refs #109
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