Skip to content

Commit bd7de91

Browse files
ericapisaniclaude
andcommitted
fix(wsgi): Gate url.full, url.path, and http.query behind send_default_pii
The url.full, url.path, and http.query span attributes can contain user-provided query parameters and paths that may include PII. Gate these behind the send_default_pii setting, consistent with how client.address is handled. Fixes PY-2552 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e7262e9 commit bd7de91

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

sentry_sdk/integrations/wsgi.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,6 @@ def _get_request_attributes(
394394
for header, value in headers.items():
395395
attributes[f"http.request.header.{header.lower()}"] = value
396396

397-
query_string = environ.get("QUERY_STRING")
398-
if query_string:
399-
attributes["http.query"] = query_string
400-
401-
attributes["url.full"] = get_request_url(environ, use_x_forwarded_for)
402-
403397
url_scheme = environ.get("wsgi.url_scheme")
404398
if url_scheme:
405399
attributes["network.protocol.name"] = url_scheme
@@ -420,4 +414,14 @@ def _get_request_attributes(
420414
if client_ip:
421415
attributes["client.address"] = client_ip
422416

417+
query_string = environ.get("QUERY_STRING")
418+
if query_string:
419+
attributes["http.query"] = query_string
420+
421+
path = environ.get("PATH_INFO", "")
422+
if path:
423+
attributes["url.path"] = path
424+
425+
attributes["url.full"] = get_request_url(environ, use_x_forwarded_for)
426+
423427
return attributes

tests/integrations/wsgi/test_wsgi.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,22 @@ def dogpark(environ, start_response):
208208
assert envelope["request"] == error_event["request"]
209209

210210

211+
@pytest.mark.parametrize("send_pii", [True, False])
211212
@pytest.mark.parametrize("span_streaming", [True, False])
212213
def test_transaction_no_error(
213214
sentry_init,
214215
capture_events,
215216
capture_items,
216217
DictionaryContaining, # noqa:N803
217218
span_streaming,
219+
send_pii,
218220
):
219221
def dogpark(environ, start_response):
220222
start_response("200 OK", [])
221223
return ["Go get the ball! Good dog!"]
222224

223225
sentry_init(
224-
send_default_pii=True,
226+
send_default_pii=send_pii,
225227
traces_sample_rate=1.0,
226228
_experiments={
227229
"trace_lifecycle": "stream" if span_streaming else "static",
@@ -235,7 +237,7 @@ def dogpark(environ, start_response):
235237
else:
236238
events = capture_events()
237239

238-
client.get("/dogs/are/great/")
240+
client.get("/dogs/are/great?toy=tennisball")
239241

240242
sentry_sdk.flush()
241243

@@ -248,17 +250,30 @@ def dogpark(environ, start_response):
248250
assert span["attributes"]["sentry.op"] == "http.server"
249251
assert span["attributes"]["sentry.span.source"] == "route"
250252
assert span["attributes"]["http.request.method"] == "GET"
251-
assert span["attributes"]["url.full"] == "http://localhost/dogs/are/great/"
252253
assert span["attributes"]["http.response.status_code"] == 200
253254
assert span["status"] == "ok"
255+
256+
if send_pii:
257+
assert span["attributes"]["url.full"] == "http://localhost/dogs/are/great"
258+
assert span["attributes"]["url.path"] == "/dogs/are/great"
259+
assert span["attributes"]["http.query"] == "toy=tennisball"
260+
else:
261+
assert "url.path" not in span["attributes"]
262+
assert "url.full" not in span["attributes"]
263+
assert "http.query" not in span["attributes"]
264+
254265
else:
255266
envelope = events[0]
256267

257268
assert envelope["type"] == "transaction"
258269
assert envelope["transaction"] == "generic WSGI request"
259270
assert envelope["contexts"]["trace"]["op"] == "http.server"
260271
assert envelope["request"] == DictionaryContaining(
261-
{"method": "GET", "url": "http://localhost/dogs/are/great/"}
272+
{
273+
"method": "GET",
274+
"url": "http://localhost/dogs/are/great",
275+
"query_string": "toy=tennisball",
276+
}
262277
)
263278

264279

0 commit comments

Comments
 (0)