langchain
                                
                                 langchain copied to clipboard
                                
                                    langchain copied to clipboard
                            
                            
                            
                        Patch LLMMathChain exec vulnerability
As referenced in other issues (see #814, #1026), the current implementation of LLMMathChain allows for prompt injection attacks which can execute arbitrary code using Python's exec method. As a quick patch, I have modified the chain to use the slightly safer eval method and modified the prompt template accordingly. From my quick testing, this doesn't seem to hurt the chain's mathematical ability and prevents the exploit outlined in #814.
NB: This is intended as a quick patch to mitigate the current security risks. Future developments, as in #1055, should further help with solving this vulnerability and others.
Here's another attempt using RestrictedPython:
https://github.com/hwchase17/langchain/pull/1134
Please review and let me know what you think.
stale, using numexpr now
using numexpr now