Skip to content

fix(data-export): Refuse exports from callers with no user - #129637

Open
gricha wants to merge 1 commit into
ref/sa-oneoffsfrom
fix/data-export-requires-user
Open

gricha wants to merge 1 commit into
ref/sa-oneoffsfrom
fix/data-export-requires-user

Conversation

@gricha

@gricha gricha commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Data export POSTs from a caller with no user (a legacy API key or an org auth token) created an export nobody could get, then returned 500.

An export is emailed to and downloaded by its user. For a caller with no user the endpoint still ran get_or_create(user_id=None, ...), scheduled the export task, and then crashed serializing the response, because the serializer looks the user up. Each attempt left an export that no one could download (the details endpoint needs a user since #129442). The user_id=None lookup also matched other no-user callers' unfinished exports with the same query.

require_user() now refuses these callers before anything is created: 401 for API keys, 403 user-required for a service account. (Org auth tokens only carry org:ci, so the permission check already returned 403.) Users are unaffected. Production had no export POST without a user in the last 30 days (0 of 3,968 sampled transactions), so no working integration relies on this.

test_api_key_cannot_export fails without the fix:

E   AssertionError: b'{"detail":"Internal Error","errorId":null}'
E   assert 500 == 401
FAILED tests/sentry/data_export/endpoints/test_data_export.py::DataExportTest::test_api_key_cannot_export

With it, test_data_export.py passes: 49 passed. Also drops data_export.py from the request.user allowlist (6 → 5).

@gricha
gricha requested review from a team as code owners November 3, 2026 01:49
@gricha
gricha added this pull request to stack #129572 November 3, 2026 01:49
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 3, 2026
@gricha
gricha force-pushed the fix/data-export-requires-user branch from 250b3ae to 3bfabab Compare November 3, 2026 04:03
An export is emailed to and downloaded by its user. For an API key or org
token, the endpoint created the export and scheduled its task, then
returned 500 because the response serializer looks the user up. Each
attempt left an export nobody could fetch, and the get_or_create on
user_id=None matched other no-user callers' unfinished exports.

require_user() refuses these callers up front (401; 403 for a service
account), and data_export.py leaves the request.user allowlist.
@gricha
gricha requested review from cvxluo and skaasten November 3, 2026 04:39
@gricha
gricha force-pushed the fix/data-export-requires-user branch from 3bfabab to 8dccd62 Compare November 3, 2026 04:41
@gricha
gricha removed this pull request from stack #129572 November 3, 2026 06:52
@gricha
gricha added this pull request to stack #129650 November 3, 2026 06:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant