Skip to content

Harden the HTML formatter against CSS.#3071

Merged
Anteru merged 1 commit intomasterfrom
harden-html-formatter
Mar 26, 2026
Merged

Harden the HTML formatter against CSS.#3071
Anteru merged 1 commit intomasterfrom
harden-html-formatter

Conversation

@Anteru
Copy link
Copy Markdown
Collaborator

@Anteru Anteru commented Mar 26, 2026

Escape various text-only attributes using html.escape.

Escape various text-only attributes using `html.escape`.
@Anteru Anteru added this to the 2.20.0 milestone Mar 26, 2026
@Anteru Anteru requested a review from birkenfeld March 26, 2026 19:17
@Anteru Anteru added the A-lexing area: changes to individual lexers label Mar 26, 2026
@Anteru Anteru merged commit d7c3453 into master Mar 26, 2026
15 checks passed
ahuimanu pushed a commit to tvproductions/gzkit that referenced this pull request Apr 22, 2026
…#281)

The previous patch (commit df13783) pinned pygments<2.20 to work
around the mkdocs strict-build crash. That pin reverted a security
fix: pygments 2.20.0 ships the HTML-formatter hardening from
pygments/pygments#3071 ("Harden the HTML formatter against CSS"),
which pymdownx.highlight tripped only because it was passing
filename=None under a specific config path.

Correct root cause, traced through pymdownx/highlight.py:

- Line 392-396: `title` stays None when `auto_title` is off AND no
  explicit title attribute is set on the fenced block.
- Line 410: `filename=title if not inline else ""`.
- Line 179: `HtmlFormatter.__init__(self, **options)` with filename=None.
- pygments 2.20.0 HtmlFormatter.__init__ line 434 now calls
  `html.escape(...)` on the value directly; None is no longer tolerated.

Fix: set `auto_title: true` on the pymdownx.highlight extension in
mkdocs.yml. This guarantees `title` is auto-generated from the lexer
name (never None), so `filename` reaches HtmlFormatter as a string, and
the pygments 2.20.0 hardening check is satisfied.

Reverts the pyproject.toml / requirements-docs.txt pygments pin added
by df13783. pygments upgrades cleanly via `uv lock --upgrade-package
pygments`; 2.20.0 restored. Verified:

  $ uv run mkdocs build --strict
  INFO -  Documentation built in 2.21 seconds

Security hardening retained. Correct fix for the class of failure is
"always pass a valid filename," not "pin to the pre-hardening version."

Closes #281
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lexing area: changes to individual lexers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants