# 域名解析问题影响主题嵌入

**URL:** <https://meta.discourse.org/t/domain-resolution-issue-affecting-topic-embeds/304868>\
**Category:** Bug\
**Created:** [2024年四月22日 07:25 UTC](https://meta.discourse.org/t/domain-resolution-issue-affecting-topic-embeds/304868 "2024-04-22T07:25:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)\
**Post date:** [2024年四月22日 07:25 UTC](https://meta.discourse.org/t/domain-resolution-issue-affecting-topic-embeds/304868/1 "2024-04-22T07:25:01Z")

</div>

可能存在影响主题嵌入的域名解析问题。

1. 主题嵌入系统依赖 FinalDestination 来解析主题嵌入 URL（[参见此处](https://github.com/discourse/discourse/blob/main/app/models/topic_embed.rb#L132)）。

2. FinalDestination 通过 SSRFDetector 解析 URL 的主机名到 IP（[参见此处](https://github.com/discourse/discourse/blob/main/lib/final_destination.rb#L259)）

3. FinalDestination 然后将 URI 发送给 Excon 以执行实际请求（[参见此处](https://github.com/discourse/discourse/blob/main/lib/final_destination.rb#L268)）。

这意味着某些主题嵌入 URL，例如

```plaintext
"https://opensource.org/blog/osi-response-to-ntia"

```

最终会被发送给 Excon 执行 GET 请求，如下所示：

```plaintext
"https://[2604:a880:800:a1::2f0:a001]/blog/osi-response-to-ntia"

```

此请求将超时。而对原始 URL 执行 `Excon.get` 则不会。

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2024年四月22日 09:39 UTC](https://meta.discourse.org/t/domain-resolution-issue-affecting-topic-embeds/304868/2 "2024-04-22T09:39:19Z")

</div>

在 Meta 上看起来还可以：

> **[OSI’s responds to NTIA on widely available AI models](https://opensource.org/blog/osi-response-to-ntia)**
>
> In addition to joining a number of other organizations in responding to the NTIA’s Request for Comment on, OSI has provided its organizational response to the call for public comment, centering its encouragement on the societal benefits of open...

根据您的描述，我猜测您的服务器在进行 DNS 查询时解析了 ipv6 记录（我们使用 [getaddrinfo](https://github.com/discourse/discourse/blob/b3f119231216d0ddad384960380f335a9f65e8e0/lib/final_destination/resolver.rb#L57) 来实现此功能）。但随后在尝试连接它们时，却失败了。

> [@angus](#):
>
> 原始 URL 的 `Excon.get` 不会。

这可能是因为它尝试使用 ip6 地址，失败了，然后回退到 ip4 地址。我们目前在 `FinalDestination#resolve` 中没有这种回退逻辑：

> <https://github.com/discourse/discourse/blob/b3f119231216d0ddad384960380f335a9f65e8e0/lib/final_destination.rb#L256-L257>
