Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
An asynchronous HTTP proxy server library using aiohttp, designed to forward requests from clients to a target server
shadowserver
is an asynchronous HTTP proxy server library using aiohttp
, designed to forward requests from clients to a target server. It handles HTTP and WebSocket connections, provides CORS support, and offers flexible SSL verification options, making it ideal for backend service proxying and server simulations in testing environments.
aiohttp
for handling multiple concurrent requests efficiently.You can install shadowserver
via pip:
pip install shadowserver
Below is a basic example of how to set up and run shadowserver
.
from shadowserver import ShadowServer
import asyncio
async def main():
# Initialize the server with the target URL and optional settings
proxy = ShadowServer(
target_base_url="https://example.com",
timeout=30,
max_conn=100,
open_on_browser=True,
verify_ssl=True
)
# Start the server
await proxy.start_server(host="127.0.0.1", port=8080)
# Run the server
asyncio.run(main())
To disable SSL verification for outgoing HTTPS requests, pass verify_ssl=False
during initialization:
proxy = ShadowServer(
target_base_url="https://example.com",
verify_ssl=False # Disables SSL verification for HTTPS requests
)
This can be useful for development environments where the target server uses a self-signed certificate.
The ShadowServer
class includes an optional redirect feature to automatically redirect requests from the base URL to a specified URL. This is enabled by passing a redirect_url
and setting redirects=True
.
str
/
) is accessed.bool
redirect_url
.Here are some examples showing how to configure the ShadowServer
with URL redirection.
In this example, requests to the base URL (/
) will be redirected to the URL specified in redirect_url
:
from shadowserver import ShadowServer
import asyncio
BASE_URL = "https://example.com/api"
REDIRECT_URL = "https://example.com/home"
server = ShadowServer(
target_base_url=BASE_URL,
redirect_url=REDIRECT_URL,
redirects=True
)
asyncio.run(server.start_server(
host="127.0.0.1",
port=3000
))
http://127.0.0.1:3000/
will automatically redirect to https://example.com/home
.http://127.0.0.1:3000/some/path
) will be proxied to https://example.com/api/some/path
.To use ShadowServer
as a proxy without redirection, omit redirect_url
and set redirects=False
:
from shadowserver import ShadowServer
import asyncio
BASE_URL = "https://example.com/api"
server = ShadowServer(
target_base_url=BASE_URL,
redirects=False # Disables redirection
)
asyncio.run(server.start_server(
host="127.0.0.1",
port=3000
))
You can specify a custom route that will be appended to the base URL. This is useful when you want the server to be accessible via a specific route.
proxy = ShadowServer(
target_base_url="https://example.com",
route="/customroute"
)
asyncio.run(proxy.start_server(host="127.0.0.1", port=8080))
To configure custom timeouts and connection limits during initialization:
proxy = ShadowServer(target_base_url="https://example.com", timeout=60, max_conn=200)
This example sets a 60-second timeout and allows up to 200 concurrent connections.
The main class for setting up and running the proxy server.
class ShadowServer:
def __init__(self, target_base_url, timeout=30, max_conn=100)
target_base_url
(str): The base URL to which all proxied requests are forwarded.timeout
(int, optional): Timeout in seconds for requests to the target server. Default is 30
.max_conn
(int, optional): Maximum number of concurrent connections. Default is 100
.redirect_url
(str, optional): URL for redirecting requests from the base URL.redirects
(bool, optional): If True
, enables redirection to redirect_url
. Default is False
.open_on_browser
(bool, optional): Automatically opens the server URL in a browser when started. Default is True
.verify_ssl
(bool, optional): If False
, disables SSL verification. Default is True
.route
(str, optional): Appends a custom route to the server URL.start_server
async def start_server(self, host='127.0.0.1', port=8080)
Starts the proxy server.
Parameters:
host
(str, optional): The host IP on which the server runs. Default is '127.0.0.1'
.port
(int, optional): The port on which the server listens. Default is 8080
.close
async def close(self)
Closes the server session and frees up resources.
The ShadowServer
proxy server processes requests as follows:
Once the server is running, you can make a GET request to any endpoint available on the target server:
curl http://127.0.0.1:8080/api/resource
This request will be proxied to https://example.com/api/resource
.
The proxy supports WebSocket connections. You can connect to the WebSocket server via the proxy as shown below:
import websockets
import asyncio
async def connect():
uri = "ws://127.0.0.1:8080/socket"
async with websockets.connect(uri) as websocket:
await websocket.send("Hello, World!")
response = await websocket.recv()
print(response)
asyncio.run(connect())
If you encounter CORS issues, ensure that the client request headers include the correct Origin
.
To disable SSL verification, set verify_ssl=False
when initializing the server.
FAQs
An asynchronous HTTP proxy server library using aiohttp, designed to forward requests from clients to a target server
We found that shadowserver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.