New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mattkrick/sanitize-svg

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mattkrick/sanitize-svg - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

36

dist/lib/sanitizeSVG.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const svgDisallowed = [
'a',
'animate',
'color-profile',
'cursor',
'discard',
'fedropshadow',
'font-face',
'font-face-format',
'font-face-name',
'font-face-src',
'font-face-uri',
'foreignobject',
'hatch',
'hatchpath',
'mesh',
'meshgradient',
'meshpatch',
'meshrow',
'missing-glyph',
'script',
'set',
'solidcolor',
'unknown',
'use'
];
const getWindow = () => (typeof window === 'undefined' ? null : window);

@@ -27,11 +53,11 @@ const readAsText = (svg) => new Promise((resolve) => {

throw new Error('Image corrupt');
const div = window.document.createElement('div');
div.innerHTML = svgText;
const svgEl = div.firstElementChild;
const playground = window.document.createElement('template');
playground.innerHTML = svgText;
const svgEl = playground.content.firstElementChild;
const attributes = Array.from(svgEl.attributes).map(({ name }) => name);
const hasScriptAttr = !!attributes.find((attr) => attr.startsWith('on'));
const scripts = svgEl.getElementsByTagName('script');
return scripts.length === 0 && !hasScriptAttr ? svg : null;
const disallowedSvgElements = svgEl.querySelectorAll(svgDisallowed.join(','));
return disallowedSvgElements.length === 0 && !hasScriptAttr ? svg : null;
};
exports.default = sanitizeSVG;
//# sourceMappingURL=sanitizeSVG.js.map

2

package.json
{
"name": "@mattkrick/sanitize-svg",
"version": "0.3.1",
"version": "0.4.0",
"description": "a small script to remove script tags from SVGs",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc