This commit is contained in:
orbisai0security 2026-05-09 07:03:13 +05:30 committed by GitHub
commit c34fd1b399
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@ from typing import Optional
from folder_paths import folder_names_and_paths, get_directory_by_type
from api_server.services.terminal_service import TerminalService
import app.logger
import ipaddress
import os
class InternalRoutes:
@ -72,7 +73,19 @@ class InternalRoutes:
def get_app(self):
if self._app is None:
self._app = web.Application()
self._app = web.Application(middlewares=[self._local_only_middleware])
self.setup_routes()
self._app.add_routes(self.routes)
return self._app
@web.middleware
async def _local_only_middleware(self, request, handler):
remote = request.remote
if remote is None:
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
try:
if not ipaddress.ip_address(remote).is_loopback:
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
except ValueError:
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
return await handler(request)