Skip to main content

groovy

A small Python library created to help developers protect their applications from Server Side Request Forgery (SSRF) attacks. It implements an asynchronous GET method called groovy.get(), which is a wrapper around httpx.AsyncClient.get() while performing DNS validation on the supplied URL using Google DNS.

It also implements mitigation for DNS rebinding attacks.

Why?

Server Side Request Forgery (SSRF) attacks can be particularly dangerous as they allow attackers to make arbitrary HTTP requests from your server, potentially accessing sensitive internal services that are normally unreachable from the internet. This could enable attackers to scan internal networks, access metadata services in cloud environments (like "AWS Instance Metadata Service"), or hit internal APIs - all while appearing to come from your trusted server. By validating URLs against public DNS servers and implementing protections against DNS rebinding, groovy helps prevent attackers from coercing your application into making requests to internal or otherwise restricted network resources.

Usage

Installation

$ pip install groovy

Also avalaible through Conda

$ conda install groovy -c conda-forge

or

$ mamba install groovy -c conda-forge

Basic Usage

import groovy as sh

await sh.get("https://huggingface.co")
>>> <Response [200 OK]>

await sh.get("http://127.0.0.1")
>>> ValueError: Hostname 127.0.0.1 failed validation

Note on Async Usage:

The example snippets above will work in environments like IPython or Jupyter notebooks where an asyncio event loop is already running. For regular Python scripts, you'll need to explicitly create and run an asyncio event loop. Here's how you can structure your code to use groovy in a standard Python script:

import asyncio
import groovy as sh

asyncio.run(sh.get("https://huggingface.co"))
>>> <Response [200 OK]>

Whitelisted Domains

You may want to whitelist certain domains from being validated. For example, if you are running code on a server that implements DNS splitting, then even public URLs may appear as internal URLs. You can whitelist domains like this:

import groovy as sh

PUBLIC_HOSTNAME_WHITELIST = ["hf.co", "huggingface.co"]

await sh.get("https://huggingface.co", domain_whitelist=PUBLIC_HOSTNAME_WHITELIST)
>>> <Response [200 OK]>

Custom Transports (Advanced)

If you know what you are doing, and what to pass in a custom instance of httpx.AsyncBaseTransport, you can use the _transport parameter in sh.get(). Setting this to False explicitly will use no secure transport (effectively making sh.get equivalent to httpx.AsyncClient.get()).

More Information

This library was created as a result of Trail of Bits' security audit of Gradio 5 (Hugging Face), and is used in the Gradio library to make secure requests to arbitrary user-specified URLs. We are releasing this as a standalone library so that other developers can benefit from our learnings. In the interest of transparency and the spirit of open-source, we are making the full security audit public.

If you find a security issue in this library, please email the Gradio team at gradio-team@huggingface.co. Thanks!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

groovy-0.0.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

groovy-0.0.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file groovy-0.0.3.tar.gz.

File metadata

  • Download URL: groovy-0.0.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for groovy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3181353a759035f73fa466a73d45c16985136b03fdb465b8821b1f3f99424d2c
MD5 a79259d2ebb07b8cb8175f40c4c6b5ad
BLAKE2b-256 185d6ea8e2916923c95097b531a82f83659ae64cee34c569cee1304aaae6b5b1

See more details on using hashes here.

File details

Details for the file groovy-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: groovy-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for groovy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42974b3ae8b3d53701c3bc9fc47ef57e0838bd1acd0c75f4b8582bfbc926ddd8
MD5 d76b2f21afdaba00308a290ef49a3a5f
BLAKE2b-256 976a4722bb81217e9425d57babf6c3f68e43c99b45b16a6a1bdd84f99d82f235

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page