Skip to content

Conversation

@mattcave
Copy link
Contributor

@mattcave mattcave commented Jan 9, 2026

Description

The existing self-reference checks only caught direct loops (A→A) but missed indirect circular references like A→B→A or longer chains. This causes infinite loops which eventually result in a stack overflow.

Added a -Visited parameter to track all domains in the resolution chain. Before recursing into an include or redirect, the function now checks if the target domain has already been visited in the current resolution path.

  • Direct self-references return specific messages (e.g., "Self-referencing SPF include")
  • Indirect circular references return "Circular SPF reference detected"

Tested against oldmomutual.com which has a circular include with oldmissourimutual.com.

Contribution Checklist

Before submitting this PR, please confirm you have completed the following:

  • [YES] 📖 Read the guidelines for contributing to this repository.
  • [YES] 🧪 Ensure the build and unit tests pass by running /powershell/tests/pester.ps1 on your local system.

The existing self-reference checks only caught direct loops (A→A) but
missed indirect circular references like A→B→A or longer chains.

Added a -Visited parameter to track all domains in the resolution chain.
Before recursing into an include or redirect, the function now checks if
the target domain has already been visited in the current resolution path.

- Direct self-references return specific messages (e.g., "Self-referencing SPF include")
- Indirect circular references return "Circular SPF reference detected"

Tested against oldmomutual.com which has a circular include with oldmissourimutual.com.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mattcave mattcave requested a review from a team as a code owner January 9, 2026 18:25
@SamErde SamErde requested a review from Copilot January 9, 2026 22:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes circular SPF reference detection by introducing a tracking mechanism for visited domains during SPF record resolution. Previously, only direct self-references (A→A) were detected, but indirect circular references (A→B→A) caused infinite loops and stack overflows.

Key changes:

  • Added a $Visited parameter array to track all domains in the resolution chain
  • Updated circular reference detection logic for both redirect and include directives
  • Distinguished between direct self-references and indirect circular references in error messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mattcave and others added 2 commits January 9, 2026 17:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mattcave
Copy link
Contributor Author

mattcave commented Jan 9, 2026

Accepted Copilot's suggestions, they make sense.

@SamErde
Copy link
Contributor

SamErde commented Jan 10, 2026

Accepted Copilot's suggestions, they make sense.

OK, cool. I didn't have a chance to test yet, so I just kicked off the Copilot review.

@mattcave
Copy link
Contributor Author

A little bump on this @SamErde. We're seeing this is production for quite a few tenants so would love to get the fix in place soon.

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