-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(components): Record audio files incorrectly saved with .jpg extension #6869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,46 @@ | |
| logger = logging.getLogger("astrbot") | ||
|
|
||
|
|
||
| def save_temp_audio(audio_data: bytes) -> str: | ||
| """Save audio data to a temporary file with a proper extension.""" | ||
| temp_dir = get_astrbot_temp_path() | ||
| timestamp = f"{int(time.time())}_{uuid.uuid4().hex[:8]}" | ||
| p = os.path.join(temp_dir, f"recordseg_{timestamp}.audio") | ||
| with open(p, "wb") as f: | ||
| f.write(audio_data) | ||
| return p | ||
|
|
||
|
|
||
| async def download_audio_by_url(url: str) -> str: | ||
| """Download audio from URL. Returns local file path.""" | ||
| try: | ||
| ssl_context = ssl.create_default_context(cafile=certifi.where()) | ||
| connector = aiohttp.TCPConnector(ssl=ssl_context) | ||
| async with aiohttp.ClientSession( | ||
| trust_env=True, | ||
| connector=connector, | ||
| ) as session: | ||
| async with session.get(url) as resp: | ||
| resp.raise_for_status() | ||
| data = await resp.read() | ||
| return save_temp_audio(data) | ||
| except (aiohttp.ClientConnectorSSLError, aiohttp.ClientConnectorCertificateError): | ||
| logger.warning( | ||
| f"SSL certificate verification failed for {url}. " | ||
| "Disabling SSL verification (CERT_NONE) as a fallback. " | ||
| "This is insecure and exposes the application to man-in-the-middle attacks. " | ||
| "Please investigate and resolve certificate issues." | ||
| ) | ||
| ssl_context = ssl.create_default_context() | ||
| ssl_context.check_hostname = False | ||
| ssl_context.verify_mode = ssl.CERT_NONE | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(url, ssl=ssl_context) as resp: | ||
|
Comment on lines
+45
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Reconsider or constrain the SSL verification disabled fallback for security-sensitive contexts This fallback fully disables certificate and hostname verification, which creates significant MITM risk if used with arbitrary URLs. If we truly need this behavior, please gate it behind an explicit config/flag, restrict it to a known host list, or otherwise tightly scope when verification is disabled so it cannot occur in general use by default. |
||
| resp.raise_for_status() | ||
| data = await resp.read() | ||
| return save_temp_audio(data) | ||
|
|
||
|
|
||
| def on_error(func, path, exc_info) -> None: | ||
| """A callback of the rmtree function.""" | ||
| import stat | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.