fix(security): 2 improvements across 2 files#312
Open
SlncTrZ wants to merge 2 commits into
Open
Conversation
- Security: Use of `exec` to parse version string in setup.py - Quality: Unused squash operation in DNC read function Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com>
- Security: Use of `exec` to parse version string in setup.py - Quality: Unused squash operation in DNC read function Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Summary
fix(security): 2 improvements across 2 files
Problem
Severity:
Low| File:setup.py:L11The
setup.pyscript usesexec(line, g)to evaluate a line fromsonnet/__init__.pythat defines__version__. This is dangerous because it executes arbitrary Python code from the file. While the file is trusted in normal circumstances, a compromised or maliciously modified__init__.pycould execute arbitrary code during the package installation process. The proper approach is to parse the version string withoutexec(e.g., using regular expressions orast.literal_evalon a well-formed assignment).Solution
Replace
exec(line, g)with a safe parsing method, such asmatch = re.search(r"__version__\s*=\s*['\"]([^'\"]+)['\"]", line); version = match.group(1)to extract the version string without executing code.Changes
setup.py(modified)sonnet/src/nets/dnc/read.py(modified)Testing