can't use getattr to get method

This commit is contained in:
Faraphel 2022-08-20 11:21:05 +02:00
parent 056088f035
commit 601342ab20
3 changed files with 7 additions and 3 deletions

View file

@ -100,6 +100,7 @@
"SAFE_EVAL_ERROR": "Safe eval error",
"TEMPLATE_USED": "Template used",
"MORE_IN_ERROR_LOG": "More information in the error.log file",
"COPY_FUNCTION_FORBIDDEN": "Copying functions is forbidden"
"COPY_FUNCTION_FORBIDDEN": "Copying functions is forbidden",
"GET_METHOD_FORBIDDEN": "Using getattr on a method is forbidden"
}
}

View file

@ -101,6 +101,7 @@
"SAFE_EVAL_ERROR": "Erreur lors d'un safe eval",
"TEMPLATE_USED": "Modèle utilisé",
"MORE_IN_ERROR_LOG": "Plus d'information dans le fichier error.log",
"COPY_FUNCTION_FORBIDDEN": "Impossible de copier une fonction"
"COPY_FUNCTION_FORBIDDEN": "Impossible de copier une fonction",
"GET_METHOD_FORBIDDEN": "Impossible d'utiliser getattr sur une méthode"
}
}

View file

@ -37,7 +37,9 @@ class safe_function:
Same as normal getattr, but magic attribute are banned
"""
if "__" in name: raise Exception(_("MAGIC_METHOD_FORBIDDEN", ' : "', name, '"'))
return getattr(obj, name, default)
attr = getattr(obj, name, default)
if callable(attr): raise Exception(_("GET_METHOD_FORBIDDEN", ' : "', name, '"'))
return attr
@staticmethod
def type(obj: any):