Dropbox and Google Drive: the token refresh check fails on text errors and Dropbox refreshes on every 401
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start in CloudAppTrait::sendRequest() to see how the parsed body reaches accessTokenNeedsRefresh(int $code, ?object $message = null) in DropboxApp and GoogleDriveApp, and in ResponseParser::parseBody() to confirm a non-JSON body comes back as a string. Widen both signatures to mixed and handle only object bodies, then change the Dropbox condition to || so only the tags in ACCESS_TOKEN_STATUS refresh. Done means new tests with a mocked HTTP client cover a 401 with a text body, a 401 with an unrelated .tag, and a 401 with expired_access_token refreshing exactly once.
Written by the indexing model from the issue text.
Description
Summary
The Dropbox and Google Drive storage adapters decide after a failed API request whether the access token must be refreshed. That check fails in two ways.
Problems
-
A
TypeErrorfor an error response that is not JSON.CloudAppTrait::sendRequest()passes the response body toaccessTokenNeedsRefresh(int $code, ?object $message = null)inDropboxAppandGoogleDriveApp.ResponseParser::parseBody()returns an object only for a JSON response and the raw text otherwise, and Dropbox answers some errors withtext/plain. Withstrict_types, the text causes aTypeError(Argument #2 ($message) must be of type ?object, string given) instead of theExceptionwith the API's error text thatsendRequest()throws for errors that are not about the token. -
Dropbox refreshes the token on every 401.
DropboxApp::accessTokenNeedsRefresh()reads:if (!isset($error['.tag']) && !in_array($error['.tag'], self::ACCESS_TOKEN_STATUS)) { return false; } return true;With
&&the method returnstruewhenever the error has a.tag, whatever its value, so a 401 that is not about the token (for example a missing permission) refreshes the token and retries.sendRequest()retries by calling itself, so the same 401 starts the next refresh: the request repeats until PHP gives up. Without a.tag, the code reads$error['.tag']anyway and raises a warning. The condition should use||, so onlyinvalid_access_tokenandexpired_access_tokenrefresh the token.
Both are in 3.1.x as well; they are fixed in 3.2.0.
Fix
accessTokenNeedsRefresh()in both apps accepts the response body as it comes (mixed) and reads the error only from an object; a text body is not a token error, sosendRequest()throws itsExceptionwith that text.DropboxApprefreshes only for the.tagvalues inACCESS_TOKEN_STATUS.- Tests with a mocked HTTP client: a 401 with a text body throws the
Exception; a 401 with another.tagthrows without refreshing; a 401 withexpired_access_tokenrefreshes and retries once.
- Dominant language
- PHP
- Stars
- 43
- Forks
- 22
- Avg merge
- 54m
- Merged PRs (30d)
- 57
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantum-php/framework
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quantum-php/framework#692 ·
Maintainers usually reply within 1 day
-
routing testing
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quantum-php/framework#547 ·
Maintainers usually reply within 1 day
-
refactoring tech debt
Difficulty 5/5 Over a week Newbie friendliness 20/100
quantum-php/framework#693 ·
Maintainers usually reply within 1 day
-
install:debugbar reads the package folder from the working directory and uses the default storage adapterPossibly taken @armanist claimed this today. Openbug console debugbar good first issue
quantum-php/framework#691 · 1 assignee ·
Maintainers usually reply within 1 day
-
console enhancement
Difficulty 4/5 3-5 days Newbie friendliness 74/100
quantum-php/framework#688 ·
Maintainers usually reply within 1 day
All issues in quantum-php/framework
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 70/100
ajeetraina/awesome-docker-sbx#559 ·
-
dependencies enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
novalo-dev/Prestashop-MCP-Server#329 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
bug origin:interactive status:available
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Ultimate-Multisite/ultimate-multisite#2131 ·
Maintainers usually reply within 1 day
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day