Repository navigation
How to get site (TCPSite or UnixSite) inside route handler #5924
Replies: 1 comment
|
For one
import socket
from aiohttp import web
async def control(request: web.Request) -> web.Response:
sock = request.get_extra_info('socket')
if sock is None or sock.family != socket.AF_UNIX:
raise web.HTTPForbidden(text='Unix-socket connections only')
# Perform the permitted control operation here.
return web.json_response({'ok': True})A connection accepted by Since these are control requests, also account for the deployment boundary: a reverse proxy forwarding public traffic to your Unix socket will pass this check. Restrict that routing and the socket's filesystem permissions as appropriate; the socket family alone does not authenticate the originating user. References: |
Uh oh!
There was an error while loading. Please reload this page.
Hello everybody,
if I run one application, one runner, and set up two sites: on UnixSite and another TCPSite, how can I distinguish from which site the request is coming, from within request handler code?
Case is to allow specific (control) requests only coming from UnixSite. (Unix socket, obviously)
Thank you!!
All reactions