fix: drop method-related code from whitelist (#33225)
This commit is contained in:
parent
3a6a2277c8
commit
56b7786599
1 changed files with 13 additions and 12 deletions
|
|
@ -620,6 +620,16 @@ xss_safe_methods: set[Callable] = set()
|
|||
allowed_http_methods_for_whitelisted_func: dict[Callable, list[str]] = {}
|
||||
|
||||
|
||||
def _in_request_or_test():
|
||||
"""
|
||||
Internal
|
||||
|
||||
Used by whitelist to determine whether type hints should be validated or not
|
||||
"""
|
||||
|
||||
return getattr(local, "request", None) or in_test
|
||||
|
||||
|
||||
def whitelist(allow_guest=False, xss_safe=False, methods=None):
|
||||
"""
|
||||
Decorator for whitelisting a function and making it accessible via HTTP.
|
||||
|
|
@ -643,17 +653,8 @@ def whitelist(allow_guest=False, xss_safe=False, methods=None):
|
|||
|
||||
global whitelisted, guest_methods, xss_safe_methods, allowed_http_methods_for_whitelisted_func
|
||||
|
||||
# validate argument types only if request is present
|
||||
in_request_or_test = lambda: getattr(local, "request", None) or in_test # noqa: E731
|
||||
|
||||
# get function from the unbound / bound method
|
||||
# this is needed because functions can be compared, but not methods
|
||||
method = None
|
||||
if hasattr(fn, "__func__"):
|
||||
method = validate_argument_types(fn, apply_condition=in_request_or_test)
|
||||
fn = method.__func__
|
||||
else:
|
||||
fn = validate_argument_types(fn, apply_condition=in_request_or_test)
|
||||
# validate argument types if request is present or in test context
|
||||
fn = validate_argument_types(fn, apply_condition=_in_request_or_test)
|
||||
|
||||
whitelisted.add(fn)
|
||||
allowed_http_methods_for_whitelisted_func[fn] = methods
|
||||
|
|
@ -664,7 +665,7 @@ def whitelist(allow_guest=False, xss_safe=False, methods=None):
|
|||
if xss_safe:
|
||||
xss_safe_methods.add(fn)
|
||||
|
||||
return method or fn
|
||||
return fn
|
||||
|
||||
return innerfn
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue