简体   繁体   English

在node.js API端点中禁止直接URL访问

[英]Disallow direct URL access in node.js API endpoint

I have an api endpoint but I want it to be access only from a certain website. 我有一个api端点,但我希望只能从某个网站访问它。

The api is from api.mydomain.com/v1/ And the website that can only access that api is mydomain.com . api来自api.mydomain.com/v1/ ,只能访问该api的网站是mydomain.com I already implemented CORS, but since my website can be access by public, no need for login, also it is static and the api is called by ajax, i did not added token. 我已经实现了CORS,但是由于我的网站可以由公众访问,无需登录,而且它是静态的,并且api由ajax调用,因此我没有添加令牌。 If the user will view-source my site they will see the api endpoint. 如果用户查看我的网站的源代码,他们将看到api端点。 So if they browse the endpoint, they can access the data directly. 因此,如果他们浏览端点,则可以直接访问数据。 I want the url end point to be access by my domain and not by directly accessing it. 我希望URL端点可以被我的域访问,而不是直接访问它。 How can I do it in node.js express project? 如何在node.js express项目中做到这一点?

看起来你需要添加某种CSRF保护,其中所有的API请求只取得由mydomain.com网页将包含一些安全令牌(您或您使用的应该提供这个安全令牌的执行框架)本SO帖子可能会帮助进一步

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

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