Skip to content

🪲 15 checks added after #2254 escape tenant names with HtmlEncode instead of Get-MtSafeMarkdown #2711

Open

Description

@earbona23

Pre-submission checklist

  • I can reproduce this issue using the latest released version of Maester.
  • I have searched the existing issues and did not find a similar report.

Describe the bug

#2254 standardised escaping of tenant-controlled names on Get-MtSafeMarkdown and closed with an explicit rule:

New checks should use Get-MtSafeMarkdown for any tenant-controlled value.

Fifteen checks added after that PR merged (2026-09-29) escape names with [System.Net.WebUtility]::HtmlEncode(...) -replace '\|', '|' instead: fourteen landed 2026-10-18 and MT.1260 on 2026-10-29. HtmlEncode escapes HTML, not markdown — and per #2254's own design, the markdown vector the report does not block is the one it leaves open.

#2254 blocks remote images in the report (report/src/lib/markdownUrl.ts) and says of the other case: "Links keep react-markdown's default policy." So for links, escaping at the call site is the only control, and HtmlEncode is not it.

Steps to reproduce

Fed the published 2.3.0 report template a result whose table cell was escaped exactly as those fifteen checks escape it, with Get-MtSafeMarkdown on the row below as a control, and opened it in a browser. No tenant involved: the names are synthetic and the host is a reserved .example name.

Name a tenant could set Escaped with HtmlEncode (the fifteen) Escaped with Get-MtSafeMarkdown
[Sign in again to continue](https://…/phish) <a href="https://…/phish">Sign in again to continue</a> — a live clickable link shown as literal text
![beacon](https://…/beacon.png) <img alt="beacon"> — element injected, src stripped by #2254's own guard, and the name is gone from the cell shown as literal text
Contoso **admin** _app_ `` code` `` Contoso <strong>admin</strong> <em>app</em> <code>code</code> — the name renders as something else shown as literal text
Contoso | Admin | hidden renders intact (the &#124; replacement does hold) renders intact

So of the three harms #2254 lists, the | one is handled by these checks, the beacon is handled by the report, and the phishing link is not handled anywhere for them. Two smaller consequences fall out of the same gap: a display name can hide itself (image syntax leaves an empty <img>) or render as different text (emphasis, code).

Expected behavior

Tenant-controlled values go through Get-MtSafeMarkdown, as #2254 states for new checks.

Where

28 call sites in 15 files on main @ 6165598. Not every one is equally exposed — built-in role names are not tenant-controlled — but the display names, UPNs and app names are.

File and line
File Lines
tests/maester/entra/Test.MT.1200.ps1 104
tests/maester/entra/Test.MT.1201.ps1 105, 107
tests/maester/entra/Test.MT.1203.ps1 95
tests/maester/entra/Test.MT.1204.ps1 162
tests/maester/entra/Test.MT.1205.ps1 128
tests/maester/entra/Test.MT.1206.ps1 249, 263
tests/maester/entra/Test.MT.1207.ps1 246, 251, 268, 290, 292
tests/maester/entra/Test.MT.1208.ps1 167
tests/maester/entra/Test.MT.1209.ps1 144, 149, 172, 174
tests/maester/entra/Test.MT.1210.ps1 175, 184, 206, 208
tests/maester/entra/Test.MT.1211.ps1 111
tests/maester/entra/Test.MT.1212.ps1 85
tests/maester/entra/Test.MT.1213.ps1 115
tests/maester/entra/Test.MT.1223.ps1 62
tests/maester/entra/Test.MT.1260.ps1 139, 140

One more is in flight: MT.1261 in #2688 carries the same two lines, so it is cheaper to change there than after merge. cc @Dfrank77 — MT.1262 and MT.1263 in #2689 and #2704 do not have this; their service principal names go through Get-MtLinkServicePrincipal, which calls the helper.

What this is not

No script execution: react-markdown renders raw HTML as text, as #2254 notes. No remote image request either — I checked, and the guard added in #2254 strips the src. The live vector is the link, plus the two display-integrity cases above.

Module version

2.3.0 (the pattern is in the shipped module: Test-MtEntraAgentBlueprintOrphaned, Test-MtEntraAgentForeignPrivileged and Test-MtEntraAgentIdentityOrphaned among others), and on main @ 6165598.

Environment data

Linux, PowerShell 7, Maester 2.3.0 from the PowerShell Gallery; report rendered in Chromium. Synthetic result object, no tenant connection.

Offer

Happy to send the 28-line swap as a PR, and to add a unit test asserting that no check applies HtmlEncode to a tenant-controlled value so the rule from #2254 holds by CI rather than by review. Say whether you want it as one PR or split by product, and whether the ~200 remaining plain-text sites named in #2254's follow-up should be in scope or left for their own pass.

Activity

  1. earbona23 commented on Nov 7, 2026

    @earbona23
    ContributorAuthor

    One more place the same question arises, which I hit while writing a family test and did not want to decide alone.

    Instance titles carry tenant-controlled names raw. A family's instance source returns a Title, and the ones on main interpolate the name straight in:

    • tests/maester/entra/Test.MT.1024.ps1:21 — Title = "$($recommendation.displayName)."
    • tests/maester/defender/Test.MT.1059.ps1:50 — Title = "MDI Health Issues - $($issueGroup.Name)."

    Neither goes through Get-MtSafeMarkdown, and the same holds for the Azure families. Whether that matters depends on something I could not settle by reading: whether a title is ever rendered as markdown. In the report I built to measure the table cells, the title appeared as plain text, so it may well be safe — but "it looked like text in the view I happened to open" is not an answer, and the title also travels into the JSON, the markdown report and the summary.

    So, as a question rather than a finding: is an instance title markdown-rendered anywhere?

    • If it is, this is a class across every family test, not a test-by-test fix, and it belongs with the 15 above.
    • If it is not, it is worth one line in writing-tests saying so, because the natural assumption from the Get-MtSafeMarkdown documentation — "use this for any value that comes from the tenant" — is that titles need it too, and the next contributor will either escape them unnecessarily or leave a cell unescaped for the same reason.

    I have left the titles alone in #2712 and followed the existing convention rather than deviating on my own.

  2. Dfrank77 commented on Nov 7, 2026

    @Dfrank77
    Contributor

    One more gap in the same area, raised by CodeRabbit on #2710: Get-MtSafeMarkdown doesn’t escape bare URLs, and the report renders with GFM (gfm: true in report/src/components/Markdown.tsx), so a display name like Sign in at https://phish.example/login still renders as a clickable link. That affects every check using the helper, so it probably needs a fix in the helper or the renderer rather than per check.

  3. earbona23 commented on Nov 7, 2026

    @earbona23
    ContributorAuthor

    Confirmed end to end, and it is slightly worse than stated. Measured with this repository's own helper and the report's own dependency and setting, not by reasoning about the spec.

    Method. Dot-sourced powershell/public/report/Get-MtSafeMarkdown.ps1 from main rather than reimplementing its regex, fed its real output to marked@18.1.3 with gfm: true (the version in report/package.json and the setting at report/src/components/Markdown.tsx:11), then ran the result through DOMPurify exactly as Markdown.tsx:32 does.

    tenant-controlled name after the helper rendered
    Sign in at https://phish.example/login unchanged <a href="https://phish.example/login">
    Sign in [aqui](https://phish.example) [aqui] and ( ) escaped [aqui]( as literal text, followed by a live link to the host
    Contoso **admin** \*\* **admin** as literal text — the helper does its job here

    The second row is the part worth adding to what you raised. The helper does stop the payload from being disguised: the visible text ends up being the URL itself rather than "Sign in again". But a clickable link to the attacker's host still renders, because the URL left behind in the text gets autolinked anyway. So for the link case the helper downgrades the attack rather than removing it.

    The sanitiser does not catch it, which I checked because it would have been the obvious place for this to be already handled: DOMPurify.sanitize keeps the anchor. Control, to show the sanitiser was actually running: the same call strips <script> and a javascript: href.

    Line 48 of the helper escapes \ ` * _ [ ] ( ) ! | < > ~. Neither : nor / is in that set, which is why a bare URL passes through untouched.

    On where to fix it, I agree it is the renderer rather than the helper, and here is a measured option. gfm: false is not available — it would take the tables with it. But disabling only marked's url tokenizer keeps GFM and drops the autolinks:

    marked.use({ tokenizer: { url() { return undefined } } })

    Measured on a table cell containing the bare URL: the table still renders, and the anchor is gone. Control: the same cell without the override does produce the anchor.

    That is a one-line change in one file, against escaping two more characters in a helper that every check calls — and it also covers the row-two case, which helper-side escaping would not.

    What I did not measure: I rendered with marked and DOMPurify standalone, not by building and opening the report app, so I have not confirmed the end result in the browser. And I have not checked whether anything in the report relies on autolinking working.

  4. earbona23 commented on Nov 7, 2026

    @earbona23
    ContributorAuthor

    Correcting myself on the fix I proposed an hour ago, before anyone acts on it. I said disabling marked's url tokenizer was a one-line change and I listed "whether anything relies on autolinking" as something I had not measured. I have now measured it, and it is not free.

    Across the .md files under tests/ on main:

    URLs count affected by disabling autolink
    in [text](url) syntax 2,410 no
    inside fenced code blocks 55 no — code spans are not autolinked anyway
    bare, in prose 119 yes — they stop being clickable

    They are real documentation links, not incidental text: learn.microsoft.com/entra/identity/conditional-access/... in the MT.10xx remediation docs, aka.ms/CATemplates..., anssi.gouv.fr in an AD-GPOREP doc. Turning those into plain text in the report is a usability regression a reader would notice, so the one-liner trades a security hole for 119 broken affordances.

    Resolved: option two, and it is open as #2715. Escaping in the helper, so the renderer and those 119 documentation links are untouched.

    : and @ join the escape set, and the dot after www is escaped in a second pass, because that autolink form contains neither. : alone is not enough: strip it from mailto:a@b and the bare a@b autolinks on its own. A plain contoso.com is left alone, since GFM does not autolink it and escaping every dot would be noise in the JSON for no gain.

    Measured against the report's own stack — the helper dot-sourced from this repository, then marked@18.1.3 with gfm: true, then DOMPurify as Markdown.tsx:32 calls it. All seven shapes stop linking, and all of them read back identically to the input:

    tenant-controlled name before after
    https://phish.example/login <a href> text
    http://phish.example/login <a href> text
    ftp://phish.example/x <a href> text
    www.phish.example/login <a href> text
    admin@phish.example <a href> text
    mailto:admin@phish.example <a href> text
    [aqui](https://phish.example) <a href> text

    That last row turned out to matter: the helper already neutralised the markdown link, but the URL left behind was autolinked anyway, so the payload was downgraded rather than removed.

    Tests: 18 of 18 in the helper's own file, and 45 of 45 across both Pester files in the repository that reference it — two existing expectations encoded the old output and are updated, nine cases added.

    Leaving the measurement above in place, since the 119 count is the reason the renderer route was the wrong call and that is worth keeping on the record.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions