ssrf_proxy.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Proxy requests to avoid SSRF
  3. """
  4. import os
  5. from httpx import get as _get
  6. from httpx import head as _head
  7. from httpx import options as _options
  8. from httpx import patch as _patch
  9. from httpx import post as _post
  10. from httpx import put as _put
  11. from requests import delete as _delete
  12. SSRF_PROXY_HTTP_URL = os.getenv('SSRF_PROXY_HTTP_URL', '')
  13. SSRF_PROXY_HTTPS_URL = os.getenv('SSRF_PROXY_HTTPS_URL', '')
  14. requests_proxies = {
  15. 'http': SSRF_PROXY_HTTP_URL,
  16. 'https': SSRF_PROXY_HTTPS_URL
  17. } if SSRF_PROXY_HTTP_URL and SSRF_PROXY_HTTPS_URL else None
  18. httpx_proxies = {
  19. 'http://': SSRF_PROXY_HTTP_URL,
  20. 'https://': SSRF_PROXY_HTTPS_URL
  21. } if SSRF_PROXY_HTTP_URL and SSRF_PROXY_HTTPS_URL else None
  22. def get(url, *args, **kwargs):
  23. return _get(url=url, *args, proxies=httpx_proxies, **kwargs)
  24. def post(url, *args, **kwargs):
  25. return _post(url=url, *args, proxies=httpx_proxies, **kwargs)
  26. def put(url, *args, **kwargs):
  27. return _put(url=url, *args, proxies=httpx_proxies, **kwargs)
  28. def patch(url, *args, **kwargs):
  29. return _patch(url=url, *args, proxies=httpx_proxies, **kwargs)
  30. def delete(url, *args, **kwargs):
  31. return _delete(url=url, *args, proxies=requests_proxies, **kwargs)
  32. def head(url, *args, **kwargs):
  33. return _head(url=url, *args, proxies=httpx_proxies, **kwargs)
  34. def options(url, *args, **kwargs):
  35. return _options(url=url, *args, proxies=httpx_proxies, **kwargs)