servo / servo/html5ever

Using html5ever in wasm package for an isomorphic html sanitizer

Open
#497 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
288
Avg merge
2d 22h
Merged PRs (30d)
8

Description

Hello,

I am looking at ways to build an HTML5 sanitizer capable of running in both Browser, NodeJS and Java environments, Java being the lowest priority at the moment. The most important requirement is to not rely on a DOM to be able to operate in these environments. I stumbled upon html5ever and it looks like the perfect tool to use for my scenario with the added benefit that it's part of the Servo project.

For Browser and NodeJS environments I would have to produce WASM artifacts given the simplicity of dealing with multiple platforms in NodeJS but also because of environments where I may not be able to load NodeJS binary native plugins. For Browser environments or mobile WebView there is no other option than producing a WASM artifact so these are the restrictions around the distribution process which I am fine with.

I am using Rust to build the sanitizer so this keeps things easy to manage staying in the same programming language all the way in the development process.

Currently, when compiling html5ever to WASM I get an output of 450kb even when running it through wasm-opt and being very aggressive on the optimizations for size. Unfortunately that is way too big of a file for the Web. Ideally, if it can be around 50kb it would make html5ever a much more desirable alternative to existing Javascript sanitizers for the browser.

I would like to ask if there is a way to either compile html5ever to WASM so that I can reach my desired target size or, alternatively, use only features from the parser that I currently need in hopes that by doing this I will manage to shave off a considerable amount of code.
My main scenario is the following: given a string containing HTML, produce a DOM tree which can be traversed to identify tags, attributes and attribute values which should be eliminated. Return a string.

Thank you for taking the time to read this issue, hopefully with your help I'll be able to use html5ever to achieve my goals.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by measuring the current html5ever WASM artifact and reviewing which parser features the proposed sanitizer actually needs. Determine whether a supported build or feature-reduction path can approach the 50kb target while parsing HTML into a traversable tree and returning sanitized HTML.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.