X5UFactory: an x5u entry can name a local file

Đang mở
#764 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
69/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
api, backend, security

Hướng nghiên cứu

Read X5UFactory::loadFromUrl() and the certificate loading path through KeyConverter::loadKeyFromCertificate(). Reproduce with the provided MockHttpClient example and check existing tests for x5u certificate formats. Done means entries containing the PEM marker no longer let OpenSSL interpret the value as a file:// path while the listed certificate formats still load.

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

Every release since 1.0.1 / 1.1.0, including 3.4.12, 4.0.8, 4.1.10, 4.2.5 and 4.3.x-dev

Description

X5UFactory::loadFromUrl() wraps an entry between PEM markers only when the entry does not already contain -----BEGIN CERTIFICATE-----, then hands it to openssl_x509_read() through KeyConverter::loadKeyFromCertificate(). OpenSSL opens a file when the string starts with file://. An entry such as

file:///-----BEGIN CERTIFICATE-----/../path/to/cert.pem

is therefore not wrapped, and the application reads /path/to/cert.pem. The path is resolved lexically, so the marker directory does not need to exist. If the file holds a PEM certificate, its public key and x5c come back as a key of the set; any other file gives the usual Unable to load the certificate.. open_basedir applies.

Only the host that answers the configured x5u URL (or the network, for an http:// URL) controls these entries. That host already chooses the keys, so no token can be forged this way. It can however probe the server for certificate files, and make the worker block on a path such as a FIFO.

How to reproduce
use Jose\Component\KeyManagement\X5UFactory;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;

$client = new MockHttpClient(new MockResponse(json_encode([
    'partner' => ['file:///-----BEGIN CERTIFICATE-----/..' . $absolutePathOfALocalCertificate],
])));
$keySet = (new X5UFactory($client))->loadFromUrl('https://partner.example.com/x5u');

// $keySet->get('partner') is the local certificate. The same entry without the marker is refused.
Possible Solution

In X5UFactory, when the marker is present, pass OpenSSL the entry from the marker on (substr($cert, strpos($cert, $marker))), and wrap it as today otherwise. The string then never starts with file://, and the formats accepted today (base64 body, PEM block, PEM preceded by text) still load. That fits a patch release.

JWKFactory::createFromCertificate() and createFromKey() (and the 4.3 fromCertificate() / fromKey()) accept file:// strings as well, because OpenSSL does. Only application strings reach them, and some code may rely on it, so refusing file:// there should go through a deprecation that points to createFromCertificateFile() / createFromKeyFile().

Additional Context

Found by the Anthropic OSS Scanner (ANT-2026-3MVD83LW). Same trust boundary as #762: the key set host reaching beyond the document it serves.

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.