简体   繁体   English

保护 NodeJS RESTful API 和 React 客户端应用程序

[英]Securing NodeJS RESTful API and React client app

I've a backend RESTful API built in NodeJS and a front end application in React JS(NextJS), both hosted on AWS.我有一个内置在 NodeJS 中的后端 RESTful API 和一个在 React JS(NextJS)中的前端应用程序,两者都托管在 AWS 上。 The client and server communicates using JWT token.客户端和服务器使用 JWT 令牌进行通信。 I want to make sure both the client app and server side app are highly secured.我想确保客户端应用程序和服务器端应用程序都是高度安全的。

What i've done:我做了什么:

  • I'm using HTTPS for both client and server我对客户端和服务器都使用 HTTPS
  • Whitelist the client react app IP address so only the client react app can talk to the server app.将客户端反应应用程序 IP 地址列入白名单,以便只有客户端反应应用程序可以与服务器应用程序通信。 This was done in AWS security group这是在 AWS 安全组中完成的
  • Use cors in my server Node.JS application, to whitelist the client IP address again as an addition to No. 1在我的服务器 Node.JS 应用程序中使用 cors,将客户端 IP 地址再次列入白名单,作为第 1 号的补充
  • Use AWS WAF to secure the backend NodeJS application,使用 AWS WAF保护后端 NodeJS 应用程序,
  • Use helmet in the NodeJS server backend API在 NodeJS 服务器后端使用安全帽API
  • Make sure the JWT token only last seven days, it'll be invalid and the user needs to login again to get a new token.确保 JWT 令牌仅持续 7 天,它将无效,用户需要再次登录才能获得新令牌。

Answers i've looked at and used:我看过并使用过的答案:

  1. How to secure client app (react) and API communication 如何保护客户端应用程序(反应)和 API 通信

  2. According to: RESTful Authentication i'm using Token in HTTP headers (eg OAuth 2.0 + JWT), this i sent for every client request根据: RESTful Authentication我在 HTTP 标头中使用令牌(例如 OAuth 2.0 + JWT),这是我为每个客户端请求发送的

  3. Using a refresh token: Refresh Token Jsonwebtoken使用刷新令牌: 刷新令牌 Jsonwebtoken

    What i'm concerned about, and i need some help with:我关心的是什么,我需要一些帮助:

    1. Since the JWT token is how the server validates the client, is the JWT communication secured? 1.既然JWT令牌是服务器验证客户端的方式,那么JWT通信是否安全? Are there other steps i can take to improve the JWT security?我可以采取其他步骤来提高 JWT 的安全性吗?

    2. Is this application architecture secured enough? 2. 这个应用架构是否足够安全?

    3. Is there anything else i can do improve it's security, as i'm really concerned and want to make sure it's very secured. 3. 我还能做些什么来提高它的安全性,因为我真的很担心并且想确保它非常安全。

    4. Should i encrypt the JSON payload sent from the client to the server? 4. 我应该加密从客户端发送到服务器的 JSON 有效载荷吗? because that's visible in any browser network tab under XHR, i'm sending username & password as payload for login.因为这在 XHR 下的任何浏览器网络选项卡中都可见,所以我正在发送用户名和密码作为登录的有效负载。

I'm mostly concerned about security because i've integrated stripe payment in the application, and i'm also storing some sensitive data.我最关心的是安全性,因为我已经在应用程序中集成了条带支付,而且我还存储了一些敏感数据。

Any recommendation would be high appreciated, this is my first time deploying an production app.任何建议将不胜感激,这是我第一次部署生产应用程序。

As of what you have done the application must be pretty much secure.... except i would like to add a few things....正如你所做的那样,应用程序必须非常安全......除了我想添加一些东西......

  1. Make sure that the tokens have expiry and use refresh token to issue new tokens.确保令牌已过期并使用刷新令牌颁发新令牌。 The jwt stored at clients could be vulnerable for man in the middle attack.存储在客户端的 jwt 可能容易受到中间人攻击。 (For more performance use redis to store refresh tokens... look more on this) (为了获得更高的性能,请使用 redis 来存储刷新令牌......查看更多内容)
  2. If you are using https, the request will be only visible to the client's browser and not to any sniffers in the network (check on this whether ure able to see encrypted payload in sniffing tools like wireshark etc... to validate the https uve used).如果您使用的是 https,则该请求将仅对客户端的浏览器可见,而对网络中的任何嗅探器均不可见(检查是否能够在诸如 wireshark 等嗅探工具中看到加密的有效负载......以验证您使用的 https )。 So its not necessary to go for any more encryption.因此,不再需要 go 进行任何加密。 That would decrease the performance of the api server.这会降低 api 服务器的性能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM