Skip to content

Commit 355499e

Browse files
committed
move getACommonTld to the shared pack
1 parent f67d0bc commit 355499e

File tree

11 files changed

+24
-21
lines changed

11 files changed

+24
-21
lines changed

javascript/ql/lib/semmle/javascript/Regexp.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,12 @@ predicate isInterpretedAsRegExp(DataFlow::Node source) {
999999
/**
10001000
* Provides utility predicates related to regular expressions.
10011001
*/
1002-
module RegExpPatterns {
1002+
deprecated module RegExpPatterns {
10031003
/**
10041004
* Gets a pattern that matches common top-level domain names in lower case.
1005+
* DEPRECATED: use the similarly named predicate from `HostnameRegex` from the `regex` pack instead.
10051006
*/
1006-
string getACommonTld() {
1007+
deprecated string getACommonTld() {
10071008
// according to ranking by http://google.com/search?q=site:.<<TLD>>
10081009
result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
10091010
}

javascript/ql/lib/semmle/javascript/security/regexp/HostnameRegexp.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ private module Impl implements Shared::HostnameRegexpSig<TreeImpl> {
1212
class DataFlowNode = JS::DataFlow::Node;
1313

1414
class RegExpPatternSource = RegExp::RegExpPatternSource;
15-
16-
string getACommonTld() { result = RegExp::RegExpPatterns::getACommonTld() }
1715
}
1816

1917
import Shared::Make<TreeImpl, Impl>

javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ query predicate problems(
3131
(
3232
// target contains a domain on a common TLD, and perhaps some other URL components
3333
target
34-
.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+" + RegExpPatterns::getACommonTld() +
34+
.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+" + HostnameRegexp::getACommonTld() +
3535
"(:[0-9]+)?/?")
3636
or
3737
// target is a HTTP URL to a domain on any TLD

javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitizationSpecific.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ import semmle.javascript.dataflow.InferredTypes
33

44
/** Holds if `node` may evaluate to `value` */
55
predicate mayHaveStringValue(DataFlow::Node node, string value) { node.mayHaveStringValue(value) }
6+
7+
import semmle.javascript.security.regexp.HostnameRegexp as HostnameRegexp

python/ql/lib/semmle/python/dataflow/new/Regexp.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ private import semmle.python.dataflow.new.DataFlow
99
/**
1010
* Provides utility predicates related to regular expressions.
1111
*/
12-
module RegExpPatterns {
12+
deprecated module RegExpPatterns {
1313
/**
1414
* Gets a pattern that matches common top-level domain names in lower case.
15+
* DEPRECATED: use the similarly named predicate from `HostnameRegex` from the `regex` pack instead.
1516
*/
16-
string getACommonTld() {
17+
deprecated string getACommonTld() {
1718
// according to ranking by http://google.com/search?q=site:.<<TLD>>
1819
result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
1920
}

python/ql/lib/semmle/python/security/regexp/HostnameRegex.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ private module Impl implements Shared::HostnameRegexpSig<TreeImpl> {
1313
class DataFlowNode = DataFlow::Node;
1414

1515
class RegExpPatternSource = Regexp::RegExpPatternSource;
16-
17-
string getACommonTld() { result = Regexp::RegExpPatterns::getACommonTld() }
1816
}
1917

2018
import Shared::Make<TreeImpl, Impl>

ruby/ql/lib/codeql/ruby/Regexp.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ private import codeql.ruby.ApiGraphs
1515
/**
1616
* Provides utility predicates related to regular expressions.
1717
*/
18-
module RegExpPatterns {
18+
deprecated module RegExpPatterns {
1919
/**
2020
* Gets a pattern that matches common top-level domain names in lower case.
21+
* DEPRECATED: use the similarly named predicate from `HostnameRegex` from the `regex` pack instead.
2122
*/
22-
string getACommonTld() {
23+
deprecated string getACommonTld() {
2324
// according to ranking by http://google.com/search?q=site:.<<TLD>>
2425
result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
2526
}

ruby/ql/lib/codeql/ruby/security/regexp/HostnameRegexp.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ private module Impl implements Shared::HostnameRegexpSig<TreeImpl> {
1212
class DataFlowNode = DataFlow::Node;
1313

1414
class RegExpPatternSource = Regexp::RegExpPatternSource;
15-
16-
string getACommonTld() { result = Regexp::RegExpPatterns::getACommonTld() }
1715
}
1816

1917
import Shared::Make<TreeImpl, Impl>

ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ query predicate problems(
3131
(
3232
// target contains a domain on a common TLD, and perhaps some other URL components
3333
target
34-
.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+" + RegExpPatterns::getACommonTld() +
34+
.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+" + HostnameRegexp::getACommonTld() +
3535
"(:[0-9]+)?/?")
3636
or
3737
// target is a HTTP URL to a domain on any TLD
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import codeql.ruby.DataFlow
22
import codeql.ruby.StringOps
3-
import codeql.ruby.Regexp::RegExpPatterns as RegExpPatterns
43

54
/** Holds if `node` may evaluate to `value` */
65
predicate mayHaveStringValue(DataFlow::Node node, string value) {
76
node.asExpr().getConstantValue().getString() = value
87
}
8+
9+
import codeql.ruby.security.regexp.HostnameRegexp as HostnameRegexp

0 commit comments

Comments
 (0)