Skip to content

fix: escape HTML in the serve build-error overlay - #3293

Merged
Keats merged 3 commits into
getzola:nextfrom
devtechedge:fix/serve-error-html-escape
Oct 8, 2026
Merged

Keats merged 3 commits into
getzola:nextfrom
devtechedge:fix/serve-error-html-escape

Conversation

@devtechedge

@devtechedge devtechedge commented Sep 29, 2026 •

Copy link
Copy Markdown

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/

If you want to add a new feature, please open a thread there first in the feature requests section.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

error_injection_middleware puts error_str straight into the overlay <pre>, with no escaping.

A build error that contains <img or & is then parsed by the browser, which is what #3288 shows with {{ <img src=error onerror=alert(1)> }} under zola serve.

A successful build already emits the author's HTML, so this is the error screen eating the source, not a new boundary.

I escape &, <, >, and " on that string before it goes into the markup, and I left the <pre> in place so the line breaks still show.

Livereload, the 404 page around the overlay, and CLI error printing are unchanged.

The 404 page reuses the same string, so it gets the escaping too.

build_error_overlay_escapes_html checks that <img and & come back as &lt;img and &amp;, and that a plain message stays literal.

Fixes #3288.

  • Are you doing the PR on the next branch?
  • Was a LLM used? If so, for what?

Yes. I used Grok 4.7 (effort/thinking: xhigh) to draft the escape and the test, then I read the diff, ran the test, and I'm standing by the change.

@Keats Keats left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just use a tera template so it's handled automatically, no need to rewrite another escape_html

Address review by replacing hand-rolled escape_html with Tera one_off autoescape.
@devtechedge

Copy link
Copy Markdown
Author

I appreciate the pointer, that is cleaner than a hand rolled escape.

Switched the overlay to a small Tera template with autoescape on, so the error text is escaped automatically and escape_html is gone.

Livereload, the 404 path, and CLI error printing are unchanged.

The existing build_error_overlay_escapes_html test still covers the <img and & case from #3288.

Let me know if you want the template moved elsewhere.

@Keats Keats left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can drop the tests

@devtechedge

Copy link
Copy Markdown
Author

Done, the overlay test and its helpers are out.

The Tera autoescape path is unchanged and still covers the case from #3288.

Let me know if you want the template moved elsewhere.

@Keats
Keats merged commit 7efdae7 into getzola:next Oct 8, 2026
6 checks passed
@Keats

Keats commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks

@devtechedge

Copy link
Copy Markdown
Author

Thanks Vincent, switching the overlay to a Tera template was a much cleaner fix than my hand-rolled escape.

I appreciate the quick reviews and the merge!

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.

2 participants