Skip to content

fix(entra): escape Markdown in agent check results - #2774

Merged
merill merged 2 commits into
maester365:mainfrom
FiraSenax:codex/fix-entra-agent-markdown
Nov 10, 2026
Merged

merill merged 2 commits into
maester365:mainfrom
FiraSenax:codex/fix-entra-agent-markdown

Conversation

@FiraSenax

@FiraSenax FiraSenax commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Tenant-controlled values in 14 Agent ID checks are HTML-encoded but still interpreted as Markdown in the report. A display name can become a disguised link, add formatting, or disappear into an image element.

Apply Get-MtSafeMarkdown at 39 output sites covering names, UPNs, roles, groups, resource names, redirect URIs and descriptions, including passing observation tables. Let the helper handle pipes and line breaks. Retain HTML encoding before Markdown escaping so names containing literal entities such as © keep their original text.

Addresses #2711. These are the 14 remaining checks listed there; MT.1260 already adopted the helper in #2710.

Validation on macOS, PowerShell 7.5.2 and Pester 5.7.1:

  • Added 136 fixture cases exercising the actual native check functions. On unchanged main 34e16ef4, 122 fail and 14 pass; all 136 pass with this patch. Cases cover disguised links, images, formatting, bare URLs, www URLs, email addresses, pipes/line breaks and literal HTML entities in findings and custom-role observations.
  • All 244 focused Agent ID/helper tests passed.
  • Full unit wrapper passed in a clean temporary checkout with the exact patch: 191 files, 8,642 cases — 8,549 passed, 93 skipped, zero failures. This includes 1,700 ScriptAnalyzer cases. The native metadata of all 14 changed checks is identical to main.
  • Module build and packaged-module validation passed.
  • Rendered the captured results with the report's locked Marked 18.1.3 and DOMPurify 3.4.17, its GFM/raw-HTML settings and image hook, using JSDOM 31.0.0. Before the fix, 84 of 136 cases produced links, 17 produced image elements, and 64 changed the supplied text. After the fix, every supplied value remains literal, no link/image elements are injected, and all table rows retain their column counts.

All inputs in the regression and renderer checks are synthetic.

Summary by CodeRabbit

  • Bug Fixes

    • Entra security reports now safely render names, reasons, permissions, and other values containing Markdown-sensitive characters, links, or line breaks.
    • Corrected the displayed formatting of user principal names in excessive-access findings.
  • Tests

    • Added coverage for Markdown rendering across Entra Agent findings and observations.

@FiraSenax
FiraSenax requested review from a team as code owners November 10, 2026 06:03
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

Entra Agent report tables now pass encoded values through Get-MtSafeMarkdown. New Pester tests check Markdown escaping in findings and observations across multiple literal shapes.

Changes: Entra Agent Markdown output

Layer / File(s) Summary
Sanitize report values
tests/maester/entra/Test.MT.1200.ps1, tests/maester/entra/Test.MT.1201.ps1, tests/maester/entra/Test.MT.1203.ps1, tests/maester/entra/Test.MT.1204.ps1, tests/maester/entra/Test.MT.1205.ps1, tests/maester/entra/Test.MT.1206.ps1, tests/maester/entra/Test.MT.1207.ps1, tests/maester/entra/Test.MT.1208.ps1, tests/maester/entra/Test.MT.1209.ps1, tests/maester/entra/Test.MT.1210.ps1, tests/maester/entra/Test.MT.1211.ps1, tests/maester/entra/Test.MT.1212.ps1, tests/maester/entra/Test.MT.1213.ps1, tests/maester/entra/Test.MT.1223.ps1
Report tables pass HTML-encoded names and other values through Get-MtSafeMarkdown instead of applying inline pipe escaping and newline replacement.
Verify Markdown escaping
powershell/tests/functions/Test-MtEntraAgentMarkdown.Tests.ps1, powershell/tests/functions/Test-MtEntraAgentSecurity.Tests.ps1
Parameterized tests check escaped output and verdicts for findings and passing observations. The security test now expects an escaped username.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • maester365/maester#2711 — The issue concerns Markdown interpretation in tenant-controlled values in the same Agent ID checks; this PR applies Get-MtSafeMarkdown to those output values.

Possibly related PRs

  • maester365/maester#2715 — That PR changes Get-MtSafeMarkdown to escape GFM autolinks; this PR applies the helper to Entra Agent findings and observations and tests escaped URLs and usernames.

Suggested labels: bug, product: entra, status: needs review

Suggested reviewers: merill, samerde

Merge Risk: Minimal · previous review 59f71

No actionable issue is established from the supplied evidence; the change is mergeable after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly summarizes the main change: escaping Markdown in Entra agent check results.
Description check Passed The description explains the change, scope, issue addressed, and validation results. It does not include the template’s checklist or an Additional Information heading, but it is otherwise complete.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (16 skipped: 16 unsupported.)

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 34e16ef and 59f718c.

Files selected for processing: 16

  • powershell/tests/functions/Test-MtEntraAgentMarkdown.Tests.ps1
  • powershell/tests/functions/Test-MtEntraAgentSecurity.Tests.ps1
  • tests/maester/entra/Test.MT.1200.ps1
  • tests/maester/entra/Test.MT.1201.ps1
  • tests/maester/entra/Test.MT.1203.ps1
  • tests/maester/entra/Test.MT.1204.ps1
  • tests/maester/entra/Test.MT.1205.ps1
  • tests/maester/entra/Test.MT.1206.ps1
  • tests/maester/entra/Test.MT.1207.ps1
  • tests/maester/entra/Test.MT.1208.ps1
  • tests/maester/entra/Test.MT.1209.ps1
  • tests/maester/entra/Test.MT.1210.ps1
  • tests/maester/entra/Test.MT.1211.ps1
  • tests/maester/entra/Test.MT.1212.ps1
  • tests/maester/entra/Test.MT.1213.ps1
  • tests/maester/entra/Test.MT.1223.ps1

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

# Keep the existing HTML encoding as well: Markdown decodes a raw © or A.
@{ Shape = 'literal HTML entities'; Text = 'Contoso © A A &'; Escaped = 'Contoso © A A &' }
)
$findingCases = foreach ($check in $checks) {
$findingCases = foreach ($check in $checks) {
foreach ($name in $names) { $check + $name }
}
$observationCases = foreach ($check in $checks | Where-Object Id -In 'MT.1207', 'MT.1209', 'MT.1210') {
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

The capture only served a renderer check outside the repo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Entire-Checkpoint: 01M73GAEKXR7XGF02CNA7498VS

@merill merill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @FiraSenax, nice thorough fix, and good call keeping the HtmlEncode before the escape so literal entities survive. Approving.

I pushed one small cleanup: dropped the MarkdownCapturePath param and the capture code from Test-MtEntraAgentMarkdown.Tests.ps1, since it only served the renderer check outside the repo (it also clears the code-scanning alert).

@merill
merill merged commit 8dbb86d into maester365:main Nov 10, 2026
15 of 16 checks passed
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.

3 participants