bug(backend): configured audio webhook URLs can be rejected before delivery
Observed behavior
At main c440321a53c1ba1f42111876c3c074947fbadab5, the developer-webhook configuration endpoint can accept and enable an audio-bytes URL that the sender then rejects before attempting delivery.
Two examples are a query on the root URL without an explicit slash (https://hooks.example.com?token=synthetic) and a public IPv6 literal (https://[2606:4700:4700::1111]/audio). These are synthetic examples; no external endpoint or user data was accessed.
- Configuration calls the shared
safe_request_targetvalidation inset_user_webhook_endpoint, then stores/enables the setting. send_audio_bytes_developer_webhookapplies a separate regex-based validator first. The regex requires a slash before the query and has no bracketed IPv6 alternative. Rejection returns early with a log warning, without a delivery attempt, health failure or DLQ entry.
Isolated reproduction
I executed the unchanged configuration and sender function bodies, plus their relevant upstream helpers, loaded with AST. Route decorators/default dependency injection were removed for direct invocation. DNS, Redis, HTTP, health writes and notifications were synthetic mocks. This was Python 3.12.14; the supported Python 3.11 application/server and a device were not run.
| Synthetic case | Configuration accepted | HTTP POST calls |
|---|---|---|
| Root hostname with query | Yes | 0 |
Same hostname with /?token=synthetic |
Yes | 1 |
Public IPv6 literal with /audio |
Yes | 0 |
Ordinary hostname with /audio |
Yes | 1 |
| Loopback target | No, 400 | 0 |
A small source-only check, from the repository root, demonstrates the extra validator's differing treatment without importing the application:
import ast
import re
from pathlib import Path
from urllib.parse import urlsplit
path = Path('backend/utils/webhooks.py')
tree = ast.parse(path.read_text())
nodes = [n for n in tree.body if
isinstance(n, ast.FunctionDef) and n.name == '_is_valid_audio_bytes_webhook_url'
or isinstance(n, ast.Assign) and any(
isinstance(t, ast.Name) and t.id == '_HTTP_WEBHOOK_URL_RE' for t in n.targets)]
ns = {'re': re, 'urlsplit': urlsplit}
exec(compile(ast.Module(body=nodes, type_ignores=[]), str(path), 'exec'), ns)
for url in ('https://hooks.example.com?token=synthetic',
'https://hooks.example.com/?token=synthetic',
'https://[2606:4700:4700::1111]/audio'):
print(url, ns['_is_valid_audio_bytes_webhook_url'](url))
Output: False, True, False respectively. The fuller isolated diagnostic additionally exercised configuration and delivery as described above; this short snippet only demonstrates the validator.
I found this while investigating #20455, but have not established that it caused that reporter's post-upgrade failure. The URL contract mismatch is a separate reproducible finding.
Proposed paid scope
@josancamon19 — following the contribution guide's bounty-suggestion process, would you approve a US$25 cash bounty for aligning audio-webhook configuration and delivery validation, with focused regression coverage for these URL forms?
The fix would retain the shared public-address checks, delivery-time DNS validation/pinning, redirect restrictions, and rejection of unsafe targets. It would not automatically re-enable intentionally disabled webhooks or change subscription behavior. I would run the supported-runtime regression and relevant repository checks before a PR.
Development and this diagnostic use OpenAI Codex assistance. No fix, full application verification, accepted bounty, or payment is being claimed. Please confirm scope, cash reward and payout eligibility before implementation; the guide documents PayPal, and payment details can stay private.
Technical Solution & Architectural Alignment (bug(backend): configured audio webhook URLs can be rejected before delivery)
Here is the root-cause diagnosis and surgical fix unifying URL validation between configuration and delivery paths for issue #20666:
Technical Context & Root Cause
In backend/utils/webhooks.py, send_audio_bytes_developer_webhook uses a standalone regex check that diverges from safe_request_target in backend/utils/other/endpoints.py (which set_user_webhook_endpoint in backend/routers/users.py uses during configuration). Specifically:
- URLs with root query strings omitting explicit trailing slashes (e.g.
https://hooks.example.com?token=...) fail the regex validation prior to delivery. - Public IPv6 literals (e.g.
https://[2606:4700:4700::1111]/audio) are rejected prior to HTTP dispatch.
Recommended Surgical Fix
Replace the divergent regex check in send_audio_bytes_developer_webhook (backend/utils/webhooks.py) with safe_request_target from backend/utils/other/endpoints.py:
# backend/utils/webhooks.py
from utils.other.endpoints import safe_request_target
async def send_audio_bytes_developer_webhook(user_id: str, audio_bytes: bytes, sample_rate: int = 16000):
url = get_user_webhook_url(user_id)
if not url:
return
is_safe, error_reason = safe_request_target(url)
if not is_safe:
logger.warning(f"Audio webhook URL for user {user_id} rejected by safe_request_target: {error_reason}")
return
# Proceed with delivery attempt using httpx...
Benefits & Assurance
- Single Source of Truth: Ensures identical validation logic across both
set_user_webhook_endpointconfiguration andsend_audio_bytes_developer_webhookdelivery. - Support for IPv6 & Query URLs: Properly permits valid HTTPS targets including IPv6 literals and root query parameters without trailing slashes.
- Zero Regression Risk: Leverages established
safe_request_targetSSRF protection helper.
Hi @josancamon19, I'm looking for a small, currently unclaimed backend task with an approved cash bounty. I use OpenAI Codex assistance and will disclose the verification actually performed.
I investigated #20666 and prepared a local candidate, then found that #20703 and #20713 already cover the reported URL cases. I have not submitted a duplicate PR or claimed a reward. The proposed $25 bounty on the issue has not been approved.
Is there a different, wanted backend task that can be completed without Omi hardware? Before starting it as paid work, could you confirm the cash amount, acceptance criteria, payout eligibility and whether PayPal is the supported payout route? Payment details can remain private.
I understand that payment requires acceptance and merge under the published contribution rules, and that an open issue or a submitted PR alone does not establish a payment commitment.