Skip to content

fix(security): XSS via HTML attributes and code blocks - #21

Merged
brendt merged 4 commits into
tempestphp:mainfrom
peaklabs-dev:fix/parser-hardening
Aug 5, 2026
Merged

fix(security): XSS via HTML attributes and code blocks#21
brendt merged 4 commits into
tempestphp:mainfrom
peaklabs-dev:fix/parser-hardening

Conversation

@peaklabs-dev

Copy link
Copy Markdown
Contributor

Issue

Attribute values (href, src, alt, class, id) and un-highlighted code blocks were interpolated into HTML without escaping, so markdown input could break out of an attribute and cause an XSS injection.

new Markdown()->parse('[click](https://evil.co" onclick="alert(1))')->html;
// before: <p><a href="https://evil.co" onclick="alert(1">click</a>)</p>
// after:  <p><a href="https://evil.co&quot; onclick=&quot;alert(1">click</a>)</p>

Changes

  • Escape HTML attribute values in token rendering
  • Escape code blocks with highlighter: null
  • Generate a proper slug for auto heading IDs
  • Expand heading auto slugs to non-Latin languages

slugs are now restricted to [a-z0-9-] instead of only replacing spaces. This ensures the generated slug can no longer contain quotes or other characters that could break out of the id attribute.
@peaklabs-dev
peaklabs-dev marked this pull request as ready for review August 4, 2026 17:10
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Benchmark Results

Comparison of fix/parser-hardening against main (81d9dcb9288ef1d18f40c4a36ec8379377417ca9).

Open to see the benchmark results
Benchmark Set Mem. Peak Time Variability
MarkdownBench(benchTempest) 01-small 3.708mb +0.02% 0.337ms +9.76% ±2.06% +125.95%
MarkdownBench(benchTempest) 02-large 6.755mb +0.27% 18.885ms +11.99% ±0.50% +126.69%

Generated by phpbench against commit 29b9404

@brendt

brendt commented Aug 5, 2026

Copy link
Copy Markdown
Member

Looking great! Thanks

@brendt
brendt merged commit 7878bfe into tempestphp:main Aug 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants