Refuse a fetch to another port than 443, an IP address or a local host name, at every hop
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f61caddced
commit
60136765b2
2 files changed
+71
-2
No files matched your search
@@ -156,6 +156,50 @@ def test_get_sends_extra_headers_on_top_of_its_own() -> None:
|
||||
assert "x-board" not in seen[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("site", [
|
||||
"metadata.google.internal", "printer.local", "router.lan", "nas.home.arpa",
|
||||
"app.localhost", "foo.0x7f000001", "printer.local.",
|
||||
])
|
||||
def test_get_refuses_a_local_name_before_any_request(site: str) -> None:
|
||||
"""A Teamtailor slug may be any host name, so the allow-list admits
|
||||
these; `_get` refuses them before a request is made."""
|
||||
asked: list[str] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
asked.append(str(request.url))
|
||||
return httpx.Response(200, content=b"<rss><channel/></rss>")
|
||||
|
||||
with _client(handler) as client:
|
||||
# A trailing dot is no Teamtailor slug at all; the rest are, and are refused.
|
||||
with pytest.raises(ValueError if site.endswith(".") else ats._Refused):
|
||||
ats._fetch_rows(client, f"teamtailor:{site}")
|
||||
for url in (f"https://{site}/jobs.rss", "https://127.0.0.1/", "https://[::1]/",
|
||||
"https://2130706433/", "https://127.1/", "https://localhost/"):
|
||||
with pytest.raises(ats._Refused):
|
||||
ats._get(client, url, "teamtailor", site)
|
||||
assert asked == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("location", [
|
||||
"https://api.lever.co:8443/x", "https://127.0.0.1/x", "https://[::1]/x",
|
||||
"https://localhost/x",
|
||||
])
|
||||
def test_get_refuses_a_redirect_to_another_port_or_a_local_host(location: str) -> None:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
return httpx.Response(302, headers={"location": location})
|
||||
|
||||
with _client(handler) as client, pytest.raises(ats._Refused):
|
||||
ats._get(client, "https://api.lever.co/v0/postings/acme", "lever", "acme")
|
||||
|
||||
|
||||
def test_get_takes_port_443_written_out_and_refuses_another() -> None:
|
||||
with _client(lambda request: httpx.Response(200, content=b"[]")) as client:
|
||||
assert ats._get(client, "https://api.lever.co:443/v0/postings/acme",
|
||||
"lever", "acme") == b"[]"
|
||||
with pytest.raises(ats._Refused):
|
||||
ats._get(client, "https://api.lever.co:8443/v0/postings/acme", "lever", "acme")
|
||||
|
||||
|
||||
def test_the_bound_get_reaches_a_replaced_ats_get(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Bound before the replacement, and still reaching it: `_get` is looked
|
||||
up when a request is made."""
|
||||
|
||||
Reference in new issue
Block a user