Skip to content

Conversation

mdtro
Copy link
Member

@mdtro mdtro commented Feb 20, 2025

Pulled from #82052 to break out these changes into smaller PRs.

Use locks to ensure an ApiGrant cannot be used twice during a race condition that would result in multiple access/refresh token pairs.

@mdtro mdtro requested review from a team as code owners February 20, 2025 19:22
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 20, 2025
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/models/apitoken.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #85570       +/-   ##
===========================================
+ Coverage   33.00%   87.78%   +54.78%     
===========================================
  Files        8694    10263     +1569     
  Lines      483957   580499    +96542     
  Branches    22645    22645               
===========================================
+ Hits       159725   509616   +349891     
+ Misses     323797    70448   -253349     
  Partials      435      435               

mdtro added 3 commits April 28, 2025 16:24
…xchanges

- Add InvalidGrantError and ExpiredGrantError
- Add get_lock_key method to ApiGrant
- Add locking around grant exchanges in ApiToken.from_grant
- Add tests for race conditions
- add application status check in grant validation
- better error handling for lock acquisition failures
- add tests for concurrent grant usage
Copy link
Member

@sentaur-athena sentaur-athena left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@mdtro mdtro merged commit df0af00 into master Apr 29, 2025
65 checks passed
@mdtro mdtro deleted the mdtro/api-grant-security branch April 29, 2025 21:00
andrewshie-sentry pushed a commit that referenced this pull request May 12, 2025
…85570)

Pulled from #82052 to break out these changes into smaller PRs.

Use locks to ensure an `ApiGrant` cannot be used twice during a race
condition that would result in multiple access/refresh token pairs.
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants