FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python: Add query for insecure SSH host key policies in Paramiko. by taus-semmle · Pull Request #1128 · github/codeql · GitHub

/ codeql Public

Python: Add query for insecure SSH host key policies in Paramiko. - #1128

Merged
markshannon merged 4 commits into
github:masterfrom
tausbn:python-paramiko-unsafe-host-key-validation
Apr 4, 2019
Merged

Python: Add query for insecure SSH host key policies in Paramiko.#1128
markshannon merged 4 commits into
github:masterfrom
tausbn:python-paramiko-unsafe-host-key-validation

Conversation

Copy link
Copy Markdown
Contributor

Adds a query that looks for instances where the host key policy is set to AutoAddPolicy or WarningPolicy both of which are insecure, as they do not terminate the connection when the host key is unknown.

@felicity-semmle for the documentation.

markshannon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A few issues

* @kind problem
* @problem.severity error
* @precision high
* @id py/missing-host-key-validation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Add "paramiko" to the id, and the description. And maybe the name if not too cumbersome.


# ... interaction with server

client.close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should have a "good" example as well, and encapsulate them in functions, so it is clear which is which.


client = SSHClient()

client.set_missing_host_key_policy(AutoAddPolicy) # bad

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can we add test for instances as well client.set_missing_host_key_policy(AutoAddPolicy())

result = theParamikoClientModule().attr("SSHClient")
}

private ClassObject unsafe_paramiko_policy(string name) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

According to the docs, instances of these classes are usable as well.

from CallNode call, string name
where
call = theParamikoSSHClientClass()
.declaredAttribute("set_missing_host_key_policy")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why declaredAttribute rather than the more usual lookupAttribute?

felicitymay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is a new query and so needs a change note. A small text suggestion, otherwise LGTM. Thanks for pinging me.

@@ -0,0 +1,32 @@
/**
* @name Accepting unknown host keys.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

By convention we don't use period to complete the @name field.

setting the missing host key policy to either <code>AutoAddPolicy</code> or
<code>WarningPolicy</code>, as both of these will continue even when the host
key is unknown. The default <code>RejectPolicy</code> throws an exception when
unknown host keys are encountered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Suggest something more like this?

"Do not accept unknown host keys. In particular, do not set the default missing host key policy for the Paramiko library to either AutoAddPolicy or WarningPolicy. Both of these policies continue even when the host key is unknown. The default setting of RejectPolicy is secure because it throws an exception when it encounters an unknown host key. "

Copy link
Copy Markdown
Contributor Author

Thank you both for your comments. I believe I have addressed them all in the commits I pushed just now.

felicitymay commented Mar 20, 2019
edited
Loading

Copy link
Copy Markdown
Contributor

Thanks for the changes to the help topic. This still needs a change note, but otherwise looks good to me.

@taus-semmle rightly points out that I'd somehow missed spotting the change note. One minor point otherwise text LGTM.

Comment thread change-notes/1.21/analysis-python.md Outdated
## New queries
| **Query** | **Tags** | **Purpose** |
|-----------|----------|-------------|
| Accepting unknown SSH host keys when using Paramiko. (`py/paramiko-missing-host-key-validation`) | security, external/cwe/cwe-295 | Finds instances where Paramiko is configured to accept unknown host keys. Results are shown on LGTM by default. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please remove the period from the name.

taus-semmle requested a review from markshannon April 4, 2019 15:09
markshannon merged commit 2ba1223 into github:master Apr 4, 2019
tausbn deleted the python-paramiko-unsafe-host-key-validation branch February 12, 2021 18:06
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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL