5
5
* @problem.severity warning
6
6
* @security-severity 7.8
7
7
* @precision medium
8
- * @id js/regex /missing-regexp-anchor
8
+ * @id swift /missing-regexp-anchor
9
9
* @tags correctness
10
10
* security
11
11
* external/cwe/cwe-020
12
12
*/
13
13
14
- private import javascript
15
- private import semmle.javascript.security.regexp.HostnameRegexp as HostnameRegexp
14
+ private import swift
15
+ private import codeql.swift.dataflow.DataFlow
16
+ private import codeql.swift.regex.Regex
17
+ private import codeql.swift.regex.RegexTreeView:: RegexTreeView as TreeImpl
18
+ private import codeql.swift.security.regex.HostnameRegex as HostnameRegex
16
19
private import codeql.regex.MissingRegExpAnchor as MissingRegExpAnchor
17
- private import semmle.javascript.security.regexp.RegExpTreeView:: RegExpTreeView as TreeImpl
18
20
19
21
private module Impl implements
20
- MissingRegExpAnchor:: MissingRegExpAnchorSig< TreeImpl , HostnameRegexp :: Impl >
22
+ MissingRegExpAnchor:: MissingRegExpAnchorSig< TreeImpl , HostnameRegex :: Impl >
21
23
{
22
- predicate isUsedAsReplace ( RegExpPatternSource pattern ) {
23
- // is used for capture or replace
24
+ predicate isUsedAsReplace ( RegexPatternSource pattern ) {
25
+ none ( )
26
+ /* java // is used for capture or replace
24
27
exists(DataFlow::MethodCallNode mcn, string name | name = mcn.getMethodName() |
25
28
name = "exec" and
26
29
mcn = pattern.getARegExpObject().getAMethodCall() and
@@ -37,20 +40,30 @@ private module Impl implements
37
40
or
38
41
name = "match" and exists(mcn.getAPropertyRead())
39
42
)
40
- )
43
+ )*/
44
+ /* rb exists(DataFlow::CallNode mcn, DataFlow::Node arg, string name |
45
+ name = mcn.getMethodName() and
46
+ arg = mcn.getArgument(0)
47
+ |
48
+ (
49
+ pattern.getAParse().(DataFlow::LocalSourceNode).flowsTo(arg) or
50
+ pattern.getAParse() = arg
51
+ ) and
52
+ name = ["sub", "sub!", "gsub", "gsub!"]
53
+ )*/
41
54
}
42
55
43
56
string getEndAnchorText ( ) { result = "$" }
44
57
}
45
58
46
- import MissingRegExpAnchor:: Make< TreeImpl , HostnameRegexp :: Impl , Impl >
59
+ import MissingRegExpAnchor:: Make< TreeImpl , HostnameRegex :: Impl , Impl >
47
60
48
- from DataFlow:: Node nd , string msg
61
+ from DataFlow:: Node node , string msg
49
62
where
50
- isUnanchoredHostnameRegExp ( nd , msg )
63
+ isUnanchoredHostnameRegExp ( node , msg )
51
64
or
52
- isSemiAnchoredHostnameRegExp ( nd , msg )
65
+ isSemiAnchoredHostnameRegExp ( node , msg )
53
66
or
54
- hasMisleadingAnchorPrecedence ( nd , msg )
67
+ hasMisleadingAnchorPrecedence ( node , msg )
55
68
// isLineAnchoredHostnameRegExp is not used here, as it is not relevant to JS.
56
- select nd , msg
69
+ select node , msg
0 commit comments