Skip to content

Properly escape JS values in head_insert template - #1003

Open
ato wants to merge 1 commit into
mainfrom
template-fix
Open

Properly escape JS values in head_insert template#1003
ato wants to merge 1 commit into
mainfrom
template-fix

Conversation

@ato

@ato ato commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Description

Removes the custom tojson filter in favor of the standard Jinja one which is actually safe in a HTML context (json.dumps doesn't escape </script>). This stops us using ujson but I wouldn't expect it's providing a worthwhile speedup for these small values anyway.

Removes the dangerous autoescape false. Instead uses the tojson filter for the JavaScript values and the safe filter for the trusted HTML of the custom banner.

Motivation and Context

The lack of escaping is unsafe and is vulnerable to a malicious WARC file. See discussion in #990.

Types of changes

  • Replay fix (fixes a replay specific issue)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added or updated tests to cover my changes.
  • All new and existing tests passed.

Removes the custom tojson filter in favor of the standard Jinja one which is actually safe in a HTML context. This stops us using `ujson` but I wouldn't expect it's providing a worthwhile speedup for these small values anyway.

Removes the dangerous `autoescape false`. Instead uses the `tojson` filter for the JavaScript values and the `safe` filter for the trusted HTML of the custom banner.

Supercedes #990.
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.

1 participant