Skip to content

Fix double-escaping in parseTypesMarkdown#1462

Merged
dav-is merged 4 commits into
masterfrom
codeql/double-escaping
May 19, 2026
Merged

Fix double-escaping in parseTypesMarkdown#1462
dav-is merged 4 commits into
masterfrom
codeql/double-escaping

Conversation

@Janpot

@Janpot Janpot commented May 14, 2026

Copy link
Copy Markdown
Member

Summary

Reorder decodeHtmlEntities in parseTypesMarkdown so &amp; is unescaped last. The previous order meant inputs like &amp;lt; would be unescaped to &lt; and then to <, instead of the correct &lt;. Fixes CodeQL alert #65 (js/double-escaping).

Ideally markdown isn't used as a data interchange format

Reorder `decodeHtmlEntities` so `&amp;` is replaced last, preventing inputs like `&amp;lt;` from being decoded twice into `<` instead of `&lt;`.
@code-infra-dashboard

code-infra-dashboard Bot commented May 14, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-1462--mui-internal.netlify.app/

Bundle size

Total Size Change: 0B(0.00%) - Total Gzip Change: 0B(0.00%)
Files: 29 total (0 added, 0 removed, 0 changed)

Show details for 29 more bundles

@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindowparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchorparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClientparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarsparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 16.93 ms -0.59 ms(-3.4%) | Renders: 4 (+0) | Paint: 72.40 ms -3.04 ms(-4.0%)

No significant changes — details


Check out the code infra dashboard for more information about this PR.

@Janpot Janpot marked this pull request as ready for review May 18, 2026 10:49
@Janpot Janpot requested a review from Copilot May 18, 2026 10:49

Copilot AI 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.

Pull request overview

This PR adjusts HTML entity decoding in the docs-infra parseTypesMarkdown pipeline to prevent double-unescaping (e.g. avoiding &amp;lt; becoming <), addressing the CodeQL js/double-escaping alert.

Changes:

  • Reordered decodeHtmlEntities() replacements so &amp; is decoded after other entities, preventing double-unescaping.
  • Added a regression test ensuring inline-code types like `&amp;lt;T&amp;gt;` decode to &lt;T&gt; (not <T>).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/docs-infra/src/pipeline/loadServerTypesText/parseTypesMarkdown.ts Reorders HTML entity decoding to avoid double-unescaping.
packages/docs-infra/src/pipeline/loadServerTypesText/parseTypesMarkdown.test.ts Adds a regression test for inline-code entity decoding.

Comment on lines +1623 to +1637
it('should not double-unescape HTML entities in inline code', async () => {
// `&amp;lt;` must decode to `&lt;` (single unescape), not `<`.
const markdown = `### Button

**Button Props:**

| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| name | \`&amp;lt;T&amp;gt;\` | - | - |
`;

const result = await parseTypesMarkdown(markdown);
const componentMeta = (result.exports.Button.type as { data: ComponentTypeMeta }).data;
expect(componentMeta.props.name.typeText).toBe('&lt;T&gt;');
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Added a second test case in commit 7e25cb0 that asserts &amp;amp;lt;T&amp;amp;gt; decodes to &amp;lt;T&amp;gt; (only one level of &amp; unescaped), covering the double-encoded pattern mentioned in the feedback.

Copilot AI commented May 18, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of Janpot May 18, 2026 10:59
@Janpot Janpot requested a review from a team May 18, 2026 12:59
@zannager zannager added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label May 18, 2026
@dav-is dav-is added the type: bug It doesn't behave as expected. label May 19, 2026
@dav-is dav-is merged commit 8db9f6d into master May 19, 2026
14 checks passed
@dav-is dav-is deleted the codeql/double-escaping branch May 19, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants