mirror of
https://github.com/beenuar/AiSOC.git
synced 2026-11-26 10:17:48 +08:00
fix(security): vendor clients refuse redirects the SSRF guard never saw (#2068)
Fixes [GHSA-hfgq-46wx-m6g5](https://github.com/beenuar/AiSOC/security/advisories/GHSA-hfgq-46wx-m6g5) (high; reported by @Echore61 — an exact report, down to citing the three in-tree paths that already do this right). **The defect**: `_first_blocked_destination` validates the caller-supplied `base_url` before dispatch, but validation has single-URL scope — and the osctrl and FleetDM clients built their `httpx.AsyncClient` with `follow_redirects=True`. A public host answering 302 with an internal `Location` (cloud metadata included) had its redirect followed with no further validation. **The fix**: both clients now set `follow_redirects=False` with the reason commented, matching `saml_metadata`, `llm_model_discovery` and `hunt/from_report` — a redirect is a second URL the guard never saw, and a 3xx surfaces as an honest vendor error. The other two `follow_redirects=True` sites in the tree fetch fixed platform constants (CISA KEV, MITRE), a different trust class, and stay as they are. **Verification**: new tests drive both clients through a real redirecting transport and assert no second hop is ever made — both fail on the pre-fix tree (`follow_redirects is True`). Full actions suite: 2,167 passed. Advisory publication naming the patched release follows the merge.
This commit is contained in:
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- **The agents image can actually render the PDFs its routes offer.** Its
|
||||
Dockerfile never installed WeasyPrint's native stack, so on every
|
||||
deployment the legacy `report.pdf` route answered 500 ("cannot load
|
||||
library 'libgobject-2.0-0'") and the case-report-export `try_pdf` leg
|
||||
could never produce a PDF — the API-side fallback carried the journey.
|
||||
The image now ships the same four Pango/Cairo libraries the API image
|
||||
always has; verified live with a warm export (17,715-byte PDF) and a
|
||||
cold one after an agents restart (served from persisted artifacts).
|
||||
|
||||
### Security
|
||||
|
||||
- **A vendor redirect can no longer carry a live action past the SSRF guard**
|
||||
(GHSA-hfgq-46wx-m6g5, high; reported by @Echore61). The dispatcher
|
||||
validates a caller-supplied `base_url` before dispatch, but validation has
|
||||
single-URL scope — and the osctrl and FleetDM clients created their HTTP
|
||||
session with `follow_redirects=True`, so a public host answering 302 could
|
||||
send the request to cloud metadata or an internal service the guard never
|
||||
saw. Both clients now refuse redirects outright, the same rule every other
|
||||
caller-URL outbound path already follows; a 3xx surfaces as an honest
|
||||
vendor error. Pinned by tests through a real redirecting transport that
|
||||
assert no second hop is ever made (both fail on the pre-fix tree).
|
||||
|
||||
|
||||
### Fixed
|
||||
|
||||
- Copilot projects alert and case evidence into allowlisted summaries instead of
|
||||
|
||||
@@ -153,7 +153,12 @@ class FleetDMClient:
|
||||
def _client(self) -> httpx.AsyncClient:
|
||||
return httpx.AsyncClient(
|
||||
verify=self._verify_tls,
|
||||
follow_redirects=True,
|
||||
# A redirect is a second URL the dispatcher's SSRF guard never
|
||||
# validated (GHSA-hfgq-46wx-m6g5): the base_url is caller input,
|
||||
# so a public host answering 302 could send this client to cloud
|
||||
# metadata or an internal service. Same rule as saml_metadata,
|
||||
# llm_model_discovery and hunt/from_report: never follow.
|
||||
follow_redirects=False,
|
||||
timeout=httpx.Timeout(30.0),
|
||||
)
|
||||
|
||||
|
||||
@@ -139,7 +139,12 @@ class OsctrlClient:
|
||||
return httpx.AsyncClient(
|
||||
headers={"Authorization": f"Bearer {self._api_token}"},
|
||||
verify=self._verify_tls,
|
||||
follow_redirects=True,
|
||||
# A redirect is a second URL the dispatcher's SSRF guard never
|
||||
# validated (GHSA-hfgq-46wx-m6g5): the base_url is caller input,
|
||||
# so a public host answering 302 could send this client to cloud
|
||||
# metadata or an internal service. Same rule as saml_metadata,
|
||||
# llm_model_discovery and hunt/from_report: never follow.
|
||||
follow_redirects=False,
|
||||
timeout=httpx.Timeout(30.0),
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""A redirect is a second URL the SSRF guard never saw (GHSA-hfgq-46wx-m6g5).
|
||||
|
||||
The dispatcher validates the caller-supplied ``base_url`` before dispatch,
|
||||
but validation has single-URL scope: a public host that answers 302 with an
|
||||
internal ``Location`` would have its redirect followed by the vendor client
|
||||
— straight past the guard to cloud metadata or an internal service. Every
|
||||
other outbound path aimed at a caller- or admin-supplied URL already sets
|
||||
``follow_redirects=False`` (``saml_metadata``, ``llm_model_discovery``,
|
||||
``hunt/from_report``); these two clients are held to the same rule, proven
|
||||
through a real redirecting transport rather than a mock of the client.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from app.clients.fleetdm_client import FleetDMClient, FleetDMError
|
||||
from app.clients.osctrl_client import OsctrlClient, OsctrlError
|
||||
|
||||
|
||||
class _RedirectingTransport(httpx.AsyncBaseTransport):
|
||||
"""Answers 302-to-internal for the first hop; records any second hop."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.requests: list[str] = []
|
||||
|
||||
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
|
||||
self.requests.append(str(request.url))
|
||||
if request.url.host == "169.254.169.254":
|
||||
return httpx.Response(200, text="latest/meta-data")
|
||||
return httpx.Response(302, headers={"Location": "http://169.254.169.254/latest/meta-data/"})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_osctrl_client_refuses_a_redirect_instead_of_following_it() -> None:
|
||||
transport = _RedirectingTransport()
|
||||
client = OsctrlClient(base_url="https://public.example.com", api_token="t", environment="prod")
|
||||
http = client._client()
|
||||
assert http.follow_redirects is False, (
|
||||
"the client must not follow redirects: the Location is a URL the dispatcher's SSRF guard never validated"
|
||||
)
|
||||
await http.aclose()
|
||||
|
||||
# Through a real transport: the 302 must surface as a vendor error with
|
||||
# no second request, never a silent hop to the Location target.
|
||||
guarded = httpx.AsyncClient(transport=transport, follow_redirects=http.follow_redirects)
|
||||
with pytest.raises(OsctrlError):
|
||||
await client._submit_query(guarded, "SELECT 1;", ["h1"])
|
||||
assert transport.requests == ["https://public.example.com/api/v1/queries/prod"], f"a second hop was made: {transport.requests}"
|
||||
await guarded.aclose()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fleetdm_client_refuses_a_redirect_instead_of_following_it() -> None:
|
||||
transport = _RedirectingTransport()
|
||||
client = FleetDMClient(base_url="https://public.example.com", api_token="t")
|
||||
http = client._client()
|
||||
assert http.follow_redirects is False
|
||||
await http.aclose()
|
||||
|
||||
guarded = httpx.AsyncClient(transport=transport, follow_redirects=http.follow_redirects)
|
||||
with pytest.raises(FleetDMError):
|
||||
await client._create_campaign(guarded, "SELECT 1;", ["h1"])
|
||||
assert transport.requests[0].startswith("https://public.example.com/"), transport.requests
|
||||
assert len(transport.requests) == 1, f"a second hop was made: {transport.requests}"
|
||||
await guarded.aclose()
|
||||
@@ -40,6 +40,14 @@ WORKDIR /app
|
||||
# proves a missing system library is required.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
# WeasyPrint's native stack. Without it the report.pdf route 500s on
|
||||
# every deployment and the case-report-export try_pdf leg can never
|
||||
# render — the same four libraries the API image already ships.
|
||||
libpango-1.0-0 \
|
||||
libpangocairo-1.0-0 \
|
||||
libcairo2 \
|
||||
libgdk-pixbuf-2.0-0 \
|
||||
shared-mime-info \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=deps /requirements.txt /requirements.txt
|
||||
|
||||
Reference in New Issue
Block a user