I stumbled across the following warning when I was reading Code Like a Pythonista: Idiomatic Python by David Goodger.
Excerpt from the article ...
print('Hello %(name)s, you have %(messages)i messages' % locals())This is very powerful. With this, you can do all the string formatting you want without having to worry about matching the interpolation values to the template.
But power can be dangerous. "With great power comes great responsibility." If you use the
locals()from with an externally-supplied template string, you expose your entire local namespace to the caller. This is just something to keep in mind.
I am trying to understand the specific scenarios in which using locals() can be dangerous. Any examples of how the presence of locals() in a code can be exploited are appreciated. Thanks!