Skip to content

Commit 4aaaf67

Browse files
committed
no entropy warning for obfuscated pages
1 parent 305141d commit 4aaaf67

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

encryptcontent/plugin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,8 @@ def on_post_page(self, output_content, page, config, **kwargs):
593593
output_content = str(soup)
594594

595595
if hasattr(page, 'encryptcontent'):
596-
if self.setup['search_plugin_found']:
597-
location = page.url.lstrip('/')
598-
self.setup['locations'][location] = page.encryptcontent['password']
596+
location = page.url.lstrip('/')
597+
self.setup['locations'][location] = [page.encryptcontent['password'], page.encryptcontent.get('obfuscate')]
599598
delattr(page, 'encryptcontent')
600599

601600
return output_content
@@ -622,7 +621,7 @@ def on_post_build(self, config, **kwargs):
622621
for entry in search_entries['docs'].copy(): #iterate through all entries of search_index
623622
for location in self.setup['locations'].keys():
624623
if entry['location'] == location or entry['location'].startswith(location+"#"): #find the ones located at encrypted pages
625-
page_password = self.setup['locations'][location]
624+
page_password = self.setup['locations'][location][0]
626625
if self.config['search_index'] == 'encrypted':
627626
search_entries.remove(entry)
628627
elif self.config['search_index'] == 'dynamically' and page_password is not None:
@@ -658,16 +657,18 @@ def on_post_build(self, config, **kwargs):
658657

659658
passwords = set() #get all unique passwords
660659
for location in self.setup['locations'].keys():
661-
passwords.add(self.setup['locations'][location])
660+
if not self.setup['locations'][location][1]:
661+
passwords.add(self.setup['locations'][location][0])
662+
self.setup['locations'].clear()
662663
min_enttropy_spied_on, min_enttropy_secret = 0, 0
663664
for password in passwords:
664665
enttropy_spied_on, enttropy_secret = self.__get_entropy_from_password__(password)
665666
if min_enttropy_spied_on == 0 or enttropy_spied_on < min_enttropy_spied_on:
666667
min_enttropy_spied_on = enttropy_spied_on
667668
if min_enttropy_secret == 0 or enttropy_secret < min_enttropy_secret:
668669
min_enttropy_secret = enttropy_secret
669-
if min_enttropy_spied_on < 100:
670+
if min_enttropy_spied_on < 100 and min_enttropy_spied_on > 0:
670671
logger.warning('mkdocs-encryptcontent-plugin will always be vulnerable to brute-force attacks!'
671-
' If someone watched you while typing your weakest password only got {spied_on} bits of entropy'
672+
' Your weakest password only got {spied_on} bits of entropy, if someone watched you while typing'
672673
' (and a maximum of {secret} bits total)!'.format(spied_on = math.ceil(enttropy_spied_on), secret = math.ceil(min_enttropy_secret))
673674
)

0 commit comments

Comments
 (0)