"""The app draws itself only from its own origin.
A font, stylesheet or script linked from another host hands that host every
visitor's address on every page load, sign-in page included, and when the host
is slow or blocked the page quietly renders in fallback type with nothing in the
console. Everything the frontend needs ships in the image instead, and the
Content-Security-Policy names no other host, so a remote link that slips back in
is refused by the browser as well as by this check.
"""
from __future__ import annotations
import pathlib
import re
ROOT = pathlib.Path(__file__).resolve().parents[1]
FRONTEND = ROOT / "frontend"
CSS_COMMENT = re.compile(r"/\*.*?\*/", re.S)
HTML_COMMENT = re.compile(r"", re.S)
REMOTE = r"""(?:https?:)?//"""
REMOTE_REFS = [
re.compile(rf"""@import\s+(?:url\(\s*)?['"]?{REMOTE}""", re.I),
re.compile(rf"""url\(\s*['"]?{REMOTE}""", re.I),
re.compile(rf"""]*\bhref\s*=\s*['"]{REMOTE}""", re.I),
re.compile(rf"""')
assert remote_refs('')
assert not remote_refs("/* no @import url('https://x.example.com') here */")
assert not remote_refs("@font-face { src: url(./inter-normal-latin.woff2); }")
assert not remote_refs('docs')