Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7541460
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
5e9f610
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 9, 2026
a590c8e
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
16ed0c8
fix test
ericapisani Jul 9, 2026
486f0bc
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
7d14a81
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
bb98334
add aws lambda test coverage
ericapisani Jul 9, 2026
61d1618
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
951c408
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
a19be39
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
620e222
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
ec6f520
update tornado test
ericapisani Jul 10, 2026
4dd3ba6
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
d0bae90
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
a6c4688
fix test
ericapisani Jul 9, 2026
d7b378b
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
52c2da1
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
aa645d7
add aws lambda test coverage
ericapisani Jul 9, 2026
8b6e3ad
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
d717172
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
c7f590f
Merge branch 'py-2584-update-wsgi-filter-headers' of github.com:getse…
ericapisani Jul 14, 2026
293a291
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
530e83c
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
326d796
update tornado test
ericapisani Jul 10, 2026
e9f0e20
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 15, 2026
48f7c7b
Merge branch 'py-2581-cookies' of github.com:getsentry/sentry-python …
ericapisani Jul 15, 2026
621d79b
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
3d7bddb
test(aiohttp): Expect single span in streaming passthrough test
ericapisani Jul 15, 2026
fad2292
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
40d9f38
feat(wsgi): Apply data_collection filtering to URL query strings
ericapisani Jul 15, 2026
e6e7148
Merge branch 'py-2581-cookies' into py-2583-query-parameters
ericapisani Jul 15, 2026
1f9bce7
lint
ericapisani Jul 15, 2026
fad0c9a
Do not encode what is added to event/span attributes in order to conf…
ericapisani Jul 16, 2026
21cf40b
feat(asgi): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
3f0bc2a
lint
ericapisani Jul 16, 2026
eee4ea2
feat(aiohttp): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
407ad17
Merge branch 'master' into py-2583-query-params-aiohttp
ericapisani Jul 22, 2026
b6b6e1e
address CR comments within aiohttp
ericapisani Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import sentry_sdk
from sentry_sdk.api import continue_trace
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy client span leaks unfiltered query strings when data_collection is configured

The legacy (non-streaming) client span path stores the raw query string without applying _apply_data_collection_filtering_to_query_string, so sensitive parameters bypass the user-configured data_collection filters.

Evidence
  • _apply_data_collection_filtering_to_query_string is imported at line 7 for use in the streaming span path.
  • In the streaming client path (on_request_start, ~line 400), parsed_url.query is filtered before being stored in attributes["url.query"].
  • In the legacy client else branch at line 428, legacy_span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query) stores the raw, unfiltered query string regardless of data_collection settings.
  • The new tests added in test_aiohttp.py (test_client_url_query_data_collection_span_streaming) only exercise the streaming path with trace_lifecycle="stream", leaving the legacy path uncovered.

Identified by Warden find-bugs · EJW-8M7

from sentry_sdk.data_collection import (
_apply_data_collection_filtering_to_query_string,
)
from sentry_sdk.integrations import (
_DEFAULT_FAILED_REQUEST_STATUS_CODES,
DidNotEnable,
Expand Down Expand Up @@ -46,6 +49,7 @@
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
logger,
parse_url,
parse_version,
Expand Down Expand Up @@ -161,7 +165,26 @@ async def sentry_app_handle(
)

url_attributes = {}
if should_send_default_pii():
if has_data_collection_enabled(client.options):
url_attributes["url.full"] = "%s://%s%s" % (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just copied from the should_send_default_pii branch, but I've just realized it's wrong: url.full should contain the query and it doesn't.

Probably makes more sense to fix this afterwards, when this stack has been merged. I'll make an issue for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🙏🏻

request.scheme,
request.host,
request.path,
)
url_attributes["url.path"] = request.path

if request.query_string:
filtered_query_string = (
_apply_data_collection_filtering_to_query_string(
query_string=request.query_string,
behaviour=client.options["data_collection"][
"url_query_params"
],
)
)
if filtered_query_string:
url_attributes["url.query"] = filtered_query_string
elif should_send_default_pii():
url_attributes["url.full"] = "%s://%s%s" % (
request.scheme,
request.host,
Expand Down Expand Up @@ -362,14 +385,33 @@ async def on_request_start(
"sentry.origin": AioHttpIntegration.origin,
"http.request.method": method,
}
if parsed_url is not None and should_send_default_pii():
attributes["url.full"] = parsed_url.url
attributes["url.path"] = params.url.path

if parsed_url.query:
attributes["url.query"] = parsed_url.query
if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment
if parsed_url is not None:
if has_data_collection_enabled(client.options):
attributes["url.full"] = parsed_url.url
attributes["url.path"] = params.url.path

if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment

if parsed_url.query:
filtered_query = (
_apply_data_collection_filtering_to_query_string(
query_string=parsed_url.query,
behaviour=client.options["data_collection"][
"url_query_params"
],
)
)
if filtered_query:
attributes["url.query"] = filtered_query
elif should_send_default_pii():
attributes["url.full"] = parsed_url.url
attributes["url.path"] = params.url.path

if parsed_url.query:
attributes["url.query"] = parsed_url.query
if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment

span = sentry_sdk.traces.start_span(
name=span_name, attributes=attributes
Expand Down
162 changes: 162 additions & 0 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,3 +1795,165 @@ async def hello(request):
else:
assert "user.ip_address" not in server_span["attributes"]
assert "user.ip_address" not in child_span["attributes"]


NO_QUERY_STRING = object()
_QUERY_PARAM_DATA_COLLECTION_CASES = [
pytest.param(
{"send_default_pii": True},
"toy=tennisball&color=red&auth=secret",
id="send_default_pii_true",
),
pytest.param(
{"send_default_pii": False},
NO_QUERY_STRING,
id="send_default_pii_false",
),
pytest.param(
{},
NO_QUERY_STRING,
id="defaults",
),
pytest.param(
{"_experiments": {"data_collection": {}}},
"toy=tennisball&color=red&auth=[Filtered]",
id="data_collection_denylist_default",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "denylist", "terms": ["toy"]}
}
}
},
"toy=[Filtered]&color=red&auth=[Filtered]",
id="data_collection_denylist_custom_terms",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "allowlist", "terms": ["toy"]}
}
}
},
"toy=tennisball&color=[Filtered]&auth=[Filtered]",
id="data_collection_allowlist",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "allowlist", "terms": ["auth"]}
}
}
},
"toy=[Filtered]&color=[Filtered]&auth=[Filtered]",
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
id="data_collection_allowlist_sensitive_term",
),
pytest.param(
{"_experiments": {"data_collection": {"url_query_params": {"mode": "off"}}}},
NO_QUERY_STRING,
id="data_collection_off",
),
pytest.param(
{
"send_default_pii": True,
"_experiments": {"data_collection": {"url_query_params": {"mode": "off"}}},
},
NO_QUERY_STRING,
id="data_collection_wins_over_send_default_pii",
),
]


@pytest.mark.asyncio
@pytest.mark.parametrize(
"init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
)
async def test_server_url_query_data_collection_span_streaming(
sentry_init, aiohttp_client, capture_items, init_kwargs, expected_query
):
init_kwargs = dict(init_kwargs)
sentry_init(
integrations=[AioHttpIntegration()],
traces_sample_rate=1.0,
_experiments={
"trace_lifecycle": "stream",
**init_kwargs.pop("_experiments", {}),
},
**init_kwargs,
)

async def hello(request):
return web.Response(text="hello")

app = web.Application()
app.router.add_get("/", hello)

items = capture_items("span")

client = await aiohttp_client(app)
resp = await client.get("/?toy=tennisball&color=red&auth=secret")
assert resp.status == 200

sentry_sdk.flush()

(server_span,) = [item.payload for item in items]

if expected_query is NO_QUERY_STRING:
assert "url.query" not in server_span["attributes"]
else:
assert server_span["attributes"]["url.query"] == expected_query


@pytest.mark.asyncio
@pytest.mark.parametrize(
"init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
)
async def test_client_url_query_data_collection_span_streaming(
sentry_init,
aiohttp_raw_server,
aiohttp_client,
capture_items,
init_kwargs,
expected_query,
):
init_kwargs = dict(init_kwargs)
sentry_init(
integrations=[AioHttpIntegration()],
traces_sample_rate=1.0,
_experiments={
"trace_lifecycle": "stream",
**init_kwargs.pop("_experiments", {}),
},
**init_kwargs,
)

async def handler(request):
return web.Response(text="OK")

raw_server = await aiohttp_raw_server(handler)

async def hello(request):
span_client = await aiohttp_client(raw_server)
await span_client.get("/?toy=tennisball&color=red&auth=secret")
return web.Response(text="hello")

app = web.Application()
app.router.add_get(r"/", hello)

items = capture_items("span")

client = await aiohttp_client(app)
await client.get("/")

sentry_sdk.flush()

inner_client_span = items[0].payload

if expected_query is NO_QUERY_STRING:
assert "url.query" not in inner_client_span["attributes"]
else:
assert inner_client_span["attributes"]["url.query"] == expected_query
Loading