CallableChecker accepts any truthy result of its callable since 4.1.8

Đang mở
#767 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
76/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-api-design

Hướng nghiên cứu

Start with CallableChecker::checkClaim() and checkHeader(), then inspect CallableCheckerTest::theCallableDoesNotReturnABoolean() and .ci-tools/rector.php. Add separate claim and header cases for the listed non-boolean results, and confirm both methods refuse every result other than true while the Rector job preserves that behavior. Update the changelog to explain the return-value requirement.

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

Mô tả

bug
Version(s) affected

4.1.8 to 4.1.10, 4.2.0 to 4.2.5, and the 4.3.x and 5.0.x branches. 3.4.x and 4.0.x are not affected.

Description

From 3.3.0 to 4.1.7, Jose\Component\Checker\CallableChecker accepted a claim or header value only when its callable returned true; any other result was a refusal. Since 4.1.8, any truthy result accepts the value: 1, a non-empty string, a non-empty array, an object.

The strict comparison was lost in a Rector rewrite (SimplifyBoolIdenticalTrueRector) in 6c2bdcff, in both checkClaim() and checkHeader():

-        if (call_user_func($this->callable, $value) !== true) {
+        if (! call_user_func($this->callable, $value)) {

Rector trusts the docblock callable(mixed $value): bool, which nothing enforces at run time. Callables that return a boolean behave as before. A callable that reports a refusal with a truthy value (an error message, a list of errors, an object, a non-zero code) now accepts the value it means to refuse.

CallableCheckerTest::theCallableDoesNotReturnABoolean() did not catch it: it calls expectException() twice in one method. The claim part now returns without exception, and the header part (fn () => 0) throws the exception the second expectException() waits for, so the test passes with both versions of the class.

How to reproduce
use Jose\Component\Checker\CallableChecker;

$checker = new CallableChecker('scope', static fn (mixed $scope): mixed => $scope === 'invoices:write' ? true : 'scope not allowed');
$checker->checkClaim('invoices:read');

// 4.1.7: InvalidClaimException 'The "scope" claim is invalid.'
// 4.1.8 and later: no exception
Possible Solution
  • Restore !== true in both methods.
  • Skip SimplifyBoolIdenticalTrueRector for this file in .ci-tools/rector.php, otherwise the Rector job rewrites it again, and say in the constructor docblock that any result other than true is a refusal. Keeping the : bool return type in the docblock lets static analysers flag callables such as preg_match().
  • Replace the test with one claim test and one header test, each expecting a single exception, fed by a data provider: false, null, 0, 1, -1, a string, an array, an object.
  • Changelog: a callable that relies on truthiness, e.g. fn ($v) => preg_match('/…/', $v), refuses every value again, as before 4.1.8; it has to return a boolean.
Additional Context

Found by the Anthropic OSS Scanner (ANT-2026-IIOME38Z).

Ngôn ngữ chính
PHP
Star
954
Fork
119
Merge trung bình
48 phút
Pull request đã merge (30 ngày)
17

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 web-token/jwt-framework

Tất cả issue của web-token/jwt-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.