File tree Expand file tree Collapse file tree 4 files changed +115
-16
lines changed
javascript/ql/src/Performance
java/ql/src/Security/CWE/CWE-730
python/ql/src/Security/CWE-730
ruby/ql/src/queries/security/cwe-1333 Expand file tree Collapse file tree 4 files changed +115
-16
lines changed Original file line number Diff line number Diff line change 15
15
</p >
16
16
17
17
<sample language =" java" >
18
- Pattern.compile("^\\s+|\\s+$").matcher(text).replaceAll("") // BAD
19
- </sample >
18
+ Pattern.compile("^\\s+|\\s+$").matcher(text).replaceAll("") // BAD</sample >
20
19
21
20
<p >
22
21
71
70
</p >
72
71
73
72
<sample language =" java" >
74
- "^0\\.\\d+E?\\d+$""
75
- </sample >
73
+ "^0\\.\\d+E?\\d+$"" </sample >
76
74
77
75
<p >
78
76
103
101
104
102
</example >
105
103
104
+ <example >
105
+ <p >
106
+ Sometimes it is unclear how a regular expression can be rewritten to
107
+ avoid the problem. In such cases, it often suffices to limit the
108
+ length of the input string. For instance, the following
109
+ regular expression is used to match numbers, and on some non-number
110
+ inputs it can have quadratic time complexity:
111
+ </p >
112
+
113
+ <sample language =" java" >
114
+ Pattern.matches("^(\\+|-)?(\\d+|(\\d*\\.\\d*))?(E|e)?([-+])?(\\d+)?$", str); </sample >
115
+
116
+ <p >
117
+ It is not immediately obvious how to rewrite this regular expression
118
+ to avoid the problem. However, you can mitigate performance issues by limiting the length
119
+ to 1000 characters, which will always finish in a reasonable amount
120
+ of time.
121
+ </p >
122
+
123
+ <sample language =" java" >
124
+ if (str.length() > 1000) {
125
+ throw new IllegalArgumentException("Input too long");
126
+ }
127
+
128
+ Pattern.matches("^(\\+|-)?(\\d+|(\\d*\\.\\d*))?(E|e)?([-+])?(\\d+)?$", str); </sample >
129
+ </example >
130
+
106
131
<include src =" ReDoSReferences.inc.qhelp" />
107
132
108
133
</qhelp >
Original file line number Diff line number Diff line change 15
15
</p >
16
16
17
17
<sample language =" javascript" >
18
- text.replace(/^\s+|\s+$/g, ''); // BAD
19
- </sample >
18
+ text.replace(/^\s+|\s+$/g, ''); // BAD</sample >
20
19
21
20
<p >
22
21
71
70
</p >
72
71
73
72
<sample language =" javascript" >
74
- /^0\.\d+E?\d+$/.test(str) // BAD
75
- </sample >
73
+ /^0\.\d+E?\d+$/.test(str) // BAD</sample >
76
74
77
75
<p >
78
76
103
101
104
102
</example >
105
103
104
+ <example >
105
+ <p >
106
+ Sometimes it is unclear how a regular expression can be rewritten to
107
+ avoid the problem. In such cases, it often suffices to limit the
108
+ length of the input string. For instance, the following
109
+ regular expression is used to match numbers, and on some non-number
110
+ inputs it can have quadratic time complexity:
111
+ </p >
112
+
113
+ <sample language =" javascript" >
114
+ /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/.test(str) // BAD</sample >
115
+
116
+ <p >
117
+ It is not immediately obvious how to rewrite this regular expression
118
+ to avoid the problem. However, you can mitigate performance issues by limiting the length
119
+ to 1000 characters, which will always finish in a reasonable amount
120
+ of time.
121
+ </p >
122
+
123
+ <sample language =" javascript" >
124
+ if (str.length > 1000) {
125
+ throw new Error("Input too long");
126
+ }
127
+
128
+ /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/.test(str)</sample >
129
+ </example >
130
+
106
131
<include src =" ReDoSReferences.inc.qhelp" />
107
132
108
133
</qhelp >
Original file line number Diff line number Diff line change 15
15
</p >
16
16
17
17
<sample language =" python" >
18
- re.sub(r"^\s+|\s+$", "", text) # BAD
19
- </sample >
18
+ re.sub(r"^\s+|\s+$", "", text) # BAD</sample >
20
19
21
20
<p >
22
21
71
70
</p >
72
71
73
72
<sample language =" python" >
74
- ^0\.\d+E?\d+$ # BAD
75
- </sample >
73
+ ^0\.\d+E?\d+$ # BAD</sample >
76
74
77
75
<p >
78
76
103
101
104
102
</example >
105
103
104
+ <example >
105
+ <p >
106
+ Sometimes it is unclear how a regular expression can be rewritten to
107
+ avoid the problem. In such cases, it often suffices to limit the
108
+ length of the input string. For instance, the following
109
+ regular expression is used to match numbers, and on some non-number
110
+ inputs it can have quadratic time complexity:
111
+ </p >
112
+
113
+ <sample language =" python" >
114
+ match = re.search(r'^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$', str) </sample >
115
+
116
+ <p >
117
+ It is not immediately obvious how to rewrite this regular expression
118
+ to avoid the problem. However, you can mitigate performance issues by limiting the length
119
+ to 1000 characters, which will always finish in a reasonable amount
120
+ of time.
121
+ </p >
122
+
123
+ <sample language =" python" >
124
+ if len(str) > 1000:
125
+ raise ValueError("Input too long")
126
+
127
+ match = re.search(r'^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$', str) </sample >
128
+ </example >
129
+
106
130
<include src =" ReDoSReferences.inc.qhelp" />
107
131
108
132
</qhelp >
Original file line number Diff line number Diff line change 15
15
</p >
16
16
17
17
<sample language =" ruby" >
18
- text.gsub!(/^\s+|\s+$/, '') # BAD
19
- </sample >
18
+ text.gsub!(/^\s+|\s+$/, '') # BAD</sample >
20
19
21
20
<p >
22
21
74
73
</p >
75
74
76
75
<sample language =" ruby" >
77
- /^0\.\d+E?\d+$/ # BAD
78
- </sample >
76
+ /^0\.\d+E?\d+$/ # BAD</sample >
79
77
80
78
<p >
81
79
108
106
109
107
</example >
110
108
109
+ <example >
110
+ <p >
111
+ Sometimes it is unclear how a regular expression can be rewritten to
112
+ avoid the problem. In such cases, it often suffices to limit the
113
+ length of the input string. For instance, the following
114
+ regular expression is used to match numbers, and on some non-number
115
+ inputs it can have quadratic time complexity:
116
+ </p >
117
+
118
+ <sample language =" ruby" >
119
+ is_matching = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/.match?(str)</sample >
120
+
121
+ <p >
122
+ It is not immediately obvious how to rewrite this regular expression
123
+ to avoid the problem. However, you can mitigate performance issues by limiting the length
124
+ to 1000 characters, which will always finish in a reasonable amount
125
+ of time.
126
+ </p >
127
+
128
+ <sample language =" ruby" >
129
+ if str.length > 1000
130
+ raise ArgumentError, "Input too long"
131
+ end
132
+
133
+ is_matching = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/.match?(str)</sample >
134
+ </example >
135
+
111
136
<include src =" ReDoSReferences.inc.qhelp" />
112
137
113
138
</qhelp >
You can’t perform that action at this time.
0 commit comments