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

Đang mở
#694 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend, cloud

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
PHP
Star
43
Fork
22
Merge trung bình
54 phút
Pull request đã merge (30 ngày)
57

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quantum-php/framework

Tất cả issue của quantum-php/framework

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.