The origins allowed besides the server's own; any allows all.
Attributes#
| Attribute | Type | Description |
|---|---|---|
origins | frozenset[Origin] = frozenset() | |
any | bool = False |
Functions#
__init__#
__init__(origins=frozenset(), any=False) -> None| Parameter | Type | Description |
|---|---|---|
origins | frozenset[Origin] = frozenset() | |
any | bool = False |
allows#
allows(sent, authority, scheme=None) -> boolWhether a request with Origin: sent to authority (its
host[:port]) may go on: no Origin, the server's own, a
listed one, or any. Over a secure scheme (https, wss)
a plain http origin of the same host is not the server's own, as
browsers see it; an https origin on a plain request is (a proxy
may have ended TLS).
| Parameter | Type | Description |
|---|---|---|
sent | str | None | |
authority | Authority | None | |
scheme | str | None = None |
Returns bool
def allows(
self, sent: str | None, authority: Authority | None, scheme: str | None = None
) -> bool:
"""Whether a request with ``Origin: sent`` to ``authority`` (its
``host[:port]``) may go on: no ``Origin``, the server's own, a
listed one, or ``any``. Over a secure ``scheme`` (``https``, ``wss``)
a plain ``http`` origin of the same host is not the server's own, as
browsers see it; an ``https`` origin on a plain request is (a proxy
may have ended TLS)."""
if sent is None or self.any:
return True
origin = parse_origin(sent.strip())
if origin is None:
return False
if origin in self.origins:
return True
if authority is None or origin == "null":
return False
sent_scheme, _, own = origin.partition("://")
if scheme in _SECURE and sent_scheme not in _SECURE:
return False
return own == _host_port(sent_scheme, authority)