Skip to content

Commit 5b2b60f

Browse files
erik-kroghMax Schaefer
andauthored
change DOS to DoS, and other small documentation fixes
Co-Authored-By: Max Schaefer <max@semmle.com>
1 parent c2efb0a commit 5b2b60f

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

change-notes/1.23/analysis-javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
| **Query** | **Tags** | **Purpose** |
1515
|---------------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
16-
| Unused index variable (`js/unused-index-variable`) | correctness | Highlights loops that iterate over an array, but do not use the index variable to access array elements, indicating a possible typo or logic error. |
17-
| Tainted .length in loop condition (`js/loop-bound-injection`) | security | Highlights loops where a user-controlled object with an arbitrary .length value can trick the server to loop infinitely. |
16+
| Unused index variable (`js/unused-index-variable`) | correctness | Highlights loops that iterate over an array, but do not use the index variable to access array elements, indicating a possible typo or logic error. Results are shown on LGTM by default. |
17+
| Tainted .length in loop condition (`js/loop-bound-injection`) | security | Highlights loops where a user-controlled object with an arbitrary .length value can trick the server to loop infinitely. Results are not shown on LGTM by default. |
1818

1919
## Changes to existing queries
2020

javascript/ql/src/Security/CWE-834/TaintedLength.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<overview>
77
<p>
8-
Using the .length property of an untrusted object as a loop bound may
8+
Using the <code>.length</code> property of an untrusted object as a loop bound may
99
cause indefinite looping since a malicious attacker can set the
1010
<code>.length</code> property to a very large number. For example,
1111
when a program that expects an array is passed a JSON object such as

javascript/ql/src/Security/CWE-834/TaintedLength.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Tainted .length in loop condition
33
* @description Iterating over an object with a user-controlled .length
4-
* property can cause indefinite looping
4+
* property can cause indefinite looping.
55
* @kind path-problem
66
* @problem.severity warning
77
* @id js/loop-bound-injection

javascript/ql/src/Security/CWE-834/examples/TaintedLength_fixed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var app = express();
44
app.post("/foo", (req, res) => {
55
var obj = req.body;
66

7-
if (!(obj instanceof Array)) { // prevents DOS
7+
if (!(obj instanceof Array)) { // prevents DoS
88
return [];
99
}
1010

@@ -13,4 +13,4 @@ app.post("/foo", (req, res) => {
1313
for (var i = 0; i < obj.length; i++) {
1414
ret.push(obj[i]);
1515
}
16-
});
16+
});

javascript/ql/src/semmle/javascript/security/dataflow/TaintedLengthCustomizations.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module TaintedLength {
9696
arrayRead.flowsToExpr(throws) and
9797
isCrashingWithNullValues(throws)
9898
) and
99-
// The existence of some kind of early-exit usually indicates that the loop will stop early and no DOS happens.
99+
// The existence of some kind of early-exit usually indicates that the loop will stop early and no DoS happens.
100100
not exists(BreakStmt br | br.getTarget() = loop) and
101101
not exists(ReturnStmt ret |
102102
ret.getParentStmt*() = loop.getBody() and
@@ -111,7 +111,7 @@ module TaintedLength {
111111
}
112112

113113
/**
114-
* Holds if `name` is a method from lodash vulnerable to a DOS attack if called with a tained object.
114+
* Holds if `name` is a method from lodash vulnerable to a DoS attack if called with a tainted object.
115115
*/
116116
predicate loopableLodashMethod(string name) {
117117
name = "chunk" or
@@ -200,7 +200,7 @@ module TaintedLength {
200200
isCrashingWithNullValues(throws)
201201
)
202202
or
203-
// similar to the loop sink - the existence of an early-exit usually means that no DOS can happen.
203+
// similar to the loop sink - the existence of an early-exit usually means that no DoS can happen.
204204
exists(ThrowStmt throw |
205205
throw.getTarget() = func.asExpr()
206206
)

javascript/ql/test/query-tests/Security/CWE-834/TaintedLengthExitBad.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function breaks(val) {
2020
for (var i = 0; i < val.length; i++) { // NOT OK!
2121
for (var k = 0; k < 2; k++) {
2222
if (k == 3) {
23-
// Does not prevent DOS, because this is inside an inner loop.
23+
// Does not prevent DoS, because this is inside an inner loop.
2424
break;
2525
}
2626
}
@@ -34,7 +34,7 @@ function throws(val) {
3434
for (var i = 0; i < val.length; i++) { // NOT OK!
3535
if (val[i] == null) {
3636
try {
37-
throw 2; // Is catched, and therefore the DOS is not prevented.
37+
throw 2; // Is caught, and therefore the DoS is not prevented.
3838
} catch(e) {
3939
// ignored
4040
}
@@ -49,7 +49,7 @@ function returns(val) {
4949
for (var i = 0; i < val.length; i++) { // NOT OK!
5050
if (val[i] == null) {
5151
(function (i) {
52-
return i+2; // Does not prevent DOS.
52+
return i+2; // Does not prevent DoS.
5353
})(i);
5454
}
5555
ret.push(val[i]);
@@ -60,10 +60,10 @@ function lodashThrow(val) { // NOT OK!
6060
_.map(val, function (e) {
6161
if (!e) {
6262
try {
63-
throw new Error(); // Does not prevent DOS
63+
throw new Error(); // Does not prevent DoS
6464
} catch(e) {
6565
// ignored.
6666
}
6767
}
6868
})
69-
}
69+
}

javascript/ql/test/query-tests/Security/CWE-834/TaintedLengthExitGood.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function breaks(val) {
1919

2020
for (var i = 0; i < val.length; i++) { // OK
2121
if (val[i] == null) {
22-
break; // prevents DOS.
22+
break; // prevents DoS.
2323
}
2424
ret.push(val[i]);
2525
}
@@ -30,7 +30,7 @@ function throws(val) {
3030

3131
for (var i = 0; i < val.length; i++) { // OK
3232
if (val[i] == null) {
33-
throw 2; // prevents DOS.
33+
throw 2; // prevents DoS.
3434
}
3535
ret.push(val[i]);
3636
}
@@ -42,7 +42,7 @@ function returns(val) {
4242

4343
for (var i = 0; i < val.length; i++) { // OK
4444
if (val[i] == null) {
45-
return 2; // prevents DOS.
45+
return 2; // prevents DoS.
4646
}
4747
ret.push(val[i]);
4848
}
@@ -51,7 +51,7 @@ function returns(val) {
5151
function lodashThrow(val) {
5252
_.map(val, function (e) { // OK
5353
if (!e) {
54-
throw new Error(); // prevents DOS.
54+
throw new Error(); // prevents DoS.
5555
}
5656
})
57-
}
57+
}

javascript/ql/test/query-tests/Security/CWE-834/TaintedLengthObviousLengthCheck.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ rootRoute.post(function(req, res) {
1111
function problem(val) {
1212
var ret = [];
1313

14-
// Prevents DOS
14+
// Prevents DoS
1515
if (val.length > 100) {
1616
return [];
1717
}
1818

1919
for (var i = 0; i < val.length; i++) { // OK
2020
ret.push(val[i]);
2121
}
22-
}
22+
}

0 commit comments

Comments
 (0)