Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@types/sanitize-html
Advanced tools
@types/sanitize-html provides TypeScript type definitions for the sanitize-html library, which is used to sanitize HTML input by removing potentially dangerous elements and attributes.
Basic HTML Sanitization
This feature allows you to sanitize a string of HTML by removing any potentially dangerous elements like <script> tags.
const sanitizeHtml = require('sanitize-html');
const dirty = '<script>alert("xss")</script><div>Safe content</div>';
const clean = sanitizeHtml(dirty);
console.log(clean); // Output: <div>Safe content</div>
Customizing Allowed Tags and Attributes
This feature allows you to specify which HTML tags and attributes are allowed in the sanitized output.
const sanitizeHtml = require('sanitize-html');
const dirty = '<a href="http://example.com" onclick="stealCookies()">Click me</a>';
const clean = sanitizeHtml(dirty, {
allowedTags: [ 'a' ],
allowedAttributes: {
'a': [ 'href' ]
}
});
console.log(clean); // Output: <a href="http://example.com">Click me</a>
Transforming Tags
This feature allows you to transform specific tags in the HTML input, such as changing the src attribute of img tags.
const sanitizeHtml = require('sanitize-html');
const dirty = '<img src="http://example.com/image.jpg" />';
const clean = sanitizeHtml(dirty, {
transformTags: {
'img': sanitizeHtml.simpleTransform('img', { 'src': 'https://example.com/placeholder.jpg' })
}
});
console.log(clean); // Output: <img src="https://example.com/placeholder.jpg">
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML, and SVG. It is similar to sanitize-html but focuses on being very fast and tolerant of different input types.
xss is a module used to filter input from users to prevent XSS attacks. It is similar to sanitize-html but offers more configuration options and a different API for defining allowed tags and attributes.
html-sanitizer is a lightweight HTML sanitizer that removes potentially dangerous elements and attributes. It is similar to sanitize-html but is designed to be simpler and more lightweight.
npm install --save @types/sanitize-html
This package contains type definitions for sanitize-html (https://github.com/punkave/sanitize-html).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sanitize-html.
These definitions were written by Rogier Schouten, Afshin Darian, BehindTheMath, Rinze de Laat, Will Gibson, A penguin, Johan Davidsson, Jianrong Yu, GP, tomotetra, and Dariusz Syncerek.
FAQs
TypeScript definitions for sanitize-html
We found that @types/sanitize-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.