在浏览器控制台上为未经身份验证的用户禁用 Meteor Router.routes

Disable Meteor Router.routes on browser console for unauthenticated user

我正在开发一个使用 Iron Router 的 Meteor 应用程序。我们的应用程序中有一个登录页面。即使用户未登录,如果我在开发人员控制台上以未授权用户身份调用以下代码:

Router.routes

它给出了所有的路线和各自的路径。有没有办法禁用对这些路径的访问,或者我是否需要在服务器代码中推送这些端点?

您在客户端上定义的所有内容在客户端上都是可见的。所有路由定义和路由逻辑也是如此。在生产代码中,这将被混淆,但它仍然存在。

如果您担心客户可以读取您的路线,那么您应该更关心它与您有关的事实。听起来有点混乱,但重点是:您应该仔细检查通过出版物发布到客户端或通过服务器上的方法操作/创建的每个数据。如果您的后端尽可能健壮和安全(100% 永远不可能),那么您无需关心客户端是否可以看到哪些路由存在并可以访问它们。

例子:

Bob 找到路由 /admin 并禁用路由器的触发器以在他不是管理员时重定向他。

现在 Bob 可以看到管理员可以看到的所有数据。为防止这种情况,您可以检查 publication 如果 Bob 具有角色 'admin' 如果他不是管理员则不要发布给他。

Ada 也找到了管理面板的这种方式,并想创建一个新用户。因为您用于创建新用户的服务器方法是 ValidatedMedthod 检查 Ava 是否具有 'admin' 角色,所以它将无法创建新用户,因为 Ava 不是管理员。

结论:

阻止客户端访问只是 UI Magic bot 一点也不安全。简单的调整,但在服务器端将帮助您睡得更好。

更多帮助:

入门的一个好方法是阅读 Meteor 安全指南:

https://guide.meteor.com/security.html

最后还有一个安全清单,出于完整性和 SEO 的原因,我只是在此处引用它:

  1. Make sure your app doesn’t have the insecure or autopublish packages.
  2. Validate all Method and publication arguments, and include the audit-argument-checks to check this automatically.
  3. Deny writes to the profile field on user documents.
  4. Use Methods instead of client-side insert/update/remove and allow/deny.
  5. Use specific selectors and filter fields in publications.
  6. Don’t use raw HTML inclusion in Blaze unless you really know what you are doing.
  7. Make sure secret API keys and passwords aren’t in your source code.
  8. Secure the data, not the UI - redirecting away from a client-side route does nothing for security, it’s just a nice UX feature.
  9. Don’t ever trust user IDs passed from the client. Use this.userId inside Methods and publications.
  10. Set up browser policy, but know that not all browsers support it so it just provides an extra layer of security to users with modern browsers.

回答中提到的有用包:

mdg:validated-method

alanning:roles

audit-argument-checks