Skip to content

Commit

Permalink
Fix regression in MTA-STS.txt line ending tests.
Browse files Browse the repository at this point in the history
The previous version introduced a regression causing valid MTA-STS
files to be recognized as invalid, with the wrong line endings (not
CRLF).  This commit fixes that by properly counting the lines in
both possible parsing methods.
  • Loading branch information
rhymeswithmogul committed Dec 9, 2023
1 parent 1e81f4c commit 8ce4b28
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# MailPolicyExplainer Change Log

## Version 1.3.1 (Wednesday, December 9, 2023)
## Version 1.3.2 (Friday, December 8, 2023)
**FIX** `Test-MtaStsPolicy` no longer misidentifies `mta-sts.txt` files with the correct CRLF line endings as malformed. This was caused by a regression in version 1.3.1.

## Version 1.3.1 (Wednesday, December 6, 2023)
- **FIX** Implied MX records are now displayed correctly.
- **NEW** The IP version checks are now displayed with an indentation when run as a part of `Test-MailPolicy`.
- **FIX** The IP version checks now work with implied MX records.
Expand Down
20 changes: 2 additions & 18 deletions MailPolicyExplainer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'src/MailPolicyExplainer.psm1'

# Version number of this module.
ModuleVersion = '1.3.1'
ModuleVersion = '1.3.2'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down Expand Up @@ -167,23 +167,7 @@ PrivateData = @{
IconUri = 'https://raw.githubusercontent.com/rhymeswithmogul/MailPolicyExplainer/main/icon/PSGallery.png'

# ReleaseNotes of this module
ReleaseNotes = 'This release adds one new feature: IP version checks are now indented when run from `Test-MailPolicy`.
Many bugs were fixed, too:
- Implied MX records are now displayed correctly.
- `Test-DaneRecords` now correctly checks DANE records for domains without MX records.
- The DMARC `fo` token is now parsed correctly when multiple values are present.
- The DMARC `rf` token is now parsed correctly.
- The IntelliSense handling of `Test-SpfRecord` has been improved by hiding some internal-use-only parameters.
- The IP version checks now work with implied MX records.
- The MTA-STS policy file test returns a better error message when the file does not have the correct CRLF line endings.
- The SMTP TLS reporting policy test now checks to make sure exactly one `v` tag is present with the value `TLSRPTv1`.
- The SMTP TLS reporting policy test now fails gracefully when invalid text is returned.
- The SPF `exists` and `mx` token parsers no longer generate a spurious error when not counting DNS lookups.
- Online help is fixed for `Test-SmtpTlsReportingPolicy`, `Test-MtaStsPolicy`, and `Test-SpfRecord`.
- Cleaned up the output of `Test-DaneRecords` a little.
- Miscellaneous code cleanup.
'
ReleaseNotes = '`Test-MtaStsPolicy` no longer misidentifies `mta-sts.txt` files with the correct CRLF line endings as malformed. This was caused by a regression in version 1.3.1.'

} # End of PSData hashtable

Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# MailPolicyExplainer News

## Version 1.3.2
This was released on Friday, December 8, 2023.

This is a bugfix release. Now, `Test-MtaStsPolicy` no longer misidentifies `mta-sts.txt` files with the correct CRLF line endings as malformed. This was caused by a regression in version 1.3.1.

## Version 1.3.1
This was released on Wednesday, December 6, 2023.

Expand Down
16 changes: 10 additions & 6 deletions src/MailPolicyExplainer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,14 @@ Function Test-MtaStsPolicy
# operating system and PowerShell version.)
Test-IPVersions "mta-sts.$DomainName"

$oldSP = [Net.ServicePointManager]::SecurityProtocol
$iwrParams = @{
'Method' = 'GET'
'Uri' = "https://mta-sts.$DomainName/.well-known/mta-sts.txt"
'ErrorAction' = 'Stop'
$oldSP = [Net.ServicePointManager]::SecurityProtocol
$ModuleInfo = (Get-Module 'MailPolicyExplainer')
$iwrParams = @{
'Method' = 'GET'
'Uri' = "https://mta-sts.$DomainName/.well-known/mta-sts.txt"
'UseBasicParsing' = $true
'UserAgent' = "Mozilla/5.0 ($($PSVersionTable.Platform); $($PSVersionTable.OS); $PSCulture) PowerShell/$($PSVersionTable.PSVersion) MailPolicyExplainer/$($ModuleInfo.Version)"
'ErrorAction' = 'Stop'
}
Try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13
Expand Down Expand Up @@ -888,7 +891,8 @@ Function Test-MtaStsPolicy
$lines = $policy.Content.Split("`r`n")
$LFlines = $policy.Content -Split "`r?`n"

If ($lines -ne $LFLines) {
If ($lines.Count -ne $LFLines.Count) {
Write-Debug "This file has $($lines.Count) CRLF-terminated lines and $($LFlines.Count) LF-terminated lines."
Write-BadNews "MTA-STS Policy: The policy file does not have the correct CRLF line endings!"
Return
}
Expand Down

0 comments on commit 8ce4b28

Please sign in to comment.