Skip to content

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

@taus-semmle

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 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.

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.

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.

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.

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.

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.

Why declaredAttribute rather than the more usual lookupAttribute?

@felicitymay 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.

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.

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.

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. "

@taus-semmle

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

felicitymay commented Mar 20, 2019

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.

Please remove the period from the name.

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