You can prevent spoofing connections from an external server purporting to be the standby server by using authentication with a user name and password.
Configure the setting in the primary server pg_hba.conf file so that authentication is performed for connections from the standby server in the same way as for connections from the client.
See
Refer to "Client Authentication" in the PostgreSQL Documentation for information on content that can be configured in pg_hba.conf.