refac
This commit is contained in:
1 parent
7c0b0e42f5
commit
741b64edb6
2 files changed
+5
-10
No files matched your search
@@ -1,15 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
from open_webui.config import WEBUI_FAVICON_URL
|
from open_webui.config import WEBUI_FAVICON_URL
|
||||||
from open_webui.env import (
|
from open_webui.env import (
|
||||||
AIOHTTP_CLIENT_ALLOW_REDIRECTS,
|
AIOHTTP_CLIENT_ALLOW_REDIRECTS,
|
||||||
AIOHTTP_CLIENT_SESSION_SSL,
|
AIOHTTP_CLIENT_SESSION_SSL,
|
||||||
AIOHTTP_CLIENT_TIMEOUT,
|
|
||||||
VERSION,
|
VERSION,
|
||||||
)
|
)
|
||||||
from open_webui.retrieval.web.utils import validate_url
|
from open_webui.retrieval.web.utils import get_ssrf_safe_session, validate_url
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -33,9 +31,9 @@ async def post_webhook(
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
try:
|
try:
|
||||||
log.debug(f'post_webhook: {url}, {message}, {event_data}')
|
log.debug(f'post_webhook: {url}, {message}, {event_data}')
|
||||||
# Block private-IP / loopback / cloud-metadata targets — the URL is
|
# Block private-IP / loopback / cloud-metadata targets for every
|
||||||
# caller-controlled (user notification settings under
|
# webhook source, including admin-managed event webhooks and
|
||||||
# ENABLE_USER_WEBHOOKS, automation notification triggers).
|
# user-configured notification URLs.
|
||||||
validate_url(url)
|
validate_url(url)
|
||||||
payload = {}
|
payload = {}
|
||||||
|
|
||||||
@@ -80,9 +78,7 @@ async def post_webhook(
|
|||||||
payload = event_data
|
payload = event_data
|
||||||
|
|
||||||
log.debug(f'payload: {payload}')
|
log.debug(f'payload: {payload}')
|
||||||
async with aiohttp.ClientSession(
|
async with get_ssrf_safe_session() as session:
|
||||||
trust_env=True, timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT)
|
|
||||||
) as session:
|
|
||||||
async with session.post(
|
async with session.post(
|
||||||
url,
|
url,
|
||||||
json=payload,
|
json=payload,
|
||||||
|
|||||||
Reference in new issue
Block a user