CookUnity services receive user-controlled text through surfaces such as account forms and delivery instructions. Implement a detector that identifies whether an input string contains any known attack signature.
Use case-insensitive matching. The detector must return True if at least one non-empty signature appears as a contiguous substring of the input, and False otherwise. Matching is literal: do not interpret regular expressions, decode encodings, or remove punctuation.
Implement contains_attack(user_input, attack_signatures).
user_input is a string.attack_signatures is a list of non-empty strings.signature.lower() occurs within user_input.lower().Your solution should efficiently search for many signatures in one input. Aim for time proportional to the input length, the total signature length, and the output construction cost, rather than rescanning the input independently for every signature.
def contains_attack(user_input, attack_signatures):