Skip to content

Commit

Permalink
add example for domain names with sub-domains to missing-regexp-anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-krogh committed May 8, 2024
1 parent 1ba27e6 commit 813ec7c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions go/ql/src/Security/CWE-020/MissingRegexpAnchorGoodDomain.go
Expand Up @@ -5,13 +5,16 @@ import (
)

func checkSubdomain(domain String) {
// GOOD: Checking the domain is `example.com` or a subdomain of `example.com`.
re := "(^|\\.)example\\.com$"

// Alternatively, checking strictly that the domain is `example.com`.
// re2 := "^example\\.com$"

// Checking strictly that the domain is `example.com`.
re := "^example\\.com$"
if matched, _ := regexp.MatchString(re, domain); matched {
// domain is good.
}
}

// GOOD: Alternatively, check the domain is `example.com` or a subdomain of `example.com`.
re2 := "(^|\\.)example\\.com$"

if matched, _ := regexp.MatchString(re2, domain); matched {
// domain is good.
}
}

0 comments on commit 813ec7c

Please sign in to comment.