Registry / http-networking / advocate

advocate

JSON →
library1.0.0pypypiunverified

Advocate is a Python library providing a safe wrapper around the popular `requests` library for making HTTP requests on behalf of a third party. It helps prevent common security pitfalls like SSRF by allowing developers to define strict URL validation patterns, limit redirects, set timeouts, and control request options. The current version is 1.0.0, and it maintains a stable release cadence focused on security and reliability.

pip install advocate
INSTALL
IMPORT
SIG · ADVOCATE
A
advocate
http-networkingpythonv1.0.0
Install
4.1s avg
Import
Disk
40MB
Pass rate
1/ 10
Env Coverage1 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✕ build_error
✕ build_error
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 4.1s
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Advocate
from advocate import Advocate

This quickstart demonstrates how to initialize `Advocate` with a strict URL regex pattern, disable redirects, set a timeout, and make a safe GET request. It also shows how the library prevents requests to URLs that don't match the configured pattern, raising `InvalidURLError`.

from advocate import Advocate # Configure Advocate for safe third-party requests # This example allows requests only to google.com/search advocate = Advocate( url_regex_pattern="^https://www\.google\.com/search", max_redirects=0, # Disallow redirects for this sensitive operation raise_on_redirect=True, timeout=5, # Set a timeout to prevent hanging requests requests_options={ "headers": {"User-Agent": "MySafeClient/1.0"}, "verify": True # Ensure SSL verification is on } ) try: # Make a safe GET request response = advocate.get("https://www.google.com/search?q=python+advocate") response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx) print(f"Request successful! Status: {response.status_code}") print("First 200 characters of response:") print(response.text[:200]) except advocate.exceptions.InvalidURLError as e: print(f"Invalid URL error: {e}") except advocate.exceptions.RedirectError as e: print(f"Redirect error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") # Example of a disallowed URL (will raise InvalidURLError) try: advocate.get("http://internal-api.example.com/sensitive-data") except advocate.exceptions.InvalidURLError as e: print(f"Successfully blocked disallowed URL: {e}") except Exception as e: print(f"Unexpected error for disallowed URL: {e}")
Debug
Known issues
gotchaThe `url_regex_pattern` is critical for security. If it's too broad or incorrectly specified, it can negate Advocate's safety features, potentially exposing your application to Server-Side Request Forgery (SSRF) vulnerabilities.
fix
Thoroughly test your `url_regex_pattern` to ensure it only permits intended URLs. Use online regex testers and consider edge cases. It's often safer to define a whitelist of allowed domains/paths rather than trying to blacklist.
affects: 1.0.0+
gotchaMisconfiguring `max_redirects` and `raise_on_redirect` can lead to unexpected behavior or security issues. For third-party requests, unsolicited redirects might point to malicious or unintended destinations.
fix
For sensitive third-party requests, it's generally recommended to set `max_redirects=0` and `raise_on_redirect=True` to explicitly control and prevent redirects. Only allow redirects if you fully trust the redirect chain.
affects: 1.0.0+
gotchaAdvocate adds overhead due to URL validation and other safety checks. Using it for requests where there is no third-party involvement or trust concern can introduce unnecessary performance penalties.
fix
Only use `Advocate` when making HTTP requests on behalf of an untrusted third party or when strict URL validation and request control are required for security. For internal or trusted requests, use `requests` directly.
affects: 1.0.0+
Upgrade
Version history
1.0.0latest on PyPI · released Jul 14, 2020
Audit
Dependencies
requestsrequiredAdvocate is a wrapper around the requests library, using it for underlying HTTP communication.
Agent activity
71 hits · last 30 days
node
60
OpenAI (training)
1
Resources
advocate — pip install advocate · libregistry