File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
resotolib/resotolib/asynchronous/web Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 3
3
from contextvars import ContextVar
4
4
from re import RegexFlag
5
5
from typing import Any , Dict , Optional , Set
6
+ from urllib .parse import urlparse
6
7
7
8
from aiohttp import web
8
9
from aiohttp .web import Request , StreamResponse
@@ -38,10 +39,18 @@ def always_allowed(request: Request) -> bool:
38
39
39
40
@middleware
40
41
async def valid_jwt_handler (request : Request , handler : RequestHandler ) -> StreamResponse :
41
- auth_header = request .headers .get ("authorization " ) or request .cookies .get ("resoto_authorization" )
42
+ auth_header = request .headers .get ("Authorization " ) or request .cookies .get ("resoto_authorization" )
42
43
if always_allowed (request ):
43
44
return await handler (request )
44
45
elif auth_header :
46
+ origin : Optional [str ] = urlparse (request .headers .get ("Origin" )).hostname
47
+ host : Optional [str ] = request .headers .get ("Host" )
48
+ if host is not None and origin is not None :
49
+ if ":" in host :
50
+ host = host .split (":" )[0 ]
51
+ if origin .lower () != host .lower ():
52
+ log .warning (f"Origin { origin } is not allowed in request from { request .remote } to { request .path } " )
53
+ raise web .HTTPForbidden ()
45
54
try :
46
55
# note: the expiration is already checked by this function
47
56
jwt = ck_jwt .decode_jwt_from_header_value (auth_header , psk )
You can’t perform that action at this time.
0 commit comments