Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .codeqlmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"codeql-go/*/ql/src/qlpack.yml",
"codeql-go/*/ql/lib/qlpack.yml",
"*/qlpack.yml",
"*/customizations/qlpack.yml"
"*/customizations/qlpack.yml",
"go/qlpack.yml",
"tests/go-tests/qlpack.yml"
],
"versionPolicies": {
"default": {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
test.ql
test-*.ql
testing/**
*/*.testproj/*
*/test-output.txt
84 changes: 84 additions & 0 deletions go/github/LocalSources.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
private import go

module LocalSources {
private import semmle.go.dataflow.DataFlow
private import semmle.go.dataflow.TaintTracking
private import semmle.go.Scopes

abstract class Range extends DataFlow::Node { }

// ========== Sources ==========

abstract class Sources extends DataFlow::Node { }

// ----------------------------------------------------
// Used for finding Selections or Calls for Go imports
// ----------------------------------------------------

//class UseOfGoImports extends Sources {
//UseOfGoImports () {
//exists ( ValueEntity read,
//DataFlow::Package pkg |
//read.getScope().getEntity(_) = pkg.getScope().getEntity(_)
//and ( this.toString().regexpMatch("selection of.*")
//or this.toString().regexpMatch("call to .*") )
//)
//}
//}

// ----------------------------------------------------

class OsCmd extends LocalSources::Range {
OsCmd() {
exists ( ValueEntity read,
DataFlow::Package pkg |
read.getScope().getEntity(_) = pkg.getScope().getEntity(_)
and this.toString() = "selection of Run"
)
}
}

class OsExec extends LocalSources::Range {
OsExec() {
exists ( ValueEntity read,
DataFlow::Package pkg |
read.getScope().getEntity(_) = pkg.getScope().getEntity(_)
and this.toString() = "selection of Command"
)
}
}

class OsArgs extends LocalSources::Range {
OsArgs() {
exists ( ValueEntity read,
DataFlow::Package pkg |
read.getScope().getEntity(_) = pkg.getScope().getEntity(_)
and this.toString() = "selection of Args"
)
}
}

// Not currently working (need a test case)
//class OsGetenv extends Sources, DataFlow::CallNode {
//OsGetenv() {
//// https://pkg.go.dev/os#Getenv
//this.getTarget().hasQualifiedName(package("os", ""), "Getenv")
//or
//// https://pkg.go.dev/os#Environ
//this.getTarget().hasQualifiedName(package("os", ""), "Environ")
//}
//}

// https://pkg.go.dev/flag
class Flag extends LocalSources::Range {
Flag() {
exists ( ValueEntity read,
DataFlow::Package pkg |
read.getScope().getEntity(_) = pkg.getScope().getEntity(_)
and
( this.toString() = "selection of String"
or this.toString() = "selection of Parse" )
)
}
}
}
2 changes: 1 addition & 1 deletion go/qlpack.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: github-queries-go
version: 0.0.0
version: 0.1.0
libraryPathDependencies: codeql-go
4 changes: 4 additions & 0 deletions tests/go-tests/qlpack.lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies: {}
compiled: false
lockVersion: 1.0.0
10 changes: 10 additions & 0 deletions tests/go-tests/qlpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: github-queries-go-tests
groups: [go, test]
dependencies:
codeql-go: "*"
codeql/go-all: "*"
github-queries-go: "*"
#codeql-queries/go: "*"

extractor: go
tests: .