Skip to content

Security: Unsafe use of exec() in version parsing#310

Open
tuanaiseo wants to merge 1 commit into
google-deepmind:v2from
tuanaiseo:contribai/fix/security/unsafe-use-of-exec-in-version-parsing
Open

Security: Unsafe use of exec() in version parsing#310
tuanaiseo wants to merge 1 commit into
google-deepmind:v2from
tuanaiseo:contribai/fix/security/unsafe-use-of-exec-in-version-parsing

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

The _get_sonnet_version() function in setup.py uses exec() to parse the version from sonnet/init.py. While currently reading from a controlled file, this pattern is dangerous as it could execute arbitrary code if the file is tampered with or if the function is repurposed to read user-controlled input.

Severity: medium
File: setup.py

Solution

Replace exec() with a safer alternative such as regex extraction or ast.parse(). Example: re.search(r'version\s*=\s*"'["']', content).group(1)

Changes

  • setup.py (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

The _get_sonnet_version() function in setup.py uses exec() to parse the __version__ from sonnet/__init__.py. While currently reading from a controlled file, this pattern is dangerous as it could execute arbitrary code if the file is tampered with or if the function is repurposed to read user-controlled input.

Affected files: setup.py

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 6, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant