Skip to content

Commit

Permalink
Reset cache function
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Feys committed Aug 21, 2024
1 parent 92fd72e commit 8ccd5f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aikido_firewall/helpers/extract_strings_from_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


def extract_strings_from_user_input_cached(obj, source):
"""Use the cache to speed up getting user input"""
context = get_current_context()
if context.parsed_userinput and context.parsed_userinput.get(source):
return context.parsed_userinput.get(source)
Expand All @@ -18,6 +19,13 @@ def extract_strings_from_user_input_cached(obj, source):
return res


def reset_userinput_cache_for_given_source(source):
"""Resets cache for the given source"""
context = get_current_context()
if context.parsed_userinput and context.parsed_userinput.get(source):
context.parsed_userinput[source] = None # Empty cache


def extract_strings_from_user_input(obj, path_to_payload=None):
"""
Extracts strings from an object (user input)
Expand Down
6 changes: 6 additions & 0 deletions aikido_firewall/sources/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
import copy
import importhook
from aikido_firewall.helpers.logging import logger
from aikido_firewall.helpers.extract_strings_from_user_input import (
reset_userinput_cache_for_given_source,
)
from aikido_firewall.context import get_current_context


def process_xml(user_input, root_element):
"""Extracts all attributes from the xml and adds them to context"""
extracted_xml_attrs = []
for el in root_element:
extracted_xml_attrs += el.items()
context = get_current_context()
reset_userinput_cache_for_given_source("xml")
context.xml += extracted_xml_attrs


Expand All @@ -25,6 +30,7 @@ def on_xml_import(eltree):
"""
modified_eltree = importhook.copy_module(eltree)
copy_xml_parser = copy.deepcopy(eltree.XMLParser)

class MutableAikidoXMLParser:
"""Aikido's mutable connection class"""

Expand Down

0 comments on commit 8ccd5f4

Please sign in to comment.