security: replace eval() with getattr() to prevent code injection#610
Open
difcn2026 wants to merge 1 commit into
Open
security: replace eval() with getattr() to prevent code injection#610difcn2026 wants to merge 1 commit into
difcn2026 wants to merge 1 commit into
Conversation
Found by AgentGuard scan (rule PY001). The eval() call with dynamic attribute access could be exploited if the key value is influenced by external input. Replaced with getattr() which is safe and equivalent. Scanned and auto-fixed by AgentGuard + GLM-5.2 https://github.com/difcn2026/agentguardp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix: Replace
eval()withgetattr()to prevent code injectionVulnerability
requests_html.py:570useseval("cookiejar."+key)to dynamically access cookie attributes. Ifkeyis ever influenced by external input, this could allow arbitrary code execution.Fix
Replaced
eval("cookiejar."+key)withgetattr(cookiejar, key, None)— functionally equivalent but safe from code injection.How I Found This
Scanned with AgentGuard (rule PY001 — eval usage), then verified manually.
AgentGuard is an open-source security scanner powered by GLM-5.2 that finds and fixes vulnerabilities automatically.
pip install agentguardpChecklist
getattrwith defaultNone)getattr(cookiejar, key, None)returns same value aseval("cookiejar."+key)for valid keys