Spaces:
Running
Running
Download sinetti_api/runtime_security.py from Couscouskabyle/iscc-app: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/spaces/Couscouskabyle/iscc-app/resolve/main/sinetti_api/runtime_security.py
- Command line
-
hf download hf://spaces/Couscouskabyle/iscc-app/sinetti_api/runtime_security.py
-
curl -L -o runtime_security.py https://huggingface.co/spaces/Couscouskabyle/iscc-app/resolve/main/sinetti_api/runtime_security.py
774 Bytes
| """Server-owned hosting and loopback policy; forwarding headers confer no trust.""" | |
| from __future__ import annotations | |
| import ipaddress | |
| import os | |
| from starlette.requests import Request | |
| from sinetti_services.hosting import hosted_runtime | |
| def local_loopback_request(request: Request) -> bool: | |
| if hosted_runtime() or os.environ.get("APP_BACKEND", "").strip().lower() != "local": | |
| return False | |
| peer = request.client.host if request.client else "" | |
| host = request.url.hostname or "" | |
| try: | |
| peer_loopback = ipaddress.ip_address(peer).is_loopback | |
| host_loopback = host.lower() == "localhost" or ipaddress.ip_address(host).is_loopback | |
| except ValueError: | |
| return False | |
| return peer_loopback and host_loopback | |