Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@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 1.6.0 (https://github.com/punkave/sanitize-html).
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/sanitize-html
Additional Details
These definitions were written by Rogier Schouten https://github.com/rogierschouten.
FAQs
TypeScript definitions for sanitize-html
The npm package @types/sanitize-html receives a total of 991,418 weekly downloads. As such, @types/sanitize-html popularity was classified as popular.
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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.