Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

import voluptuous as vol
from aiohttp import web
from aiohttp.web_exceptions import HTTPUnauthorized, HTTPGone, HTTPNotFound
from aiohttp.web_exceptions import (
HTTPForbidden,
HTTPGone,
HTTPNotFound,
HTTPUnauthorized,
)
from homeassistant.components.binary_sensor import HomeAssistant # fix tests
from homeassistant.components.camera import async_get_stream_source, async_get_image
from homeassistant.components.http import HomeAssistantView
Expand Down Expand Up @@ -247,8 +252,10 @@ async def get(self, request: web.Request):

# fix for https://github.com/AlexxIT/WebRTC/pull/320
elif not utils.validate_signed_request(request):
# you shall not pass
raise HTTPUnauthorized()
# Reject invalid/expired stream signatures with 403, not 401.
# HA's ban middleware treats HTTPUnauthorized as a failed login and
# can IP-ban the client after login_attempts_threshold hits (#955).
raise HTTPForbidden()

hass = request.app["hass"]

Expand Down Expand Up @@ -299,7 +306,8 @@ class HLSView(HomeAssistantView):

async def get(self, request: web.Request, filename: str):
if request.cookies.get(HLS_COOKIE) != HLS_SESSION:
raise HTTPUnauthorized()
# Same ban footgun as authSig above — do not raise 401 (#955).
raise HTTPForbidden()

if filename not in ("playlist.m3u8", "init.mp4", "segment.m4s", "segment.ts"):
raise HTTPNotFound()
Expand Down