Repository: litestar-org/litestar

Issue:
Bug: Cookies with the strings "session" in their name interfere with the session middleware
**Describe the bug**
If a request contains the a cookie with the name containing the string `session`, it will result in invalid session data 

**To Reproduce**

```python
from secrets import token_bytes
from typing import Any

from starlite import Request, Starlite, get, post
from starlite.middleware.session import SessionCookieConfig
from starlite.testing import TestClient

session_config = SessionCookieConfig(secret=token_bytes())

session_data = {"foo": "bar"}


@get("/")
def get_something(request: Request) -> dict[str, Any]:
    return request.session


@post("/")
def set_session_data(request: Request) -> None:
    request.set_session(session_data)


app = Starlite(
    route_handlers=[get_something, set_session_data],
    middleware=[session_config.middleware],
)

client = TestClient(app)

assert client.post("/session").json() == session_data
assert client.get("/session", cookies={"thisisnotasessioncookie": "foo"}).json() == session_data
```

**Additional context**

This is happening because of [this line](this line: https://github.com/starlite-api/starlite/blob/main/starlite/middleware/session.py#L259).

```python
cookie_keys = sorted(key for key in connection.cookies if self.config.key in key)
```
It is meant to check for multiple session cookies, in case data has to be stored in multiple cookies due to size constraints. In these cases, session cookies are created following the schema `session-<i>`, but this isnt' checked for. The line should be

```python
cookie_keys = sorted(key for key in connection.cookies re.fullmatch(fr"{self.config.key}(?:-\d+)?", key))
```
to only check for cookies following the exact pattern potentially set by the middleware (regex should be compiled on the middleware instance beforehand).


Bug: Cookies with the strings "session" in their name interfere with the session middleware
**Describe the bug**
If a request contains the a cookie with the name containing the string `session`, it will result in invalid session data 

**To Reproduce**

```python
from secrets import token_bytes
from typing import Any

from starlite import Request, Starlite, get, post
from starlite.middleware.session import SessionCookieConfig
from starlite.testing import TestClient

session_config = SessionCookieConfig(secret=token_bytes())

session_data = {"foo": "bar"}


@get("/")
def get_something(request: Request) -> dict[str, Any]:
    return request.session


@post("/")
def set_session_data(request: Request) -> None:
    request.set_session(session_data)


app = Starlite(
    route_handlers=[get_something, set_session_data],
    middleware=[session_config.middleware],
)

client = TestClient(app)

assert client.post("/session").json() == session_data
assert client.get("/session", cookies={"thisisnotasessioncookie": "foo"}).json() == session_data
```

**Additional context**

This is happening because of [this line](this line: https://github.com/starlite-api/starlite/blob/main/starlite/middleware/session.py#L259).

```python
cookie_keys = sorted(key for key in connection.cookies if self.config.key in key)
```
It is meant to check for multiple session cookies, in case data has to be stored in multiple cookies due to size constraints. In these cases, session cookies are created following the schema `session-<i>`, but this isnt' checked for. The line should be

```python
cookie_keys = sorted(key for key in connection.cookies re.fullmatch(fr"{self.config.key}(?:-\d+)?", key))
```
to only check for cookies following the exact pattern potentially set by the middleware (regex should be compiled on the middleware instance beforehand).




Discussion:

Resolving patch:
diff --git a/starlite/middleware/session.py b/starlite/middleware/session.py
--- a/starlite/middleware/session.py
+++ b/starlite/middleware/session.py
@@ -1,5 +1,6 @@
 import binascii
 import contextlib
+import re
 import time
 from base64 import b64decode, b64encode
 from os import urandom
@@ -138,6 +139,7 @@ def __init__(
         self.app = app
         self.config = config
         self.aesgcm = AESGCM(config.secret.get_secret_value())
+        self.cookie_re = re.compile(rf"{self.config.key}(?:-\d+)?")
 
     def dump_data(self, data: Any, scope: Optional["Scope"] = None) -> List[bytes]:
         """Given orjson serializable data, including pydantic models and numpy
@@ -256,7 +258,7 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
         if scope["type"] in self.config.scopes:
             scope.setdefault("session", {})
             connection = ASGIConnection[Any, Any, Any](scope)
-            cookie_keys = sorted(key for key in connection.cookies if self.config.key in key)
+            cookie_keys = sorted(key for key in connection.cookies if self.cookie_re.fullmatch(key))
             if cookie_keys:
                 data = [connection.cookies[key].encode("utf-8") for key in cookie_keys]
                 # If these exceptions occur, the session must remain empty so do nothing.


Test patch:
diff --git a/tests/middleware/test_session_middleware.py b/tests/middleware/test_session_middleware.py
--- a/tests/middleware/test_session_middleware.py
+++ b/tests/middleware/test_session_middleware.py
@@ -99,6 +99,27 @@ def handler(request: Request) -> None:
     assert "session-0" in response.cookies
 
 
+def test_session_cookie_name_matching(session_middleware: SessionMiddleware) -> None:
+    session_data = {"foo": "bar"}
+
+    @get("/")
+    def handler(request: Request) -> Dict[str, Any]:
+        return request.session
+
+    @post("/")
+    def set_session_data(request: Request) -> None:
+        request.set_session(session_data)
+
+    with create_test_client(
+        route_handlers=[handler, set_session_data],
+        middleware=[session_middleware.config.middleware],
+    ) as client:
+        client.post("/")
+        client.cookies[f"thisisnnota{session_middleware.config.key}cookie"] = "foo"
+        response = client.get("/")
+        assert response.json() == session_data
+
+
 @pytest.mark.parametrize("mutate", [False, True])
 def test_load_session_cookies_and_expire_previous(mutate: bool, session_middleware: SessionMiddleware) -> None:
     """Should load session cookies into session from request and overwrite the