Blazor 服务器:使用 HTTPS 保护传输中的信息:WebSocket 是否不够安全?

发布于 2025-01-11 12:27:28 字数 1070 浏览 0 评论 0原文

Blazor 服务器开发非常棒!我担心的问题之一是通过 SignalR/WebSockets 发送数据的安全性。

根据我的理解,客户端和服务器之间的通信是:

  1. 用户采取操作,例如单击按钮
  2. Javascript 创新了与服务器的 WebSocket 通信
  3. 服务器用我返回的数据进行响应
  4. Javascript 更改页面 (DOM)

从 Chrome 开发者工具中,我可以在 websocket 上看到这种情况发生,即 wss://localhost/_blazor?id=XXXXXXXXXXXXXXX。由于 websocket 是 wss:// 我认为通信是安全的并且确保了完整性和机密性,例如中间人攻击等

那么为什么 Microsoft 建议更改为 Blazor 服务器威胁迁移文档中的“始终使用 HTTPS”?

通过 HTTPS 保护传输中的信息

Blazor Server 使用 SignalR 在客户端和 服务器。 Blazor 服务器通常使用 SignalR 的传输 协商,通常是 WebSocket。

Blazor 服务器不确保数据的完整性和机密性 服务器和客户端之间发送的数据。始终使用 HTTPS。

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/threat-mitigation?view=aspnetcore-6.0#protect-information-in-transit-with-https

Blazor Server development is great! One of my concerns is with the security of data being sent through SignalR/WebSockets.

From my understanding the communication between client and server is:

  1. Action is taken by user e.g. clicks button
  2. Javascript innovates the WebSocket communication with my server
  3. Server responds with data that I've returned
  4. Javascript changes the page (DOM)

From Chrome developer tools I can see this happening on the websocket i.e. wss://localhost/_blazor?id=XXXXXXXXXXXXXX. As the websocket is wss:// I thought communication was secure and ensured integrity and confidentiality e.g. man-in-the-middle attacks etc

So why has Microsoft advised to "Always user HTTPS" in their Blazor Server Threat Migration documentation?

Protect information in transit with HTTPS

Blazor Server uses SignalR for communication between the client and
the server. Blazor Server normally uses the transport that SignalR
negotiates, which is typically WebSockets.

Blazor Server doesn't ensure the integrity and confidentiality of the
data sent between the server and the client. Always use HTTPS.

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/threat-mitigation?view=aspnetcore-6.0#protect-information-in-transit-with-https

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2025-01-18 12:27:28

感谢布伦南在评论中回答我的问题。

那么,为什么 Microsoft 建议在其 Blazor 服务器威胁迁移文档中“始终使用 HTTPS”?

该警告只是一般文本。文档中的两个声明是相互独立的。

下面解释了 Blazor Server 通常用于客户端和服务器之间通信的机制,即 WebSockets

<块引用>

通过 HTTPS 保护传输中的信息

Blazor Server 使用 SignalR 在客户端和服务器之间进行通信。 Blazor 服务器通常使用 SignalR 协商的传输,通常是 WebSocket。

下面指出在客户端和服务器之间通信时应始终使用安全协议,即 HTTPS

<块引用>

Blazor 服务器不确保服务器和客户端之间发送的数据的完整性和机密性。始终使用 HTTPS。

我认为 Microsoft 指的是使用标准 API (HTTP/2) 端点来确保完整性和机密性。正如 Brennan 指出的 - WebSockets 是 HTTP/1.1 的扩展,因此可以使用 HTTPS。

希望这对未来的人们有所帮助。

Thank you to Brennan for answering my question in the comments.

So why has Microsoft advised to "Always user HTTPS" in their Blazor Server Threat Migration documentation?

The warning is just general text. The two statements on the documentation are independent of each other.

The below explains the mechanism Blazor Server typically uses for communication between client and server i.e. WebSockets

Protect information in transit with HTTPS

Blazor Server uses SignalR for communication between the client and the server. Blazor Server normally uses the transport that SignalR negotiates, which is typically WebSockets.

The below states you should always use a secure protocol when communicating between client and server i.e. HTTPS

Blazor Server doesn't ensure the integrity and confidentiality of the data sent between the server and the client. Always use HTTPS.

I assumed Microsoft was referring to using standard API (HTTP/2) endpoints to ensure integrity and confidentiality. As Brennan pointed out - WebSockets is an extension of HTTP/1.1, and thus can use HTTPS.

Hopefully, this helps people in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文