diff --git a/mercurial/hg.py b/mercurial/hg.py
index a2a380e2750fdd0406cc23a0ca8c8d3eee4d0e63_bWVyY3VyaWFsL2hnLnB5..3fde328d0913c4a0d88718ede1abf785bc460479_bWVyY3VyaWFsL2hnLnB5 100644
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -923,7 +923,7 @@
         dst.setconfig('bundle', 'mainreporoot', r, 'copied')
 
     # copy selected local settings to the remote ui
-    for sect in ('auth', 'hostfingerprints', 'http_proxy'):
+    for sect in ('auth', 'hostfingerprints', 'hostsecurity', 'http_proxy'):
         for key, val in src.configitems(sect):
             dst.setconfig(sect, key, val, 'copied')
     v = src.config('web', 'cacerts')
diff --git a/tests/test-https.t b/tests/test-https.t
index a2a380e2750fdd0406cc23a0ca8c8d3eee4d0e63_dGVzdHMvdGVzdC1odHRwcy50..3fde328d0913c4a0d88718ede1abf785bc460479_dGVzdHMvdGVzdC1odHRwcy50 100644
--- a/tests/test-https.t
+++ b/tests/test-https.t
@@ -501,6 +501,17 @@
   abort: error: *unsupported protocol* (glob)
   [255]
 
+.hg/hgrc file [hostsecurity] settings are applied to remote ui instances (issue5305)
+
+  $ cat >> copy-pull/.hg/hgrc << EOF
+  > [hostsecurity]
+  > localhost:minimumprotocol=tls1.2
+  > EOF
+  $ P="$CERTSDIR" hg -R copy-pull id https://localhost:$HGPORT/
+  (could not negotiate a common protocol; see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error)
+  abort: error: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:590)
+  [255]
+
   $ killdaemons.py hg0.pid
   $ killdaemons.py hg1.pid
   $ killdaemons.py hg2.pid