fix(gitlab): URL-encode project IDs for issue creation and lookup#114287
fix(gitlab): URL-encode project IDs for issue creation and lookup#114287sentry[bot] wants to merge 1 commit intomasterfrom
Conversation
|
The original error came from this ticket. In this case, Sentry is using the following format for API requests: Which is incorrect per GitLab api. The following formats are correct (URL encoded or projectID): |
Backend Test FailuresFailures on
|
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.
Reviewed by Cursor Bugbot for commit 7896b73. Configure here.
| return self.get(GitLabApiClientPath.project.format(project=project_id)) | ||
| return self.get( | ||
| GitLabApiClientPath.project.format(project=quote(str(project_id), safe="")) | ||
| ) |
There was a problem hiding this comment.
Missing URL encoding in get_issue breaks defense-in-depth
Medium Severity
The defense-in-depth quote() encoding was added to get_project and create_issue but not to get_issue, which has the same vulnerability. In issues.py, the get_issue flow calls client.get_issue(project_id, issue_num) followed by client.get_project(project_id) inside the same try block. When project_id is a path-based identifier (from a stored external issue key containing path_with_namespace), get_issue will still 404 because its project_id isn't URL-encoded, and the now-fixed get_project call on the next line is never reached due to the exception.
Reviewed by Cursor Bugbot for commit 7896b73. Configure here.


GitLab issue creation failed with a 404 Not Found error when a project was selected via the autocomplete search. The root cause was that the
handle_search_repositoriesendpoint insrc/sentry/integrations/gitlab/search.pywas returning theproject["path_with_namespace"](e.g.,group/subgroup/project) as the project identifier value. This path, containing unencoded slashes, was then used directly in the GitLab API request URL byGitLabApiClient.create_issueandGitLabApiClient.get_projectwithout proper URL-encoding, leading to a malformed request and a 404 from GitLab.This fix addresses the issue in two ways:
handle_search_repositoriesinsrc/sentry/integrations/gitlab/search.pyto returnstr(project["id"])as thevaluefor project choices. This ensures that the autocomplete consistently provides numeric project IDs, aligning with the expected format for GitLab API calls and preventing path-based identifiers from being submitted.from urllib.parse import quoteand appliedquote(str(project), safe="")to theprojectargument inGitLabApiClient.create_issueandGitLabApiClient.get_projectinsrc/sentry/integrations/gitlab/client.py. This ensures that even if a path-based project ID (e.g., from a stale saved default inproject_issue_defaults) is passed, it will be correctly URL-encoded before being sent to the GitLab API. This mirrors existing safe practices in other GitLab client methods likesearch_project_issues.This resolves the 404 for users who previously had path-based project IDs stored as defaults or who selected projects via the autocomplete search.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Fixes SENTRY-5P1P