The Wayback Machine - https://web.archive.org/web/20250521185337/https://github.com/github/codeql-go/pull/166
Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Add some queries for commonly-used third-part libraries #166

Closed
wants to merge 1 commit into from

Conversation

RicterZ
Copy link
Contributor

@RicterZ RicterZ commented Jun 9, 2020

Hi, I add some queries for commonly-used third-part libraries:

  • github.com/emicklei/go-restfu
  • github.com/jinzhu/gorm
  • github.com/jmoiron/sqlx
  • github.com/json-iterator/go

@RicterZ RicterZ changed the title add some sinks in commonly-used SQL libraries Add some queries for commonly-used third-part libraries Jun 9, 2020
Copy link
Contributor

@max-schaefer max-schaefer left a comment

Choose a reason for hiding this comment

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

Many thanks for your contribution, we really appreciate it!

I have a few initial thoughts below.

Since this is a contribution to the standard library, we need to hold it to a higher standard than an experimental contribution. In particular, it would be great if you could add tests for all the new APIs you added support for. @sauyon can help with stubbing out dependencies, you can take a look at a few recent PRs to see how this works.

Also, can you make sure that all your code is auto-formatted?

@@ -0,0 +1,25 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this to frameworks/Encoding.qll, please? No nee for the "thirdpartlib" bit.

@@ -0,0 +1,25 @@
/**
* Provides classes modeling security-relevant aspects of the third-part libraries.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is too generic; can you make it a little more specific?


import go

module ThirdPartEncodingJson {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to wrap this into a module, I think.


module ThirdPartEncodingJson {
/** Provides models of some functions in the `github.com/json-iterator/go` package. */
class JsoniterUnmarshalingFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class JsoniterUnmarshalingFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
private class JsoniterUnmarshalingFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {

import go

module ThirdPartEncodingJson {
/** Provides models of some functions in the `github.com/json-iterator/go` package. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, a more specific comment would be better, since this models one particular function.

* Source from go-resultful
* Document: https://github.com/emicklei/go-restful
*/
class GoRestfulSource extends DataFlow::Node, UntrustedFlowSource::Range {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest making this class private and moving it into go/frameworks/HTTP.qll.

exists(
Method meth, string name |
meth.hasQualifiedName("github.com/emicklei/go-restful", "Request", name) and
asExpr() = meth.getACall().asExpr() and
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
asExpr() = meth.getACall().asExpr() and
this = meth.getACall() and

GoRestfulSource() {
exists(
Method meth, string name |
meth.hasQualifiedName("github.com/emicklei/go-restful", "Request", name) and
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the new(-ish) [...] syntax for this:

Suggested change
meth.hasQualifiedName("github.com/emicklei/go-restful", "Request", name) and
meth.hasQualifiedName(package("github.com/emicklei/go-restful", ""), "Request", [
"QueryParameters", "QueryParameter",
"BodyParameter", "HeaderParameter",
"PathParameters", "PathParameter"
]) and

(Note also the use of the package helper predicate; go-restful seems to use semantic import versioning.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for hijacking this.
Is there a "coding style" for set literals?
Is it ok to use them in functions like this hasQualifiedName(_, ["foo", "bar", "foobar"]) (1)
or should one rather use something like this instead (2)

exists(string name | name in ["foo", "bar", "foobar"] | hasQualifiedName(_, name))

If one already knows set literals (1) is probably understandable, but if I didn't know them I'd probably find that confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't, both alternatives are fine.

@@ -0,0 +1,48 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please make these classes private and move them into go.frameworks.SQL?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same suggestions regarding code style as with GoRestfulSource above.

@max-schaefer
Copy link
Contributor

Superseded by #270.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.