Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import contacts via SFTP #765

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Import contacts via SFTP #765

wants to merge 11 commits into from

Conversation

alanzirek
Copy link
Collaborator

@alanzirek alanzirek commented Feb 27, 2025

WIP

@alanzirek alanzirek force-pushed the import-contacts-sftp branch from 3bef987 to 3a0f45d Compare February 27, 2025 17:34
@alanzirek alanzirek force-pushed the import-contacts-sftp branch from 67ec57b to 5799cd3 Compare February 28, 2025 12:55
@alanzirek alanzirek force-pushed the import-contacts-sftp branch from 060ad2a to 26b50ea Compare February 28, 2025 15:41
@alanzirek alanzirek force-pushed the import-contacts-sftp branch from 26b50ea to fb866ef Compare February 28, 2025 15:42

# Récupère et ajoute le fingerprint du serveur SFTP à la liste des fingerprints autorisés
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

Check failure

Code scanning / CodeQL

Accepting unknown SSH host keys when using Paramiko High test

Setting missing host key policy to AutoAddPolicy may be unsafe.

Copilot Autofix AI about 1 hour ago

To fix the problem, we should replace the use of AutoAddPolicy with RejectPolicy. This ensures that the SSH client will only connect to hosts with known and verified keys, maintaining the security of the connection.

We need to modify the code in core/tests/test_fetch_export_agricoll_contacts_file.py to use RejectPolicy instead of AutoAddPolicy. Additionally, we should ensure that the host key is added to the known hosts list before attempting to connect. This can be done by manually adding the host key to the SSHClient object.

Suggested changeset 1
core/tests/test_fetch_export_agricoll_contacts_file.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/tests/test_fetch_export_agricoll_contacts_file.py b/core/tests/test_fetch_export_agricoll_contacts_file.py
--- a/core/tests/test_fetch_export_agricoll_contacts_file.py
+++ b/core/tests/test_fetch_export_agricoll_contacts_file.py
@@ -17,5 +17,7 @@
         client = paramiko.SSHClient()
-        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+        client.set_missing_host_key_policy(paramiko.RejectPolicy())
+        client.load_system_host_keys()
         client.connect(settings.SFTP_HOST, settings.SFTP_PORT, settings.SFTP_USERNAME, settings.SFTP_PASSWORD)
         fingerprint = client.get_transport().get_remote_server_key().fingerprint
+        client.get_host_keys().add(settings.SFTP_HOST, client.get_transport().get_remote_server_key().get_name(), client.get_transport().get_remote_server_key())
         original_fingerprints = CleverCloudSftpVerifier.CLEVER_CLOUD_FINGERPRINTS.copy()
EOF
@@ -17,5 +17,7 @@
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.set_missing_host_key_policy(paramiko.RejectPolicy())
client.load_system_host_keys()
client.connect(settings.SFTP_HOST, settings.SFTP_PORT, settings.SFTP_USERNAME, settings.SFTP_PASSWORD)
fingerprint = client.get_transport().get_remote_server_key().fingerprint
client.get_host_keys().add(settings.SFTP_HOST, client.get_transport().get_remote_server_key().get_name(), client.get_transport().get_remote_server_key())
original_fingerprints = CleverCloudSftpVerifier.CLEVER_CLOUD_FINGERPRINTS.copy()
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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