From c3c37e1650f1c075b421f7ba0c66058027b666eb Mon Sep 17 00:00:00 2001 From: gr Date: Tue, 27 Oct 2026 15:03:47 +0800 Subject: [PATCH] =?UTF-8?q?CA=E8=AF=81=E4=B9=A6=E5=8C=85=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E6=97=B6=E9=80=80=E5=9B=9E=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E5=BA=93=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=20CONFIG=5FINVALID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DifyRequiredAttachmentUpload:配置的 ca_file 不存在或不可读时记 warning 并改用系统证书库,仍校验对端证书与主机名 - DifyWorkflowRunStatus:同样处理,不再返回 RUN_STATUS_CONFIG_INVALID Co-Authored-By: Claude Opus 5.5 --- .../common/service/DifyRequiredAttachmentUpload.php | 11 ++++++++++- server/app/common/service/DifyWorkflowRunStatus.php | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/app/common/service/DifyRequiredAttachmentUpload.php b/server/app/common/service/DifyRequiredAttachmentUpload.php index 8cd85187a..c45c6ee89 100644 --- a/server/app/common/service/DifyRequiredAttachmentUpload.php +++ b/server/app/common/service/DifyRequiredAttachmentUpload.php @@ -284,7 +284,16 @@ final class DifyRequiredAttachmentUpload if (!array_key_exists('skip_missing', $options)) $options['skip_missing'] = true; if (!is_bool($options['skip_missing'])) self::fail('CONFIG_INVALID'); $caFile = $options['ca_file'] ?? ''; - if (!is_string($caFile) || ($caFile !== '' && (!is_file($caFile) || !is_readable($caFile)))) self::fail('CONFIG_INVALID'); + if (!is_string($caFile)) self::fail('CONFIG_INVALID'); + if ($caFile !== '' && (!is_file($caFile) || !is_readable($caFile))) { + // CA 证书包是可选项:路径失效(如 .env 沿用了其他机器的路径)时退回系统证书库, + // 仍校验对端证书与主机名,不再让所有 AI 请求因此失败。 + if (class_exists(\think\facade\Log::class)) { + try { \think\facade\Log::warning('dify attachment ca_file unreadable, using system CA store'); } + catch (\Throwable $ignored) {} + } + $caFile = ''; + } $options['ca_file'] = $caFile; $options['resolved_hosts'] = self::resolvedHosts(array_key_exists('resolved_hosts', $options) ? $options['resolved_hosts'] : []); diff --git a/server/app/common/service/DifyWorkflowRunStatus.php b/server/app/common/service/DifyWorkflowRunStatus.php index 575bc4137..186e989fb 100644 --- a/server/app/common/service/DifyWorkflowRunStatus.php +++ b/server/app/common/service/DifyWorkflowRunStatus.php @@ -41,10 +41,11 @@ final class DifyWorkflowRunStatus $upload = array_key_exists('required_attachment_upload', $config) ? $config['required_attachment_upload'] : []; $caFile = is_array($upload) ? (array_key_exists('ca_file', $upload) ? $upload['ca_file'] : '') : null; $root = is_string($baseUrl) ? self::apiRoot($baseUrl) : null; + // 可选 CA 证书包路径失效时退回系统证书库(仍校验证书),与附件上传保持一致。 + if (is_string($caFile) && $caFile !== '' && (!@is_file($caFile) || !@is_readable($caFile))) $caFile = ''; if ($root === null || !is_string($apiKey) || $apiKey === '' || strlen($apiKey) > 4096 || preg_match('/[^\x21-\x7e]/', $apiKey) !== 0 - || !is_string($caFile) || preg_match('/[\x00-\x1f\x7f]/', $caFile) !== 0 - || ($caFile !== '' && (!@is_file($caFile) || !@is_readable($caFile)))) { + || !is_string($caFile) || preg_match('/[\x00-\x1f\x7f]/', $caFile) !== 0) { return self::error('RUN_STATUS_CONFIG_INVALID'); } unset($config, $models, $model, $upload, $baseUrl);