fix(safeoutputs): use sanitize_config for identifier fields instead of sanitize_text#433
Conversation
…f sanitize_text sanitize_text() wraps @-signs in backticks and escapes HTML, which corrupts identifier fields like tags, branch names, labels, and repo names. Switch all identifier fields across 10 safe-output files from sanitize_text() to sanitize_config(), which only strips control characters, neutralizes pipeline commands, and enforces size limits. Rich-text fields (title, description, body, content, comment, reason) remain on sanitize_text(). Co-authored-by: Copilot <[email protected]>
🔍 Rust PR ReviewSummary: Looks good — the fix is correct, well-scoped, and preserves all existing security guarantees. Findings✅ What Looks Good
|
Problem
sanitize_text()(the full sanitization pipeline) wraps@-signs in backticks to prevent ADO mentions, escapes HTML tags, neutralizes bot triggers, etc. These transforms are correct for rich-text content rendered as markdown/HTML in ADO UI, but they corrupt identifier fields like tags, branch names, labels, and repository names.Example: A work item tag
copilot:repo=msazuresphere/4x4/VsCodeExtension@maingets transformed tocopilot:repo=msazuresphere/4x4/VsCodeExtension`@main`— which then failsallowed-tagsvalidation because the backtick-wrapped form doesn't match the allowlist pattern.Fix
Switch all identifier fields from
sanitize_text()→sanitize_config()across 10 safe-output files.sanitize_config()only strips control characters, neutralizes pipeline commands (##vso[/##[), and enforces size limits — safe for identifiers without corrupting them.Fields changed to
sanitize_configadd_build_tag.rstagcreate_work_item.rstagsupdate_work_item.rsstate,area_path,iteration_path,assignee,tagscreate_pr.rslabelscreate_branch.rsbranch_namequeue_build.rsbranch,parameters(keys & values)link_work_items.rslink_typeresolve_pr_thread.rsstatus,repositorysubmit_pr_review.rsevent,repositoryupdate_pr.rsrepository,operation,reviewers,labels,voteFields kept on
sanitize_textRich-text fields:
title,description,body,content,comment,reason— these are rendered as markdown/HTML and need the full pipeline.Test updates
Updated
update_work_item::test_sanitize_fieldsto assert that tags are preserved as-is (no backtick wrapping of@), reflecting the corrected behavior.Validation
cargo build✅cargo test✅ (all pass)cargo clippy --all-targets --all-features✅