Skip to content

No check under tests/ad/ escapes directory data in its result markdown (0 of 270; 77 print a name into a table) #2796

Open

Description

@earbona23

Summary

No check under tests/ad/ escapes directory data before putting it in the result markdown. Not one of 270. Seventy-seven of them put a name-like attribute into a markdown table row, in 95 places.

This is the sibling of #2711, which is about 15 checks using HtmlEncode instead of Get-MtSafeMarkdown. Those at least escape something. The AD surface escapes nothing.

Measured

On main at 02a220b2, over tests/ad/*/*.ps1:

AD checks:                                                270
with a markdown table:                                    268
that interpolate a value into a table row:                148
that interpolate a name-like attribute into a table row:   77   (95 places)
that call Get-MtSafeMarkdown:                               0

"Name-like" means the interpolated expression reads Name, DisplayName, DistinguishedName, SamAccountName, Description, ZoneName, Trustee*, Account, Principal*, Identity, Owner* or Member*. Counters, booleans and computed verdicts are not counted.

A sample of what it looks like:

$result += "| $($_.Name) | $($_.Count) |" + "`n"
$result += "| $($_.Name) | $($_.Enabled) | $($_.DistinguishedName) |" + "`n"
$result += "| $($zone.ZoneName) | $($zone.ZoneType) |" + "`n"

Why it matters

Get-MtSafeMarkdown's own description states the rule and the consequence:

Use this for any value that comes from the tenant (display names, app names, policy names, etc.) before inserting it into test result markdown. Without it, a value such as an app registration named ![x](https://attacker.example/pixel.png) or [Sign in again](https://phish.example) would be rendered by the report as a remote image or a clickable link, and a | would break table layout.

Everything in that sentence applies to a directory object. An AD object's cn or description is far less constrained than a sAMAccountName: a group named [Open ticket](https://phish.example) or a description containing a | reaches the report with no escaping at all. A Maester AD report is routinely shared with people who did not run it, which is the audience the link renders for.

sAMAccountName is restricted enough that it probably cannot carry a pipe, so the realistic carriers are description, cn and display names, DNs that embed an escaped name, and any error string that quotes one.

Why not a PR per check

95 places across 77 files, in one of the areas under most active development right now — #2783, #2784, #2785, #2786 and #2734 all add or move AD checks this week, and all follow the current convention, which is no escaping. Hand-editing 77 files against that would conflict with every one of them and would be obsolete by the time it was reviewed.

What I think it needs, in order:

  1. A gate first, so the number cannot grow. A general test in the shape of TestParameterNames.Tests.ps1 that fails when a check under tests/ad/ interpolates one of those attribute names into a markdown table row without Get-MtSafeMarkdown, with the current 77 as a baseline that may only fall. That is how the class stops expanding while the backlog is worked off, and it is the same ratchet shape the repository already uses elsewhere.
  2. Then the sweep, in batches by folder (user/, group/, dacl/, spn/, …) so each is reviewable.

I am happy to write both. I would rather agree the gate's shape here first, since a general test that fails on the whole AD surface on day one is only useful if the baseline is accepted along with it.

Not claimed

I have not found a tenant where this is exploited, and this is not a vulnerability report: it needs someone who can already name an AD object, which in most domains means delegated rights over an OU. It is the same reasoning that made #2254 worth doing for Entra, applied to the surface that never got it.

Activity

  1. earbona23 commented on Nov 13, 2026

    @earbona23
    ContributorAuthor

    Adding a second defect that lives in these same files, because it is not the one this issue describes and Get-MtSafeMarkdown does not fix it.

    @julien-ly measured on a tenant in #2800 that a Conditional Access policy named Maester 2800 $& $$ test renders on main as Maester 2800 %TestResult% $ test. The cause is the last line of the idiom these checks all end with:

    $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result

    -replace is Regex.Replace, and Regex.Replace interprets $&, $$, $1 and ${name} in the replacement string. $& is the whole match, so it expands back to %TestResult%. #2800 fixes its own 22 call sites by switching to .Replace(), which takes the argument literally.

    Why this is a separate problem from the one above: Get-MtSafeMarkdown escapes \ ` * _ [ ] ( ) ! | < > ~ : @ and the dot after www. $ is not in that set and does not belong there, since $ means nothing in Markdown. So escaping an AD name correctly still leaves it open to this. Fixing #2796 as written would not close it.

    Measured on main (2d659e8), same method as above — I cut the raw count down rather than report it, because most of these tables carry only numbers:

    files with -replace '%TestResult%' / '%ResultDetail%' and a variable replacement:  501
    of those, interpolating a directory or tenant name into that variable:            133
    

    tests/ad/computer/Test.AD-COMP-10.ps1 is the case I read end to end: $($_.Name) and $($_.DistinguishedName) go into $result at L92 and L105, and $result is the replacement at L114. A computer object named WS-$&-01 puts %TestResult% in the middle of the table. It is the same file and the same line this issue already quotes, which is the useful part: the AD checks need both changes, and one of them is a one-character edit per call site.

  2. added
    product: ad
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product: ad

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions