55 * @problem.severity warning
66 * @security-severity 7.8
77 * @precision medium
8- * @id js/regex /missing-regexp-anchor
8+ * @id swift /missing-regexp-anchor
99 * @tags correctness
1010 * security
1111 * external/cwe/cwe-020
1212 */
1313
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
1619private import codeql.regex.MissingRegExpAnchor as MissingRegExpAnchor
17- private import semmle.javascript.security.regexp.RegExpTreeView:: RegExpTreeView as TreeImpl
1820
1921private module Impl implements
20- MissingRegExpAnchor:: MissingRegExpAnchorSig< TreeImpl , HostnameRegexp :: Impl >
22+ MissingRegExpAnchor:: MissingRegExpAnchorSig< TreeImpl , HostnameRegex :: Impl >
2123{
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
2427 exists(DataFlow::MethodCallNode mcn, string name | name = mcn.getMethodName() |
2528 name = "exec" and
2629 mcn = pattern.getARegExpObject().getAMethodCall() and
@@ -37,20 +40,30 @@ private module Impl implements
3740 or
3841 name = "match" and exists(mcn.getAPropertyRead())
3942 )
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+ )*/
4154 }
4255
4356 string getEndAnchorText ( ) { result = "$" }
4457}
4558
46- import MissingRegExpAnchor:: Make< TreeImpl , HostnameRegexp :: Impl , Impl >
59+ import MissingRegExpAnchor:: Make< TreeImpl , HostnameRegex :: Impl , Impl >
4760
48- from DataFlow:: Node nd , string msg
61+ from DataFlow:: Node node , string msg
4962where
50- isUnanchoredHostnameRegExp ( nd , msg )
63+ isUnanchoredHostnameRegExp ( node , msg )
5164 or
52- isSemiAnchoredHostnameRegExp ( nd , msg )
65+ isSemiAnchoredHostnameRegExp ( node , msg )
5366 or
54- hasMisleadingAnchorPrecedence ( nd , msg )
67+ hasMisleadingAnchorPrecedence ( node , msg )
5568// isLineAnchoredHostnameRegExp is not used here, as it is not relevant to JS.
56- select nd , msg
69+ select node , msg
0 commit comments