lambda-proxy
lambda-proxy copied to clipboard
Harden security by not exposing error messages
Currently, any error in a route will get exposed to the caller:
https://github.com/vincentsarago/lambda-proxy/blob/master/lambda_proxy/proxy.py#L697-L705:
try:
response = route_entry.endpoint(**function_kwargs)
except Exception as err:
self.log.error(str(err))
response = (
"ERROR",
"application/json",
json.dumps({"errorMessage": str(err)}),
)
While this is very helpful during development and debugging, it has the potential of giving a malicious actor information the developer did not expect to expose. This issue is to argue for, and track, a feature which makes this behaviour optional and disabled by default.
Possible implementations could be:
- An
APIpropertyroute_exception_handlerwith the signatureException -> Optional[Response]which enables the user to choose how errors are exposed. (defaults to a handler returning an Internal server error message). If the function returns None, it would default to "Internal server error". - An
APIpropertyverbose_error_responses: boolwhich control how errors are returned (Truewould be current implementation,Falsewould be("ERROR", "application/json", '{"errorMessage": "Internal server error"}')