diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
index 8260fa9f30b952048ed8961bbb76a62204334b98_bWVyY3VyaWFsL2Jvb2ttYXJrcy5weQ==..d1c13a4dc638cefc71728da24f91a723313b049e_bWVyY3VyaWFsL2Jvb2ttYXJrcy5weQ== 100644
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -183,5 +183,6 @@
     marks = getattr(repo, '_bookmarks', {})
 
     d = {}
+    hasnode = repo.changelog.hasnode
     for k, v in marks.iteritems():
         # don't expose local divergent bookmarks
@@ -186,6 +187,6 @@
     for k, v in marks.iteritems():
         # don't expose local divergent bookmarks
-        if '@' not in k or k.endswith('@'):
+        if hasnode(v) and ('@' not in k or k.endswith('@')):
             d[k] = hex(v)
     return d
 
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
index 8260fa9f30b952048ed8961bbb76a62204334b98_dGVzdHMvdGVzdC1oZ3dlYi1jb21tYW5kcy50..d1c13a4dc638cefc71728da24f91a723313b049e_dGVzdHMvdGVzdC1oZ3dlYi1jb21tYW5kcy50 100644
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1386,4 +1386,10 @@
   $ QUERY_STRING='style=raw'
   $ python hgweb.cgi
 
+listbookmarks hides secret bookmarks
+
+  $ PATH_INFO=/; export PATH_INFO
+  $ QUERY_STRING='cmd=listkeys&namespace=bookmarks'
+  $ python hgweb.cgi
+
   $ cd ..