简体   繁体   English

如何使用 express 和 nuxtjs 加密/解密 API 数据以防止刮擦?

[英]How to encrypt/decrypt API data with express and nuxtjs to prevent scraping?

I want to encrypt my API data so that the user can't see it in the network tab or as plaintext in something like the window.__nuxt__ object.我想加密我的 API 数据,以便用户无法在网络选项卡中看到它,也无法在window.__nuxt__ object 之类的内容中看到它。

The way I'm doing this now:我现在这样做的方式:

  1. encrypt data in back-end with a secret string (like a password)使用秘密字符串(如密码)在后端加密数据
  2. send encrypted data to front-end将加密数据发送到前端
  3. decrypt it on client-side (using the same password as in the back-end)在客户端解密(使用与后端相同的密码)

Here is the problem: The function that decrypts my data can be found by looking through the bundled JavaScript files in the Browser.这是问题所在:通过浏览浏览器中捆绑的 JavaScript 文件,可以找到解密我的数据的 function。

Although the function is obfuscated, it is possible the reverse engineer it.尽管 function 被混淆了,但有可能对其进行逆向工程。 And since the password is stored within the function (it has to be, right? Since I don't have the process.env variables on the client-side) everyone can(theoretically) scrape my data.而且由于密码存储在 function 中(它必须是,对吧?因为我在客户端没有 process.env 变量)每个人都可以(理论上)刮我的数据。

What is the best way to prevent this?防止这种情况的最佳方法是什么?

I know that the data is visible eventually in the browser.我知道数据最终在浏览器中是可见的。 I just don't want it the be visible in plaintext.我只是不希望它以纯文本形式显示。

I'm using express in the back-end and NuxtJS in the front-end by the way.顺便说一句,我在后端使用 express,在前端使用 NuxtJS。

There's no way to prevent this.没有办法阻止这种情况。 All you can do is make it more difficult.你所能做的就是让它变得更加困难。

Ultimately, if the data is visible to the user in the browser, you can just get it from the DOM in memory.最终,如果用户在浏览器中可以看到数据,则可以从 memory 中的 DOM 中获取数据。 All the code to transform the encrypted data into the original information must be supplied if you need the user to see the data.如果您需要用户查看数据,则必须提供将加密数据转换为原始信息的所有代码。

You can obfuscate the code, but your attacker doesn't even need to reverse engineer it to get the data, they just need to run it.你可以混淆代码,但你的攻击者甚至不需要逆向工程来获取数据,他们只需要运行它。

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

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