Repository navigation
[SYNPY-1942] Fix Security alerts - #1475
Merged
Merged
Conversation
BryanFauble
approved these changes
Nov 3, 2026
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.
Problem:
SonarCloud found three log injection alerts (
pythonsecurity:S5145, alerts fix for syn.store of files with no .path, SYNR-474 #52, Session tokens and .setendpoints method #54, Query chunking, and Logout, Store/Submit #55) insynapseclient/core/version_check.py. The version check writes version strings into log and stdout messages. These strings come from data that the code does not control:synapseclient.__version__)latestVersionin the local package metadatainfo.versionin the PyPI JSON responseThe code only did an
assert isinstance(..., str)on these values. A string such as"1.2.3\nFORGED LOG ENTRY"passes that check and can add a false line to the log. Also,assertstatements are removed when Python runs with-O, so the check did not always run.Some locked dependencies in
Pipfile.lockwere out of date.There are five open HIGH Trivy alerts (msgpack Fix synpy167 #181 and fixed attrubute error for syn.username when not logged in (SYNPY-706) #538, urllib3 fixed comment typo (SYNPY-658) #528 and removed integration test calling POST /entity/{id}/lockAccessRequirement (SYNPY-690) #529, setuptools changed list() function to synlist() as to not overload built-in list() constructor #182). This PR does not change files for these alerts. Refer to the Trivy section below for the reason.
Solution:
_validate_version()toversion_check.py. It accepts a value only if the value is astrand fully matches a known version pattern: release,a/b/rcpre-release,.post, and.devversions (for example4.14.0,4.14.0rc1,4.14.0.post1,0.5.1.dev200). If the value does not match, it raisesValueError. Newline characters and other text cannot get into a log message.check_for_updates(),_version_check(), and_get_version_info_from_pypi()now use_validate_version()instead ofassert isinstance(...).Pipfile.lock: certifi 2026.7.22 → 2026.10.18, setuptools 84.0.0 → 84.1.0, filelock 4.1.1 → 4.2.1, virtualenv 21.14.7 → 21.14.9.Why the Trivy alerts will close without more changes
trivy_periodic_scan.ymlworkflow scans the published image for the latest git tag (nowv4.14.0). TheDockerfileatv4.14.0installspython3-pipandpython3-setuptoolsfrom apt and upgrades pip. pip has its own vendored copies of urllib3 and msgpack, and these copies are the old versions that Trivy finds.setup.cfgalready requiresurllib3>=2.8.0andsetuptools>=80.10.1. The rebuild log shows urllib3 2.8.0 and setuptools 84.2.1 installed for synapseclient.Dockerfileondevelop. It removes the apt Python packages, runsapt-get upgrade, and uninstalls pip after it installs synapseclient. But thatDockerfileis not in a release tag yet.REF_TO_CHECKOUT: <latest tag>). It pushes the image and creates the next patch tag only if the rebuilt image passes Trivy. At the moment, the rebuild uses the oldv4.14.0Dockerfile, so it fails every day and opens an "unresolved container vulnerabilities" issue.Dockerfile. The periodic scan will then scan (or rebuild from) an image that does not have pip. That image will not contain the vulnerable msgpack, urllib3, or setuptools. When the new SARIF upload does not contain these findings, GitHub closes the alerts automatically.Testing:
tests/unit/synapseclient/core/unit_test_version_check.py:test_validate_version_valid: release, pre-release, post-release, and dev versions are returned unchanged.test_validate_version_invalid: empty strings, non-version text, trailing\nor\r\n, leading spaces,1..2, injected log lines,None, and integers raiseValueError.test_get_version_info_from_pypi_invalid: an invalid version from the PyPI response is not returned.test_version_check_invalid_local_metadata: an invalid locallatestVersionis not used.test_check_for_updates_invalid_current_version: an invalid current version raisesValueError, and nothing is written to stdout.