简体   繁体   English

有没有办法识别快速的服务器到服务器请求来源

[英]Is there a way to identify express server-to-server request origin

Is there a way to obtain the origin information of a remote server making requests to my api server?有没有办法获取向我的 api 服务器发出请求的远程服务器的源信息? The objective is to prevent possible server-to-server authentication token spoofing.目的是防止可能的服务器到服务器身份验证令牌欺骗。

To test, I basically sent remote requests to the server from a test server listening on port 8000 .为了进行测试,我基本上从侦听端口8000的测试服务器向服务器发送了远程请求。 While the req.connection.remote.address logged by the api server was consistent, the req.connection.remote.port changed with every request.虽然 api 服务器记录的req.connection.remote.address是一致的,但req.connection.remote.port随着每个请求而变化。

Is there a way to obtain the address of the test server along with its port 8000 from the request object at the api server?有没有办法从api服务器的请求对象中获取测试服务器的地址及其端口8000 An outside of the box solution would be appreciated as well.盒外解决方案也将受到赞赏。

Is there a way to obtain the address of the test server along with its port 8000 from the request object at the api server?有没有办法从api服务器的请求对象中获取测试服务器的地址及其端口8000?

No, there is not unless the requesting server specifically provides that information for you in a non-standard (custom) header.不,除非请求服务器在非标准(自定义)标头中专门为您提供该信息,否则不会。 It is not part of TCP/IP or HTTP that you would know anything about what type of http client it is that is making the request or that it's even actually an http server making a request of your http server.它不是 TCP/IP 或 HTTP 的一部分,您不知道发出请求的是什么类型的 http 客户端,或者它甚至实际上是一个 http 服务器向您的 http 服务器发出请求。 From the networking point of view, it's just some http client at some IP address and you don't know anything about what else that http client might be doing (in your case also an http server).从网络的角度来看,它只是某个 IP 地址上的某个 http 客户端,而您对该 http 客户端可能正在执行的其他操作一无所知(在您的情况下也是一个 http 服务器)。

An incoming TCP/IP connection never comes from the public, incoming port of the requesting web server.传入 TCP/IP 连接永远不会来自请求 Web 服务器的公共传入端口。 Instead, it comes from some dynamically assigned outbound port that is likely different for every request.相反,它来自某个动态分配的出站端口,每个请求可能都不同。 That's how TCP/IP works.这就是 TCP/IP 的工作原理。 Outbound ports are dynamically assigned when the socket is created and they come from a different port range than is typically used for listening for incoming requests.创建套接字时会动态分配出站端口,它们来自与通常用于侦听传入请求的端口范围不同的端口范围。

If the request is originating from a cooperating server, then you can ask it to set a custom header that indicates what port it is running on for incoming requests, but if it's not a cooperating server, there is no way for you to know what port is listens for incoming requests or if even it is a server at all.如果请求来自合作服务器,那么您可以要求它设置一个自定义标头,指示它为传入请求在哪个端口上运行,但如果它不是合作服务器,则您无法知道哪个端口是侦听传入的请求,或者它甚至是一个服务器。

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

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