保护表单提交的公共端点

发布于 2025-01-15 00:53:21 字数 471 浏览 2 评论 0原文

我有一个 next.js 静态网站,其中有一些表单,例如联系方式、工作申请等。我们的后端是.NET 4.6。由于这些表单是公开的,API 端点(Web 服务)基本上没有身份验证,任何人都可以使用 Postman 等工具开始发出请求。如何确保这些端点的安全?我想到了一些我可以做的事情:

  1. 加密这些请求的有效负载,然后在处理之前在后端解密它们。这个想法是,如果其他人可以看到端点 URL,他们仍然无法正确加密数据,端点将拒绝它。出现的问题是,可以使用开发工具检查前端用于加密有效负载的密钥,然后任何人都可以发送正确加密的有效负载。

  2. 在后端,检查请求标头以确保引用或原始标头指向我的网站。现在的问题是,有一些工具可以帮助您模仿成功的请求标头,这意味着有人可以使用正确的标头来欺骗请求。

确保这些端点安全的最佳方法是什么?有没有办法限制我的网站只能请求它?或者有没有办法在客户端隐藏加密密钥?关于如何解决这个问题还有其他建议吗?

I have a next.js static website that has some forms such as contact, job applications, etc. Our backend is .NET 4.6. Since these forms are public, the API endpoints (Web services) basically have no authentication and anyone could start making requests using a tool such as Postman. How could I make these endpoints secure ? I thought of a few things I could do:

  1. Encrypting the payloads of these requests and then decrypting them at the backend before processing it. The idea being if someone else can see the endpoint url, they still can't encrypt the data correctly and the endpoint would reject it. The problem arises that the key that frontend uses to encrypt the payload can be inspected using dev tools and then anyone could send correctly encrypted payloads.

  2. At the backend, checking the request headers to make sure that referer or origin headers point to my website. The problem now is that there are tools that can help you imitate a successful request headers, meaning that someone could spoof a request with correct headers.

What would be best way to making those endpoints secure ? Is there a way I can restrict only my website to be able to request it ? Or is there a way to hide the encryption keys on client side ? Any other suggestions on how I could approach this problem ?

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

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

发布评论

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

评论(1

找回味觉 2025-01-22 00:53:21

由于您的 API 是公开的,并且生成有效负载的 HTML 也是公开的,因此实际上无法保证安全性。
但是,您可以通过使用以下步骤来使其变得更加困难

  1. 请求在表单提交期间发送令牌

    • 当请求此令牌时,记录请求者的 IP
    • 限制每个 IP 每小时允许的请求数量(可能是 5?)
  2. 将从 #1 获取的令牌传递到 #2

    • 提交表单后,验证令牌的请求者 IP 和当前请求 IP 是否匹配
    • 检查给定时间范围内是否有来自同一 IP 的其他表单提交,如果有,则拒绝该请求。

或者

您只需限制每个 IP 每小时允许的提交数量。
虽然这不会阻止攻击,但它会减慢他们的速度,使他们能够转向更容易的目标。

Since your API is public and the HTML that generates the payload is public, there is really no way to guarantee security.
However, you could make it harder by using the following steps

  1. Request a token to send during form submit

    • When this token is requested, log the requestor's IP
    • Limit how many requests per IP can be allowed per hour (may be 5?)
  2. Pass the token gotten from #1 in #2

    • When the form is submitted, verify that the token's requestor IP and current request IP Match
    • Check if there are other form submissions from the same IP in a given timeframe, if so, reject the request.

OR

You simply limit how many submissions per IP per hour are allowed.
While this will not STOP the attack, it will slow them down enough that they will move to easier targets.

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