Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Up to standards ✅🟢 Issues
|
|
This is the same class I measured in #2796 — 270 AD checks, 268 with tables, 77 interpolating a name-like field in 95 places, and zero calling Two things, one actionable and one I verified so you don't have to take it on faith. The byte order mark hunk duplicates #2795
Why it is worth separating rather than leaving both: that one byte is what (The other cause is the runner's own I tested the new link pattern rather than eyeballing itNested quantifiers over a tenant-controlled string is exactly where catastrophic backtracking lives, so I ran the new pattern against .NET regex directly with a 5 s timeout. Correctness:
That last row is the one I most wanted to see hold: the https-only restriction still rejects the smuggled scheme after the pattern was widened. Backtracking, with Linear, and the reason is structural rather than luck: the three alternatives inside No other findings. The |
|
Thanks @earbona23 — removed the unrelated BOM correction in 53a0442. Rechecked through |
|
Verified on That also removes the ordering problem: whichever of the two lands first, neither now rewrites the other's file. Two factual notes, neither a blocker:
|
|
Ran the 20 Graph-only checks this PR touches at Then, with a disabled Conditional Access policy named |
|
Two things I measured on
The idiom is wide, but narrower than a raw grep suggests. On
I started with the 501 and cut it down deliberately: the first three I opened ( None of that is a request to widen this PR — 22 call sites in one change is already the right size, and the CIS and Entra set is where it was reported. I am noting the rest so whoever decides the follow-up has the number in front of them, and I will keep it with the AD escaping work in #2796 rather than open a separate issue for it. |
earbona23
left a comment
There was a problem hiding this comment.
Approving. First external review. This fixes a corruption I would not have found by reading, so I measured it from both ends.
The -replace to .Replace change is the substantive fix
-replace treats its replacement string as a substitution pattern, so $ is a metacharacter there. I ran the two forms side by side against the template this code uses:
| name in the result markdown | -replace (today's main) |
.Replace (this PR) |
|---|---|---|
Policy $& Draft |
Policy %TestResult% Draft |
Policy $& Draft |
A $$ B |
A $ B |
A $$ B |
Policy $1 Draft |
unchanged | unchanged |
Costs $100 |
unchanged | unchanged |
Two concrete corruptions. $& expands to the matched text, so a policy named with it makes the placeholder itself appear in the report as if it were tenant data — an operator reading Policy %TestResult% Draft has no way to tell that is not the real name. $$ silently collapses to a single $. $1 happens to survive only because the pattern %TestResult% has no capture groups, so the blast radius is narrower than "any dollar sign" but it is real and it is silent either way.
Narrow trigger, but this is a report an operator uses to decide what to change in a tenant, and a name that is not the name is the kind of wrong that costs someone an afternoon.
The tests pin it, and I checked that they do
61 cases across Test-MtLiteralCisPolicyNames.Tests.ps1 (51) and Test-MtSecurityCheckMarkdown.Tests.ps1 (10), all green on the head. The fixtures go straight at it:
$name = 'Policy $& $$ $1 ${name}'and assert the literal survives, including the combination with a pipe — HQ | Berlin $& $$ is asserted to come out as HQ \| Berlin $& $$, pipe escaped and dollars intact. That is the right assertion: escape what breaks the table, preserve what is part of the name.
Then the control that matters. I reverted the 21 check files to main and kept your test files:
CONTROL against main: passed=5 failed=56
[-] <Id> preserves replacement tokens and the <State> verdict (x56)
So the suite fails against the old code in 56 places and passes against the new one. The tests are not passing for an unrelated reason, and they cover the change across all 21 checks rather than one sample.
The affected-objects regex change is the consequence, and it is the part worth reading twice
Escaping display names in result markdown is only half the job — Get-MtAffectedObjectFromMarkdown then has to parse names that now carry backslash escapes:
-$linkPattern = '\[(?<name>(?:[^\[\]]|\[[^\[\]]*\])+)\]\((?<url>https://[^)\s]+)...'
+$linkPattern = '\[(?<name>(?:\\.|[^\[\]\\]|\[(?:\\.|[^\[\]\\])*\])+)\]\((?<url>https://[^)\s]+)...'Consuming \\. first means an escaped bracket no longer terminates the name, so a name like \[RaviK\] - Policy stays whole instead of being cut at the first escaped bracket. Without this half, the first half would have broken the affected-objects page for exactly the names it set out to protect. Catching that the two have to move together is the thing I would most expect a PR like this to miss.
Worth noting the file already carried the reasoning for why this surface matters:
https only: display names are not escaped in result markdown, so a crafted name can smuggle a
javascript:url into a link that would otherwise match a portal pattern.
That comment described a gap and worked around it at the parser. This PR closes it at the source and updates the workaround to match, which is the right order to do those two things in.
What is left, and it is not yours
The Get-MtSafeMarkdown additions cover tests/cis and tests/maester/entra. tests/ad is untouched and still at 0 of 270 files using the helper while 131 print a directory value into a table — that is my issue #2796 and a separate change. Mentioning it only so the scope of this PR is not mistaken for the whole problem.
BOM correct throughout, and nothing in the diff changes a verdict — every change is to what the result says, not to whether a check passes.
While reviewing name escaping for Conditional Access policy plans in #2733, I came across existing formatting issues in other checks. These also affect standalone policies and do not depend on the plans feature.
Tenant-controlled names can shift report columns, break portal links, or turn
$&/$$into%TestResult%/$.Use literal placeholder insertion in 19 CIS result tables. Recover escaped affected-object link labels without losing unmatched or nested brackets, while retaining ID-based identity. Escape named-location and anti-spam policy names, baseline placeholder app link labels (MT.1259), and authentication-strength names (MT.1224). Existing scope, enforcement-state and pass/fail criteria are unchanged.
Validation:
main(2d659e8) inad49941: the repository unit-test runner reports 681 passed, 1 failed across 8 files covering affected objects, literal CIS names, security-check Markdown, Invoke-Maester, selection, help and encoding. The sole failure is the known missing BOM inInvoke-MtPackGitHubRequest.Tests.ps1, addressed separately by fix(tests): add the missing byte order mark to Invoke-MtPackGitHubRequest.Tests.ps1 #2795.Build-LocalMaester.ps1passes. The earlier post-removal pack-request run also passed all 24 tests.Merge compatibility: current
main(2d659e8) is merged viaad49941; the 24-file report-fix diff is byte-for-byte unchanged against the updated base. Independent of #2733. The existing CA policy/plan table escaping stays in that PR. The generic Markdown-label parser correction is identical in both branches. Both merge orders were simulated and produce the same conflict-free tree; the combined version was tested. The unrelated UTF-8 BOM correction inpowershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1is excluded from this PR and handled separately by #2795. Until that fix lands inmain, the known file-encoding check failure remains.Summary by CodeRabbit