Skip to content

Avoid implicit innerHTML assignments #2636

@blois

Description

@blois

Since innerHTML assignments can lead to unintended side effects it should be clear to consumers of these APIs when data may lead to an innerHTML assignment.

An example of an assignment which should probably be clearer:

import ipywidgets as widgets
widgets.Checkbox(description="<marquee>this is html</marquee>")

Potential ways to address this:

  • Switch to textContent assignments. This is the easiest to audit and in many cases may be what users expect.
  • Use a sanitizer to sanitize the text before assigning to innerHTML. Good for cases where you want to allow rich content but not arbitrary code execution.
  • Require an opt-in to use innerHTML or to disable sanitization.

From a quick glance, a few places that could be worth changing:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions