diff --git a/homeassistant/components/http/security_filter.py b/homeassistant/components/http/security_filter.py index 32ebcacfff4..eab0a2b0764 100644 --- a/homeassistant/components/http/security_filter.py +++ b/homeassistant/components/http/security_filter.py @@ -40,12 +40,19 @@ def setup_security_filter(app): @middleware async def security_filter_middleware(request, handler): """Process request and block commonly known exploit attempts.""" - if FILTERS.search(request.raw_path): + if FILTERS.search(request.path): _LOGGER.warning( "Filtered a potential harmful request to: %s", request.raw_path ) raise HTTPBadRequest + if FILTERS.search(request.query_string): + _LOGGER.warning( + "Filtered a request with a potential harmful query string: %s", + request.raw_path, + ) + raise HTTPBadRequest + return await handler(request) app.middlewares.append(security_filter_middleware) diff --git a/tests/components/http/test_security_filter.py b/tests/components/http/test_security_filter.py index 8190c514603..91fde9c6c54 100644 --- a/tests/components/http/test_security_filter.py +++ b/tests/components/http/test_security_filter.py @@ -35,17 +35,26 @@ async def test_ok_requests(request_path, request_params, aiohttp_client): @pytest.mark.parametrize( - "request_path,request_params", + "request_path,request_params,fail_on_query_string", [ - ("/proc/self/environ", {}), - ("/", {"test": "/test/../../api"}), - ("/", {"test": "test/../../api"}), - ("/", {"sql": ";UNION SELECT (a, b"}), - ("/", {"sql": "concat(..."}), - ("/", {"xss": "