Skip to content
Open
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
2 changes: 1 addition & 1 deletion go/ql/src/experimental/CWE-525/WebCacheDeception.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* @name Web Cache Deception
* @description A caching system has been detected on the application and is vulnerable to web cache deception. By manipulating the URL it is possible to force the application to cache pages that are only accessible by an authenticated user. Once cached, these pages can be accessed by an unauthenticated user.
* @kind problem
Expand Down
24 changes: 12 additions & 12 deletions go/ql/test/experimental/CWE-090/LDAPInjection.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,31 @@ func main() {}
// bad is an example of a bad implementation
func (ld *Ldap) bad(req *http.Request) {
// ...
untrusted := req.UserAgent()
untrusted := req.UserAgent() // $ Source[go/ldap-injection]
goldap.NewSearchRequest(
untrusted, // BAD: untrusted dn
untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted dn
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=organizationalPerson))"+untrusted, // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // BAD: untrusted attribute
"(&(objectClass=organizationalPerson))"+untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // $ Alert[go/ldap-injection] // BAD: untrusted attribute
nil,
)
goldapv3.NewSearchRequest(
untrusted, // BAD: untrusted dn
untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted dn
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=organizationalPerson))"+untrusted, // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // BAD: untrusted attribute
"(&(objectClass=organizationalPerson))"+untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // $ Alert[go/ldap-injection] // BAD: untrusted attribute
nil,
)
gopkgldapv2.NewSearchRequest(
untrusted, // BAD: untrusted dn
untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted dn
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=organizationalPerson))"+untrusted, // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // BAD: untrusted attribute
"(&(objectClass=organizationalPerson))"+untrusted, // $ Alert[go/ldap-injection] // BAD: untrusted filter
[]string{"dn", "cn", untrusted}, // $ Alert[go/ldap-injection] // BAD: untrusted attribute
nil,
)
client := &ldapclient.LDAPClient{}
client.Authenticate(untrusted, "123456") // BAD: untrusted filter
client.GetGroupsOfUser(untrusted) // BAD: untrusted filter
client.Authenticate(untrusted, "123456") // $ Alert[go/ldap-injection] // BAD: untrusted filter
client.GetGroupsOfUser(untrusted) // $ Alert[go/ldap-injection] // BAD: untrusted filter
// ...
}

Expand Down
4 changes: 3 additions & 1 deletion go/ql/test/experimental/CWE-090/LDAPInjection.qlref
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
query: experimental/CWE-090/LDAPInjection.ql
postprocess: utils/test/PrettyPrintModels.ql
postprocess:
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql
4 changes: 3 additions & 1 deletion go/ql/test/experimental/CWE-203/Timing.qlref
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
query: experimental/CWE-203/Timing.ql
postprocess: utils/test/PrettyPrintModels.ql
postprocess:
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql
12 changes: 6 additions & 6 deletions go/ql/test/experimental/CWE-203/timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func bad(w http.ResponseWriter, req *http.Request) (interface{}, error) {
secret := "MySuperSecretPasscode"
secretHeader := "X-Secret"

headerSecret := req.Header.Get(secretHeader)
headerSecret := req.Header.Get(secretHeader) // $ Source[go/timing-attack]
secretStr := string(secret)
if len(headerSecret) != 0 && headerSecret != secretStr {
if len(headerSecret) != 0 && headerSecret != secretStr { // $ Alert[go/timing-attack]
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
Expand All @@ -25,9 +25,9 @@ func bad2(w http.ResponseWriter, req *http.Request) (interface{}, error) {
secret := "MySuperSecretPasscode"
secretHeader := "X-Secret"

headerSecret := req.Header.Get(secretHeader)
headerSecret := req.Header.Get(secretHeader) // $ Source[go/timing-attack]
secretStr := string(secret)
if len(headerSecret) != 0 && strings.Compare(headerSecret, secretStr) != 0 {
if len(headerSecret) != 0 && strings.Compare(headerSecret, secretStr) != 0 { // $ Alert[go/timing-attack]
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
Expand All @@ -38,8 +38,8 @@ func bad4(w http.ResponseWriter, req *http.Request) (interface{}, error) {
secret := "MySuperSecretPasscode"
secretHeader := "X-Secret"

headerSecret := req.Header.Get(secretHeader)
if len(secret) != 0 && headerSecret != "SecretStringLiteral" {
headerSecret := req.Header.Get(secretHeader) // $ Source[go/timing-attack]
if len(secret) != 0 && headerSecret != "SecretStringLiteral" { // $ Alert[go/timing-attack]
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
Expand Down
3 changes: 2 additions & 1 deletion go/ql/test/experimental/CWE-285/PamAuthBypass.qlref
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
experimental/CWE-285/PamAuthBypass.ql
query: experimental/CWE-285/PamAuthBypass.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
2 changes: 1 addition & 1 deletion go/ql/test/experimental/CWE-285/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func bad() error {
t, _ := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) {
return "", nil
})
}) // $ Alert
return t.Authenticate(0)

}
Expand Down
8 changes: 4 additions & 4 deletions go/ql/test/experimental/CWE-287/ImproperLdapAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func bad(w http.ResponseWriter, req *http.Request) (interface{}, error) {
ldapServer := "ldap.example.com"
ldapPort := 389
bindDN := "cn=admin,dc=example,dc=com"
bindPassword := req.URL.Query()["password"][0]
bindPassword := req.URL.Query()["password"][0] // $ Source[go/improper-ldap-auth]

// Connect to the LDAP server
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
Expand All @@ -25,7 +25,7 @@ func bad(w http.ResponseWriter, req *http.Request) (interface{}, error) {
defer l.Close()

// BAD: user input is not sanetized
err = l.Bind(bindDN, bindPassword)
err = l.Bind(bindDN, bindPassword) // $ Alert[go/improper-ldap-auth]
if err != nil {
return fmt.Errorf("LDAP bind failed: %v", err), err
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func bad2(req *http.Request) {
ldapPort := 389
bindDN := "cn=admin,dc=example,dc=com"
// BAD : empty password
bindPassword := ""
bindPassword := "" // $ Source[go/improper-ldap-auth]

// Connect to the LDAP server
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
Expand All @@ -94,7 +94,7 @@ func bad2(req *http.Request) {
defer l.Close()

// BAD : bindPassword is empty
err = l.Bind(bindDN, bindPassword)
err = l.Bind(bindDN, bindPassword) // $ Alert[go/improper-ldap-auth]
if err != nil {
log.Fatalf("LDAP bind failed: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion go/ql/test/experimental/CWE-287/ImproperLdapAuth.qlref
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
query: experimental/CWE-287/ImproperLdapAuth.ql
postprocess: utils/test/PrettyPrintModels.ql
postprocess:
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql
6 changes: 3 additions & 3 deletions go/ql/test/experimental/CWE-321-V2/HardCodedKeys.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#select
| go-jose.v3.go:24:32:24:37 | JwtKey | go-jose.v3.go:13:21:13:33 | "AllYourBase" | go-jose.v3.go:24:32:24:37 | JwtKey | This $@. | go-jose.v3.go:13:21:13:33 | "AllYourBase" | Constant Key is used as JWT Secret key |
| golang-jwt-v5.go:27:9:27:15 | JwtKey1 | golang-jwt-v5.go:19:22:19:34 | "AllYourBase" | golang-jwt-v5.go:27:9:27:15 | JwtKey1 | This $@. | golang-jwt-v5.go:19:22:19:34 | "AllYourBase" | Constant Key is used as JWT Secret key |
edges
| go-jose.v3.go:13:14:13:34 | type conversion | go-jose.v3.go:24:32:24:37 | JwtKey | provenance | |
| go-jose.v3.go:13:21:13:33 | "AllYourBase" | go-jose.v3.go:13:14:13:34 | type conversion | provenance | |
Expand All @@ -11,6 +14,3 @@ nodes
| golang-jwt-v5.go:19:22:19:34 | "AllYourBase" | semmle.label | "AllYourBase" |
| golang-jwt-v5.go:27:9:27:15 | JwtKey1 | semmle.label | JwtKey1 |
subpaths
#select
| go-jose.v3.go:24:32:24:37 | JwtKey | go-jose.v3.go:13:21:13:33 | "AllYourBase" | go-jose.v3.go:24:32:24:37 | JwtKey | This $@. | go-jose.v3.go:13:21:13:33 | "AllYourBase" | Constant Key is used as JWT Secret key |
| golang-jwt-v5.go:27:9:27:15 | JwtKey1 | golang-jwt-v5.go:19:22:19:34 | "AllYourBase" | golang-jwt-v5.go:27:9:27:15 | JwtKey1 | This $@. | golang-jwt-v5.go:19:22:19:34 | "AllYourBase" | Constant Key is used as JWT Secret key |
3 changes: 2 additions & 1 deletion go/ql/test/experimental/CWE-321-V2/HardCodedKeys.qlref
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
experimental/CWE-321-V2/HardCodedKeys.ql
query: experimental/CWE-321-V2/HardCodedKeys.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
4 changes: 2 additions & 2 deletions go/ql/test/experimental/CWE-321-V2/go-jose.v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// NOT OK
var JwtKey = []byte("AllYourBase")
var JwtKey = []byte("AllYourBase") // $ Source

func main2(r *http.Request) {
signedToken := r.URL.Query().Get("signedToken")
Expand All @@ -21,7 +21,7 @@ func verifyJWT(signedToken string) {
fmt.Println("verifying JWT")
DecodedToken, _ := jwt.ParseSigned(signedToken)
out := CustomerInfo{}
if err := DecodedToken.Claims(JwtKey, &out); err != nil {
if err := DecodedToken.Claims(JwtKey, &out); err != nil { // $ Alert
panic(err)
}
fmt.Printf("%v\n", out)
Expand Down
4 changes: 2 additions & 2 deletions go/ql/test/experimental/CWE-321-V2/golang-jwt-v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type CustomerInfo struct {
}

// BAD constant key
var JwtKey1 = []byte("AllYourBase")
var JwtKey1 = []byte("AllYourBase") // $ Source

func main1(r *http.Request) {
signedToken := r.URL.Query().Get("signedToken")
verifyJWT_golangjwt(signedToken)
}

func LoadJwtKey(token *jwt.Token) (interface{}, error) {
return JwtKey1, nil
return JwtKey1, nil // $ Alert
}

func verifyJWT_golangjwt(signedToken string) {
Expand Down
24 changes: 12 additions & 12 deletions go/ql/test/experimental/CWE-369/DivideByZero.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ import (
)

func myHandler1(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value, _ := strconv.Atoi(param1)
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}

func myHandler2(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value := int(param1[0])
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}

func myHandler3(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value, _ := strconv.ParseInt(param1, 10, 64)
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}

func myHandler4(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value, _ := strconv.ParseFloat(param1, 32)
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}

func myHandler5(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value, _ := strconv.ParseUint(param1, 10, 64)
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}

Expand All @@ -51,10 +51,10 @@ func myHandler6(w http.ResponseWriter, r *http.Request) {
}

func myHandler7(w http.ResponseWriter, r *http.Request) {
param1 := r.URL.Query()["param1"][0]
param1 := r.URL.Query()["param1"][0] // $ Source[go/divide-by-zero]
value := int(param1[0])
if value >= 0 {
out := 1337 / value
out := 1337 / value // $ Alert[go/divide-by-zero]
fmt.Println(out)
}
}
Expand Down
4 changes: 3 additions & 1 deletion go/ql/test/experimental/CWE-369/DivideByZero.qlref
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
query: experimental/CWE-369/DivideByZero.ql
postprocess: utils/test/PrettyPrintModels.ql
postprocess:
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql
8 changes: 4 additions & 4 deletions go/ql/test/experimental/CWE-400/DatabaseCallInLoop.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#select
| DatabaseCallInLoop.go:9:3:9:41 | call to First | DatabaseCallInLoop.go:7:2:11:2 | range statement | DatabaseCallInLoop.go:9:3:9:41 | call to First | This calls call to First in a $@. | DatabaseCallInLoop.go:7:2:11:2 | range statement | loop |
| test.go:11:2:11:13 | call to Take | test.go:20:2:22:2 | for statement | test.go:11:2:11:13 | call to Take | This calls call to Take in a $@. | test.go:20:2:22:2 | for statement | loop |
| test.go:11:2:11:13 | call to Take | test.go:24:2:26:2 | for statement | test.go:11:2:11:13 | call to Take | This calls call to Take in a $@. | test.go:24:2:26:2 | for statement | loop |
edges
| DatabaseCallInLoop.go:7:2:11:2 | range statement | DatabaseCallInLoop.go:9:3:9:41 | call to First |
| test.go:10:1:12:1 | function declaration | test.go:11:2:11:13 | call to Take |
Expand All @@ -7,7 +11,3 @@ edges
| test.go:21:3:21:14 | call to runQuery | test.go:10:1:12:1 | function declaration |
| test.go:24:2:26:2 | for statement | test.go:25:3:25:17 | call to runRunQuery |
| test.go:25:3:25:17 | call to runRunQuery | test.go:14:1:16:1 | function declaration |
#select
| DatabaseCallInLoop.go:9:3:9:41 | call to First | DatabaseCallInLoop.go:7:2:11:2 | range statement | DatabaseCallInLoop.go:9:3:9:41 | call to First | This calls call to First in a $@. | DatabaseCallInLoop.go:7:2:11:2 | range statement | loop |
| test.go:11:2:11:13 | call to Take | test.go:20:2:22:2 | for statement | test.go:11:2:11:13 | call to Take | This calls call to Take in a $@. | test.go:20:2:22:2 | for statement | loop |
| test.go:11:2:11:13 | call to Take | test.go:24:2:26:2 | for statement | test.go:11:2:11:13 | call to Take | This calls call to Take in a $@. | test.go:24:2:26:2 | for statement | loop |
4 changes: 2 additions & 2 deletions go/ql/test/experimental/CWE-400/DatabaseCallInLoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ func getUsers(db *gorm.DB, names []string) []User {
res := make([]User, 0, len(names))
for _, name := range names {
var user User
db.Where("name = ?", name).First(&user)
db.Where("name = ?", name).First(&user) // $ Alert
res = append(res, user)
}
} // $ Source
return res
}
3 changes: 2 additions & 1 deletion go/ql/test/experimental/CWE-400/DatabaseCallInLoop.qlref
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
experimental/CWE-400/DatabaseCallInLoop.ql
query: experimental/CWE-400/DatabaseCallInLoop.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
6 changes: 3 additions & 3 deletions go/ql/test/experimental/CWE-400/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type User struct {
}

func runQuery(db *gorm.DB) {
db.Take(nil)
db.Take(nil) // $ Alert
}

func runRunQuery(db *gorm.DB) {
Expand All @@ -19,9 +19,9 @@ func main() {
var db *gorm.DB
for i := 0; i < 10; i++ {
runQuery(db)
}
} // $ Source

for i := 10; i > 0; i-- {
runRunQuery(db)
}
} // $ Source
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
query: experimental/CWE-522-DecompressionBombs/DecompressionBombs.ql
postprocess: utils/test/PrettyPrintModels.ql
postprocess:
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql
Loading
Loading