Conversation
Add a new API endpoint that allows looking up project DSNs by their public key portion. This powers the command palette DSN lookup feature behind the organizations:cmd-k-dsn-lookup feature flag.
Add DSN lookup functionality to both the new supercharged command palette and the legacy search modal. Users can paste a DSN and get quick navigation to the corresponding project. Depends on backend PR #108400.
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
The endpoint was missing the organizations:cmd-k-dsn-lookup feature flag check, making it accessible to any authenticated user regardless of whether the feature was enabled for their org. Also removes a broken unauthenticated test (silo mode issue with client.logout in region silo) and adds a test for the flag-disabled case.
Fixes mypy union-attr errors where ProjectKey | None was accessed without narrowing.
JoshFerge
left a comment
There was a problem hiding this comment.
I believe this introduces a security vulnerability as is as we're not checking that the user has access to the project key. can we:
-
use
ProjectEndpointorOrganizationEndpoint, which makes sure the user making request has access to the org/project? -
in the
ProjectKeylookup, make sure we're addingprojectto the ORM query so we prevent IDOR attacks?
mind adding a bit of description to the PR / endpoint docstring? from reading this i'm not quite sure what the intended use of the endpoint is (a user gives a dsn and it gets back info about it?)
|
|
||
| try: | ||
| parsed = urlparse(dsn) | ||
| except Exception: |
There was a problem hiding this comment.
blanket exception handling is not ideal. how exactly can urlparse error? I assume it returns an error more specific than Exception.
There was a problem hiding this comment.
Good call — removed the try/except entirely. urlparse is extremely permissive and basically never raises; request.GET.get() always returns str | None and we already guard None/empty above. Invalid DSNs (like "not-a-dsn") just produce a parsed result with no username, which the if not public_key check handles.
JoshFerge
left a comment
There was a problem hiding this comment.
and if this is intended to be a user scoped endpoint, can we use UserEndpoint?
sentry/src/sentry/users/api/bases/user.py
Line 102 in 88684c1
Address security review feedback:
- Switch from bare Endpoint to OrganizationEndpoint so auth and org
access are handled by the base class
- Scope ProjectKey query with project__organization_id to prevent IDOR
- Move URL from /api/0/dsn-lookup/ to
/api/0/organizations/{org}/dsn-lookup/
- Add endpoint docstring explaining the use case
- Remove manual OrganizationMember check (now handled by base class)
urlparse only raises for non-string input, but request.GET.get() always returns str | None and we already guard against None/empty. Invalid DSNs are handled by the subsequent `if not public_key` check.
|
Re: Latest push removes the blanket |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Only resolve DSNs for active projects, active keys, and user-facing keys. Prevents returning metadata for deleted projects, inactive keys, or internal keys (e.g. profiling, escalating_issues).
Summary
Adds a private API endpoint that resolves a Sentry DSN to its associated project and key metadata. This powers the command palette (Cmd+K) — users can paste a DSN and quickly navigate to the corresponding project.
Endpoint:
GET /api/0/organizations/{org}/dsn-lookup/?dsn=<dsn>Behavior:
ProjectKeyscoped to the requesting organizationAccess control:
OrganizationEndpointbase class enforces org membershipProjectKeyquery is scoped byproject__organization_idto prevent IDORorganizations:cmd-k-dsn-lookupfeature flagContext
Split from #108396 — this is the backend half. The frontend PR (command palette integration) will follow and reference this PR as a dependency.
Test plan
pytest tests/sentry/api/endpoints/test_dsn_lookup.py)