Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
escape-html
Advanced tools
The escape-html package is designed to provide a simple and efficient way to escape HTML entities in strings. This is particularly useful to prevent XSS (Cross-Site Scripting) attacks by sanitizing user input or any data that might be dynamically inserted into HTML documents. The primary functionality of this package is to convert characters like '<', '>', '&', '"', and "'" into their corresponding HTML entities, making the output safe to include in HTML content.
Escaping HTML entities
This feature allows the conversion of potentially dangerous characters into their safe HTML entity equivalents. The provided code sample demonstrates how to use the escape-html package to escape a string that contains HTML and JavaScript, which could be harmful if rendered directly in a web page.
"const escapeHtml = require('escape-html');\nconst unsafeString = '<script>alert(\"XSS\")</script>';\nconst safeString = escapeHtml(unsafeString);\nconsole.log(safeString); // Output: <script>alert("XSS")</script>"
The 'he' package is a robust HTML entity encoder/decoder written in JavaScript. Unlike escape-html, which primarily focuses on escaping strings for safe HTML insertion, 'he' offers more comprehensive functionalities including the ability to decode HTML entities back to their original form. This makes 'he' more versatile for handling HTML entities in various contexts.
While escape-html is focused on escaping strings to prevent XSS attacks, 'sanitize-html' goes a step further by allowing detailed configuration of what HTML tags and attributes are allowed. It can remove or sanitize HTML to a whitelist of allowed elements and attributes, making it a more comprehensive solution for sanitizing HTML content beyond just escaping entities.
Escape string for use in HTML
var escape = require('escape-html');
var html = escape('foo & bar');
// -> foo & bar
$ npm run-script bench
> escape-html@1.0.3 bench nodejs-escape-html
> node benchmark/index.js
http_parser@1.0
node@0.10.33
v8@3.14.5.9
ares@1.9.0-DEV
uv@0.10.29
zlib@1.2.3
modules@11
openssl@1.0.1j
1 test completed.
2 tests completed.
3 tests completed.
no special characters x 19,435,271 ops/sec ±0.85% (187 runs sampled)
single special character x 6,132,421 ops/sec ±0.67% (194 runs sampled)
many special characters x 3,175,826 ops/sec ±0.65% (193 runs sampled)
MIT
FAQs
Escape string for use in HTML
The npm package escape-html receives a total of 30,418,141 weekly downloads. As such, escape-html popularity was classified as popular.
We found that escape-html demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.