Skip to content

Tracking pull request to merge release-1.32.0 to main#796

Open
kuanfandevops wants to merge 5 commits intomainfrom
release-1.32.0
Open

Tracking pull request to merge release-1.32.0 to main#796
kuanfandevops wants to merge 5 commits intomainfrom
release-1.32.0

Conversation

@kuanfandevops
Copy link
Collaborator

No description provided.

@sonarqubecloud
Copy link

* sftp automation

* some fixes and changes
@sonarqubecloud
Copy link

pkey_file = get_minio_object(settings.SSH_PKEY_FILENAME)
pkey = paramiko.RSAKey.from_private_key(io.StringIO(pkey_file.data.decode("utf-8")))
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

Setting missing host key policy to AutoAddPolicy may be unsafe.

Copilot Autofix

AI 5 months ago

To fix this issue, you should change the missing host key policy in the get_ssh_client() function from paramiko.AutoAddPolicy to paramiko.RejectPolicy. The RejectPolicy will refuse connection if the host key is not present in the known hosts file, ensuring host authenticity and protecting against man-in-the-middle exploits. This fix should be implemented by changing line 157 in django/api/services/cra.py so that it reads client.set_missing_host_key_policy(paramiko.RejectPolicy).

If this change causes exceptions upon connecting to new servers, you'll need to ensure that host keys are preloaded into the system's known hosts (or manually added via Paramiko's load_system_host_keys or load_host_keys methods). However, based solely on the code provided, only the policy line needs to be updated.

Suggested changeset 1
django/api/services/cra.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/django/api/services/cra.py b/django/api/services/cra.py
--- a/django/api/services/cra.py
+++ b/django/api/services/cra.py
@@ -154,7 +154,7 @@
     pkey_file = get_minio_object(settings.SSH_PKEY_FILENAME)
     pkey = paramiko.RSAKey.from_private_key(io.StringIO(pkey_file.data.decode("utf-8")))
     client = paramiko.SSHClient()
-    client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
+    client.set_missing_host_key_policy(paramiko.RejectPolicy)
     client.connect(
         settings.CRA_SFTP_HOST,
         port=int(settings.CRA_SFTP_PORT),
EOF
@@ -154,7 +154,7 @@
pkey_file = get_minio_object(settings.SSH_PKEY_FILENAME)
pkey = paramiko.RSAKey.from_private_key(io.StringIO(pkey_file.data.decode("utf-8")))
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
client.set_missing_host_key_policy(paramiko.RejectPolicy)
client.connect(
settings.CRA_SFTP_HOST,
port=int(settings.CRA_SFTP_PORT),
Copilot is powered by AI and may make mistakes. Always verify output.
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.

2 participants