Conversation
|
👍 |
|
Hello, thanks for the contribution. The pickle deserialization hardening seems ok. |
|
Hi @snowpeacock, Thank you for the review. As you know, HTML is generated through multiple patterns:
The current fix manually applies Here's what this approach could look like for each pattern : case 1 (e.g, table_class.py) # Before
page_f.write(header_f.read() % (self.id, self.id, self.title, self.id))
# After
template = SafeTemplate.from_file(header_path)
page_f.write(template.render(
id=self.id,
title=self.title,
icon=raw('<i class="bi bi-shield"></i>')
))case 2 (e.g, card_class.py) # Before
page_f.write(html_header % (self.color, self.title, self.icon))
# After
template = SafeTemplate(html_header)
page_f.write(template.render(
raw(self.color),
self.title,
raw(self.icon)
))case 3 (e.g, smolcard_class.py) # Before - custom fillTemplate() method
html_line = self.fillTemplate(html_raw, template_data)
# After
template = SafeTemplate(html_raw)
html_line = template.render(**template_data)case 4 (e.g, grid_class.py) # Before
new_contents = template_contents.replace("// DATA PLACEHOLDER", textToInsert)
# After
template = SafeTemplate(template_contents)
result = template.replace("// DATA PLACEHOLDER", textToInsert)
page_f.write(str(result))case 5 (e.g, controls/*.py) # Before
temp_data["name"] = '<i class="bi bi-server"></i> ' + d["name"]
# After : helper function
temp_data["name"] = icon_label("bi bi-server", d["name"])
# Helper in safe_template.py
def icon_label(icon_class, label):
"""Shortcut for the common icon + label pattern."""
return f'<i class="{icon_class}"></i> {SafeTemplate._escape(label)}'What do you think? Is this the kind of approach you had in mind? |
This PR addresses several minor security vulnerabilities in AD_Miner (cf. #225)
pickle.load()with a restricted unpickler that only allows whitelistedclasses, preventing arbitrary code execution from malicious cache files
script injection through malicious AD object names
Changes
Pickle deserialization hardening:
safe_pickle.pywith RestrictedUnpickler implementing a strict class whitelistcache_class.pyandanalyse_cache.pyto usesafe_load()instead ofpickle.load()analyse_cache.pyXSS prevention:
escape_html()utility function inutils.pygrid_data_stringify()to escape dynamic valuessearch_bar.jsandgraph.jscommon_analysis.py,main_page.py, andtable_class.pyRisk
Without this fix:
(users, computers, groups, domains)