Skip to content

A decimal character reference with more than 4,300 digits crashes citry check and interactive renders #291

Closed

Description

@JuroOravec

What happens

Python refuses to turn a string of more than 4,300 digits into an int,
and Python's html.unescape does exactly that for &#<digits>;. Citry
calls html.unescape in several places, so a reference such as
&#000…0106; (5,000 zeros, which a browser reads as j) raises an
uncaught ValueError there.

citry check on this file (with --static, or with --app) prints a
traceback and exits with code 1:

from citry import Citry, Component

app = Citry(autodiscover=False)

class Card(Component):
    citry = app
    template = """
        <img role="&#000…0106;">
    """
  File ".../citry/analysis.py", line 1311, in _attribute_value_finding
  File ".../citry/util/html.py", line 116, in decode_attribute_entities
  File ".../citry/util/html.py", line 92, in _decode_attribute_charref
  ...
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5003 digits; use sys.set_int_max_str_digits() to increase the limit

An interactive component (one with js) that prints such a reference in
a Markup value fails to render with the same error, from
_vue/direct_capture.py:2547. The same Markup value in a component
without js renders.

Both failures happen on main and on a build that contains #289; #289
does not change these files.

Cause

#289 fixes this for the output checks of security_csp and
security_javascript: its Rust decoder stops reading digits once the
number passes U+10FFFF and decodes to U+FFFD. The other decoders still go
through html.unescape. On main:

Place What reaches it
packages/py/citry/citry/util/html.py:92 (decode_attribute_entities) authored attribute values, through citry check and the template lint (analysis.py, _markup_lint.py, _css_lint.py, _checker.py, _registry_lint.py)
_vue/direct_capture.py:2547 a Markup value printed as text in an interactive component
ext/i18n/bindings.py:429 a Markup value with no < printed by $c-tr text
_vue/direct_capture.py:3633 and :3656 attribute text read while Citry prepares an interactive component's render
_vue/capture.py:898 and :914, citry_render.py:838 text Citry escaped itself, so & arrives as &amp;. A user value is unlikely to reach these as a raw reference, but they share the same call.

Only the first two rows were run; the others come from reading the code.
decode_attribute_entities is also called at render time for a Markup
attribute value (attrs.py:384, _vue/json_data.py:165,
util/html.py:135). A Markup value with the long reference bound to
:title or :class rendered without error, so those calls were not
traced further.

Who hits it

Almost nobody writes a reference this long on purpose. It matters
because the failure is a crash with an internal traceback, and because a
Markup value built from outside input can carry one and stop an
interactive page from rendering.

Fix direction

Add one helper in citry.util.html that decodes character references by
the browser's rules for numbers: skip leading zeros, stop reading digits
once the value passes U+10FFFF, and decode such a value to U+FFFD. #289's
parse_code_point in crates/citry_html_transform/src/output_policy.rs
does this in Rust. Replace every html.unescape call in the table with it
(or route decode_attribute_entities' numeric branch through it). Add a
test at each place a user value can reach: citry check on a template
with the reference, and an interactive component printing it in
Markup. A grep for unescape( in packages/py/citry/citry finds them.

Found while working on #289 (part of #274).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions