简体   繁体   English

节点JS | 英雄联盟 | MongoDB 地图集 | 如何确保只有我的应用程序可以访问我的后端?

[英]Node JS | Heroku | MongoDB Atlas | How do I make sure only my app can access my backend?

I've built my backend using MongoDB Atlas, Express, and Node JS and deployed it to Heroku.我使用 MongoDB Atlas、Express 和 Node JS 构建了我的后端,并将其部署到 Heroku。 Using Postman, the app is operating properly so far (users are getting added and I'm receiving the json web token correctly).使用 Postman,该应用程序目前运行正常(用户正在添加并且我正在正确接收 json 网络令牌)。

But I'm thinking that this might not be correct because it seems like anyone with access to my Heroku URL and routes can easily create a new user, receive the json web token, and basically operate their entire app using my backend.但我认为这可能不正确,因为似乎任何有权访问我的 Heroku URL 和路由的人都可以轻松创建新用户,接收 json 网络令牌,并基本上使用我的后端操作他们的整个应用程序。

My questions are:我的问题是:

  1. Am I missing something huge about how I've built my backend?我是否遗漏了一些关于我如何构建后端的重要信息?
  2. How do I go about securing my backend so that only my apps can access the backend?我如何着手保护我的后端,以便只有我的应用程序可以访问后端?

You can use Passportjs to protect your routes, passport will be your middleman between person accessing the back-end and your actual back-end.您可以使用Passportjs来保护您的路线,护照将成为访问后端的人和您的实际后端之间的中间人。

You can give access to the routes if a valid JWT is passed ( JWT strategy ) otherwise it will throw 401 (Unauthorized).如果传递了有效的 JWT( JWT 策略),您可以授予对路由的访问权限,否则它将抛出 401(未授权)。

There are 400+ strategies available, I will recommend JWT one because you are already generating JWT.有 400 多种策略可用,我会推荐 JWT 一种,因为您已经在生成 JWT。

Protecting backed is integral part because most of scripts can disable security on front-end leaving apps vulnerable to attacks.保护后台是不可或缺的一部分,因为大多数脚本可以禁用前端的安全性,使应用程序容易受到攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅在node.js heroku应用程序上授予对我的网站的访问权限 - How do i grant access to my site only on a node.js heroku app 为什么我的 AWS Lambda 节点 JS 应用程序无法访问我的 MongoDB Atlas 集群? - Why can't my AWS Lambda node JS app access my MongoDB Atlas cluster? 如何在我的节点 js 应用程序中显示来自 MongoDB Atlas 的数据? - How do i display my data from MongoDB Atlas in my node js application? 仅从我的应用程序访问我的后端node.js - access my backend node.js only from my app 我可以使用 Netlify 为我的 node.js 后端托管我的 React Web 应用和 Heroku 吗? - Can I use Netlify to host my React web app and Heroku for my node.js backend? 如何在Heroku上部署MongoDB app并接入MongoDB Atlas? - How do I deploy MongoDB app on Heroku and connect it to MongoDB Atlas? 如何将我的本地 node.js 应用程序连接到我的 Heroku Postgres 数据库? - How can I connect my local node.js app to my Heroku Postgres database? 将 MongoDB Atlas 连接到 Heroku Node.js 应用程序的替代方案 - Alternatives for connecting MongoDB Atlas to Heroku Node.js app 无法在heroku上使用node.js连接到mongodb-atlas - can't connect to mongodb-atlas with node.js on heroku 如何将我的Heroku配置变量链接到Node.js应用程序 - How do I link my Heroku Config Variables to a Node.js app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM