Skip to content

New query to check for making a request without cert verification. #530

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

Merged
merged 6 commits into from
Nov 27, 2018

Conversation

markshannon
Copy link
Contributor

Checks for calls of the form request.{http_verb}(verify=False)

@markshannon markshannon force-pushed the python-no-cert-validation branch from 3c98434 to bfc001c Compare November 23, 2018 14:48
Copy link
Contributor

@felicitymay felicitymay left a comment

Choose a reason for hiding this comment

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

Some comments on the text. For some reason, this PR hasn't triggered a qhelp preview.

@@ -57,6 +57,7 @@ A new predicate `Stmt.getAnEntryNode()` has been added to make it easier to writ
| **Query** | **Tags** | **Purpose** |
|-----------------------------|-----------|--------------------------------------------------------------------|
| Information exposure through an exception (`py/stack-trace-exposure`) | security, external/cwe/cwe-209, external/cwe/cwe-497 | Finds instances where information about an exception may be leaked to an external user. Enabled on LGTM by default. |
| Request Without Certificate Validation (`py/request-without-cert-validation`) | security, external/cwe/cwe-295 | Finds requests where certificate verification has been explicitly turned off, possibly allowing man-in-the-middle attacks. Not enabled on LGTM by default. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change query name to sentence case, that is: "Request without certificate validation".

<overview>
<p>
Encryption is key to the security of most, if not all, online communication.
Using TLS can enusre that neither party in the communication is an interloper.
Copy link
Contributor

Choose a reason for hiding this comment

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

TLS - ? Please include the definition the first time you mention this acronym

<overview>
<p>
Encryption is key to the security of most, if not all, online communication.
Using TLS can enusre that neither party in the communication is an interloper.
Copy link
Contributor

Choose a reason for hiding this comment

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

Using TLS can enusre that neither party in the communication is an interloper.

Firstly: "enusre" is a typo. Secondly, this reads a little strangely. Suggest something like: "Using TLS can ensure that communication cannot be interrupted by an interloper".

Encryption is key to the security of most, if not all, online communication.
Using TLS can enusre that neither party in the communication is an interloper.
For this reason, is is unwise to disable the verification that TLS provides.
<code>requests</code> provides verification by default, and it is only when
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest: "The requests method provides verification by default. To disable TLS verification you have to explicitly turn it off using verify=False." - assuming that requests is a method. It should read better and avoids starting a sentence with lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

requests is a module containing several functions, all of which have the optional verify parameter.

<references>
<li>
Common Weakness Enumeration:
<a href="https://cwe.mitre.org/data/definitions/295.html">CWE-295: Improper Certificate Validation</a>.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please delete this reference. While this is better than the autogenerated reference, it will result in duplication in the query help output.

@@ -0,0 +1,36 @@
/**
* @name Request Without Certificate Validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this to sentence case.


<example>
<p>
The example shows two unsafe calls to <a href="https://semmle.com">semmle.com</a>, followed by various safe alternatives.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this text also cover the wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The code should be self explanatory.

@felicitymay
Copy link
Contributor

Is this intended for 1.19?

@markshannon markshannon changed the base branch from next to rc/1.19 November 27, 2018 11:33
@markshannon
Copy link
Contributor Author

Comments addressed and re-targeted at rc/1.19

@felicitymay
Copy link
Contributor

Thanks for the text changes. Content all LGTM now.

Copy link
Contributor

@taus-semmle taus-semmle left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise LGTM.

exists(ModuleObject req |
req.getName() = "requests" and
result = req.getAttribute(httpVerbLower())
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be written a bit shorter as result = any(ModuleObject req | req.getName() = "requests").getAttribute(httpVerbLower()).

We should consider extending the library to have an easier way of expressing the any(ModuleObject m | m.getName() = "foo") idiom, as it is quite common. Perhaps we could add a NamedModule subclass of ModuleObject that accepts a string name in its characteristic predicate, and adds this.getName() = name as a constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #554

@taus-semmle
Copy link
Contributor

Oh, we should move dashboard-configs/internal/lgtm/python2-alerts-lgtm and its ilk into this repo. Otherwise, we'll have to create internal PRs to keep that file synchronised.

See https://git.semmle.com/Semmle/code/pull/28942

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.

3 participants