Dropbox and Google Drive: the token refresh check fails on text errors and Dropbox refreshes on every 401

オープン
#694 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend, cloud

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

bug

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

  1. A TypeError for an error response that is not JSON. CloudAppTrait::sendRequest() passes the response body to accessTokenNeedsRefresh(int $code, ?object $message = null) in DropboxApp and GoogleDriveApp. ResponseParser::parseBody() returns an object only for a JSON response and the raw text otherwise, and Dropbox answers some errors with text/plain. With strict_types, the text causes a TypeError (Argument #2 ($message) must be of type ?object, string given) instead of the Exception with the API's error text that sendRequest() throws for errors that are not about the token.

  2. 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 returns true whenever 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 only invalid_access_token and expired_access_token refresh 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, so sendRequest() throws its Exception with that text.
  • DropboxApp refreshes only for the .tag values in ACCESS_TOKEN_STATUS.
  • Tests with a mocked HTTP client: a 401 with a text body throws the Exception; a 401 with another .tag throws without refreshing; a 401 with expired_access_token refreshes and retries once.
主要言語
PHP
スター
43
フォーク
22
平均マージ
54分
マージ済み PR(30日)
57

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quantum-php/framework のほかの issue

quantum-php/framework の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。