Potential fix for code scanning alert no. 9: Use of insecure SSL/TLS version #6
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.
Potential fix for https://github.com/sredevopsorg/copyparty/security/code-scanning/9
To remediate the issue, we must ensure that insecure protocols such as TLSv1.0 and TLSv1.1 are not allowed, by explicitly setting the minimum accepted protocol in the SSL context to TLSv1.2 or higher. This entails, after creating the SSL context on line 168, adding code to set
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
(for Python >=3.7), or, for earlier Python versions, disabling them via context options:ctx.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
. Since we don't know the Python version at runtime, we should add a version check. The best way is to set the minimum version for modern Python, and fall back to disabling protocols via context options for old Python.This change should be done right after context creation (line 168), to ensure all connections use only secure protocol versions. We need to add
import sys
if not already present for the version check. The fix must be implemented within the scope shown, so all edits should be within copyparty/httpconn.py. No functional changes to the rest of the code are required.Suggested fixes powered by Copilot Autofix. Review carefully before merging.