Skip to content

Commit 4296334

Browse files
ericapisaniclaude
andauthored
fix(sanic): Gate url.full, url.path, and http.query behind send_default_pii (#6663)
The `url.full`, `url.path`, and `http.query` span attributes on Sanic request spans are now only set when `send_default_pii=True`. Previously `url.full` was always set, which could leak sensitive path or query parameter values. This matches the same fix already applied to the aiohttp, wsgi, and asgi integrations. Fixes PY-2555 Fixes #6660 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 21486dc commit 4296334

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

sentry_sdk/integrations/sanic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,12 @@ def _get_request_attributes(request: "Request") -> "Dict[str, Any]":
380380

381381
urlparts = urlsplit(request.url)
382382

383-
if urlparts.query:
384-
attributes[SPANDATA.HTTP_QUERY] = urlparts.query
383+
if should_send_default_pii():
384+
attributes[SPANDATA.URL_FULL] = request.url
385+
attributes["url.path"] = urlparts.path
385386

386-
attributes[SPANDATA.URL_FULL] = request.url
387+
if urlparts.query:
388+
attributes[SPANDATA.HTTP_QUERY] = urlparts.query
387389

388390
if urlparts.scheme:
389391
attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = urlparts.scheme

tests/integrations/sanic/test_sanic.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def __init__(
363363
@pytest.mark.skipif(
364364
not PERFORMANCE_SUPPORTED, reason="Performance not supported on this Sanic version"
365365
)
366+
@pytest.mark.parametrize("send_pii", [True, False])
366367
@pytest.mark.parametrize("span_streaming", [True, False])
367368
@pytest.mark.parametrize(
368369
"test_config",
@@ -424,6 +425,7 @@ def test_transactions(
424425
capture_events: "Any",
425426
capture_items: "Any",
426427
span_streaming: bool,
428+
send_pii: bool,
427429
) -> None:
428430
if span_streaming and not test_config.streaming_compatible:
429431
pytest.skip("unsampled_statuses is not supported in span streaming mode")
@@ -432,6 +434,7 @@ def test_transactions(
432434
sentry_init(
433435
integrations=[SanicIntegration(*test_config.integration_args)],
434436
traces_sample_rate=1.0,
437+
send_default_pii=send_pii,
435438
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
436439
)
437440

@@ -469,9 +472,6 @@ def test_transactions(
469472

470473
attrs = segment["attributes"]
471474
assert attrs["http.request.method"] == "GET"
472-
assert attrs["url.full"].endswith(test_config.url)
473-
if "?" in test_config.url:
474-
assert attrs["http.query"] == test_config.url.split("?", 1)[1]
475475
assert attrs["network.protocol.name"] == "http"
476476
header_keys = {
477477
key[len("http.request.header.") :]
@@ -483,6 +483,18 @@ def test_transactions(
483483
assert segment["status"] == (
484484
"error" if test_config.expected_status >= 400 else "ok"
485485
)
486+
487+
if send_pii:
488+
assert attrs["url.full"].endswith(test_config.url)
489+
assert attrs["url.path"] == test_config.url.split("?")[0]
490+
if "?" in test_config.url:
491+
assert attrs["http.query"] == test_config.url.split("?", 1)[1]
492+
493+
else:
494+
assert "url.full" not in attrs
495+
assert "url.path" not in attrs
496+
assert "http.query" not in attrs
497+
486498
else:
487499
# Extract the transaction events by inspecting the event types. We should at most have 1 transaction event.
488500
transaction_events = [

0 commit comments

Comments
 (0)