Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

py-svg-hush

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

py-svg-hush

  • 0.1.2
  • PyPI
  • Socket score

Maintainers
1

py-svg-hush

py-svg-hush is a Python package for sanitizing SVG files using the svg-hush Rust library.

Installation

py-svg-hush requires Python 3.7 or later. You can install it using pip:

pip install py-svg-hush

Usage

from py_svg_hush import filter_svg

svg_bytes = b"""
<svg xmlns="http://www.w3.org/2000/svg">
    <script>alert('Malicious script')</script>
</svg>
"""

keep_data_url_mime_types = {
    "image": ["jpeg", "png", "gif"],
}

sanitized_svg = filter_svg(svg_bytes, keep_data_url_mime_types)

filter_svg

The filter_svg function sanitizes SVG data by removing potentially malicious elements and attributes, as well as restricting the allowed MIME types of data: URLs in the SVG. It is a simple wrapper around the underlying Rust function.

Parameters
  • svg (bytes): The SVG data to be filtered.
  • keep_data_url_mime_types (Optional[Dict[str, List[str]]]): A dictionary that maps MIME types to lists of allowed subtypes for data: URLs in the SVG. If a data: URL's MIME type and subtype are not in the dictionary it will be dropped. If this parameter is None, all data: URLs are dropped.
Returns
  • (bytes): The sanitized SVG data.
Raises
  • ValueError: If there is an error processing the SVG data.
  • TypeError: If any of the arguments are of the wrong type.

Development

To set up a development environment for py-svg-hush, you can use the following steps:

Clone the repository:

git clone git@github.com:jams2/py-svg-hush.git

Install development dependencies:

pip install .[dev,testing]

Build the Rust library, resulting in a Python module:

maturin develop

Run tests:

pytest

FAQs


Did you know?

Socket

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.

Install

Related posts

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