Quote the credentials in the Freebox camera stream URL (#184572)

This commit is contained in:
Franck Nijhof
2026-10-06 22:24:54 -04:00
committed by GitHub
parent e44e2164f6
commit 0b8675e78f
2 changed files with 56 additions and 1 deletions
+19 -1
View File
@@ -1,6 +1,7 @@
"""Support for Freebox cameras."""
from typing import Any, override
from urllib.parse import quote
from aiohttp import web
from haffmpeg.camera import CameraMjpeg
@@ -62,6 +63,23 @@ def add_entities(
async_add_entities(new_tracked, True)
def _quote_credentials(url: str) -> str:
"""Quote the credentials in a stream URL.
The Freebox generates the camera password, which can contain characters like
a slash that break parsing the URL if they are not percent-encoded.
"""
scheme, separator, rest = url.partition("://")
credentials, at_sign, location = rest.rpartition("@")
if not separator or not at_sign:
return url
user, colon, password = credentials.partition(":")
return (
f"{scheme}://{quote(user, safe='')}{colon}{quote(password, safe='')}@{location}"
)
class FreeboxCamera(FreeboxHomeEntity, Camera):
"""Representation of a Freebox camera."""
@@ -87,7 +105,7 @@ class FreeboxCamera(FreeboxHomeEntity, Camera):
@override
async def stream_source(self) -> str:
"""Return the stream source."""
return self._input.split(" ")[-1]
return _quote_credentials(self._input.split(" ")[-1])
@override
async def async_camera_image(
+37
View File
@@ -4,11 +4,13 @@ from copy import deepcopy
from unittest.mock import Mock
from freezegun.api import FrozenDateTimeFactory
import pytest
from homeassistant.components.camera import (
DOMAIN as CAMERA_DOMAIN,
SERVICE_DISABLE_MOTION,
SERVICE_ENABLE_MOTION,
async_get_stream_source,
)
from homeassistant.components.freebox import SCAN_INTERVAL
from homeassistant.components.freebox.const import DOMAIN
@@ -115,3 +117,38 @@ async def test_motion_detection_toggle(
blocking=True,
)
router().home.set_home_endpoint_value.assert_called_with(15, 0, {"value": True})
@pytest.mark.parametrize(
("stream", "expected_source"),
[
pytest.param(
"http://freeboxcam:AaaA/1A1@192.168.1.10/img/stream.m3u8",
"http://freeboxcam:AaaA%2F1A1@192.168.1.10/img/stream.m3u8",
id="slash_in_password",
),
pytest.param(
"http://freeboxcam:Aa%1A@192.168.1.10/img/stream.m3u8",
"http://freeboxcam:Aa%251A@192.168.1.10/img/stream.m3u8",
id="percent_in_password",
),
pytest.param(
"http://freeboxcam:AaaA1A1@192.168.1.10/img/stream.m3u8",
"http://freeboxcam:AaaA1A1@192.168.1.10/img/stream.m3u8",
id="plain_password",
),
],
)
async def test_stream_source_quotes_credentials(
hass: HomeAssistant, router: Mock, stream: str, expected_source: str
) -> None:
"""Test the stream source has the credentials generated by the Freebox quoted."""
nodes = deepcopy(DATA_HOME_GET_NODES)
for node in nodes:
if node["id"] == 15: # Caméra I from fixture
node["props"]["Stream"] = stream
break
router().home.get_home_nodes.return_value = nodes
await setup_platform(hass, CAMERA_DOMAIN)
assert await async_get_stream_source(hass, "camera.camera_i") == expected_source