Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

sonalys/sanitize

Open more actions menu

Repository files navigation

Sanitize

Go Reference Tests codecov

Sanitize is a sanitization library.
It's purpose is to allow content policy enforcement. This library currently supports HTML.

Examples

package sanitize_test

import (
	"bytes"
	"fmt"
	"strings"

	"github.com/sonalys/sanitize"
)

const testEmail = `` +
	`<html><head>
<title>My Email</title>
</head>
<body>
<script>
	alert('not allowed');
</script>
<img onload="alert('not allowed')" src="a" />
<a href="http://visit.me">click here</a></body></html>
`

func ExampleHTML() {
	r := strings.NewReader(testEmail)
	w := bytes.NewBuffer(make([]byte, 0, len(testEmail)))

	err := sanitize.HTML(r, w,
		sanitize.DefaultEmailPolicies(),
	)
	if err != nil {
		panic(err)
	}

	fmt.Print(w.String())
	// Output:
	// <html><head>
	// <title>My Email</title>
	// </head>
	// <body>
	//
	// <img/>
	// <a href="http://visit.me" rel="noreferrer nofollow">click here</a>
	// </body></html>
}

Contribution

Refer to contributing.md

License

This repository is licensed under the MIT License

About

A very small library for html content policy and sanitization, focused on email html

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.