Sanitize selected function arguments by replacing MongoDB operators.
pip install mongo_secure
from mongo_secure import sanitize
@sanitize("name", "place")
def hello_world(name, place):
print(name)
print(place)
hello_world("$toInt", "$gt")
#<= _toInt
#<= _gtNested objects are sanitized recursively
from mongo_secure import replace_blocked_mongo_operators
payload = {
"$set": {
"age": "$toInt",
"tags": ["safe", "$where"]
}
}
print(replace_blocked_mongo_operators(payload))
#<= {"_set": {"age": "_toInt", "tags": ["safe", "_where"]}}MIT