Coder Social home page Coder Social logo

lucacasonato / ammonia-wasm Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 3.0 2.75 MB

WASM bindings for the Ammonia HTML sanitizer

Home Page: https://deno.land/x/ammonia

License: MIT License

TypeScript 57.89% Makefile 0.19% JavaScript 28.23% Rust 13.69%
deno html5 sanitizer wasm

ammonia-wasm's Introduction

ammonia-wasm

deno doc

WASM bindings for the Ammonia HTML sanitizer.

Ammonia is a whitelist-based HTML sanitization library written in Rust. It is designed to prevent cross-site scripting, layout breaking, and clickjacking caused by untrusted user-provided HTML being mixed into a larger web page.

Ammonia uses html5ever to parse and serialize document fragments the same way browsers do, so it is extremely resilient to syntactic obfuscation.

Ammonia parses its input exactly according to the HTML5 specification; it will not linkify bare URLs, insert line or paragraph breaks, or convert (C) into ©. If you want that, use a markup processor before running the sanitizer.

How to use

import * as ammonia from "https://deno.land/x/[email protected]/mod.ts";
await ammonia.init();

// Simple cleaning with conservative defaults.
ammonia.clean("XSS<script>attack</script>"); // XSS

// Custom options
const builder = new ammonia.AmmoniaBuilder();
builder.tags.delete("p"); // strip the <p> tag
const cleaner = builder.build();
ammonia.clean("foo<p>bar</p>"); // foobar

For exact details on the options on AmmoniaBuilder or any other API, view deno doc.

Thanks

Thanks to the authors of Ammonia (@notriddle, and @lnicola), the countless of contributors to html5ever, and the HTML spec authors.

Additional thanks to the @denosaurs folks for the build.ts script this repo uses.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.