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);