Jul-08-2018, 02:31 AM
I was reading about str.format() and the security vulnerability that exists allowing an attacker access to sensitive information.
This code example is from the linked site:
Do f-strings have the same security vulnerability as
This code example is from the linked site:
>>> # This is our super secret key: >>> SECRET = 'this-is-a-secret' >>> class Error: ... def __init__(self): ... pass >>> # A malicious user can craft a format string that >>> # can read data from the global namespace: >>> user_input = '{error.__init__.__globals__[SECRET]}' >>> # This allows them to exfiltrate sensitive information, >>> # like the secret key: >>> err = Error() >>> user_input.format(error=err) 'this-is-a-secret'The recommendation was to use template strings when ever users have to supply values to the program.
Do f-strings have the same security vulnerability as
str.format()
? What code sample would you write to prove that it is or isn't vulnerable?