All Projects → rehypejs → Rehype Sanitize

rehypejs / Rehype Sanitize

Licence: mit
plugin to sanitize HTML

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Rehype Sanitize

Eyepetizer
An unofficial Eyepetizer(开眼视频) App built using Ijkplayer, RxJava2, Retrofit2, Dagger2, Room , DataBinding and Clean-MVVM Architecture.
Stars: ✭ 22 (-15.38%)
Mutual labels:  clean
Furo
A clean customizable documentation theme for Sphinx
Stars: ✭ 267 (+926.92%)
Mutual labels:  clean
Neovim Init.vim
🏮 The perfect Neovim configuration for productive people who wants to level up their Vim experience with a clean, minimal-looking aesthetic, as well as a highly extensible, easily customizable set of popular tools and shortcuts to boost productivity. 🏮
Stars: ✭ 440 (+1592.31%)
Mutual labels:  clean
typester
✒️ A WYSIWYG that gives you predictable and clean HTML
Stars: ✭ 29 (+11.54%)
Mutual labels:  clean
Tin Summer
Find build artifacts that are taking up disk space
Stars: ✭ 259 (+896.15%)
Mutual labels:  clean
Clean Architecture Zh
《架构整洁之道》中文翻译
Stars: ✭ 299 (+1050%)
Mutual labels:  clean
mold
✂️ Is a general library to help modify or set data within data structures and other objects.
Stars: ✭ 114 (+338.46%)
Mutual labels:  clean
Nord Tmux
An arctic, north-bluish clean and elegant tmux color theme.
Stars: ✭ 567 (+2080.77%)
Mutual labels:  clean
Alduin
[DISCONTINUED] An RSS, Atom and JSON feed aggregator available on Windows and Linux.
Stars: ✭ 272 (+946.15%)
Mutual labels:  clean
Discord bot.py
🍺 A simple discord bot that helps you getting started within discord.py
Stars: ✭ 313 (+1103.85%)
Mutual labels:  clean
riblet-sample
A sample to represent Uber Riblets design pattern using Swift.
Stars: ✭ 42 (+61.54%)
Mutual labels:  clean
strip-markdown
plugin remove Markdown formatting
Stars: ✭ 84 (+223.08%)
Mutual labels:  clean
Modclean
Remove unwanted files and directories from your node_modules folder
Stars: ✭ 309 (+1088.46%)
Mutual labels:  clean
git-bonsai
Tend the branches of your git garden
Stars: ✭ 15 (-42.31%)
Mutual labels:  clean
Cola
🥤 COLA: Clean Object-oriented & Layered Architecture
Stars: ✭ 6,186 (+23692.31%)
Mutual labels:  clean
Modesta
🎨 A clean CSS framework made to be dark, responsive and easy to build with.
Stars: ✭ 76 (+192.31%)
Mutual labels:  clean
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (+996.15%)
Mutual labels:  clean
Cleanmywechat
自动删除 PC 端微信缓存数据,包括从所有聊天中自动下载的大量文件、视频、图片等数据内容,解放你的空间。
Stars: ✭ 816 (+3038.46%)
Mutual labels:  clean
Hugo Paper
🥛 A simple, clean, flexible Hugo theme
Stars: ✭ 538 (+1969.23%)
Mutual labels:  clean
.emacs.d
🎉 Personal GNU Emacs configuration
Stars: ✭ 313 (+1103.85%)
Mutual labels:  clean

rehype-sanitize

Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to sanitize HTML.

Install

npm:

npm install rehype-sanitize

Use

Say we have the following file, index.html:

<div onmouseover="alert('alpha')">
  <a href="jAva script:alert('bravo')">delta</a>
  <img src="x" onerror="alert('charlie')">
  <iframe src="javascript:alert('delta')"></iframe>
  <math>
    <mi xlink:href="data:x,<script>alert('echo')</script>"></mi>
  </math>
</div>
<script>
require('child_process').spawn('rm', ['-r', '-f', process.env.HOME]);
</script>

And our script, example.js, looks as follows:

var fs = require('fs')
var rehype = require('rehype')
var merge = require('deepmerge')
var gh = require('hast-util-sanitize/lib/github')
var sanitize = require('rehype-sanitize')

var schema = merge(gh, {tagNames: ['math', 'mi']})

rehype()
  .data('settings', {fragment: true})
  .use(sanitize, schema)
  .process(fs.readFileSync('index.html'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

<div>
  <a>delta</a>
  <img src="x">

  <math>
    <mi></mi>
  </math>
</div>

API

rehype().use(sanitize[, schema])

Remove potentially dangerous things from HTML, or more correct: keep only the safe things in a document.

schema

The sanitation schema defines how and if nodes and properties should be cleaned. The schema is documented in hast-util-sanitize.

Security

Improper use of rehype-sanitize can open you up to a cross-site scripting (XSS) attack. The defaults are safe, but deviating from them is likely unsafe.

Use rehype-sanitize after all other plugins, as other plugins are likely also unsafe.

Related

Contribute

See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].