Skip to content

Commit 9a37682

Browse files
committed
Moved comment to previous line if resulting in long line
1 parent a9f107c commit 9a37682

9 files changed

+20
-10
lines changed

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalBad.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
public class PartialPathTraversalBad {
22
public void example(File dir, File parent) throws IOException {
3-
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath())) { // BAD: dir.getCanonicalPath() not slash-terminated
3+
// BAD: dir.getCanonicalPath() not slash-terminated
4+
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath())) {
45
throw new IOException("Path traversal attempt: " + dir.getCanonicalPath());
56
}
67
}

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalGood.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
public class PartialPathTraversalGood {
44
public void example(File dir, File parent) throws IOException {
5-
if (!dir.toPath().normalize().startsWith(parent.toPath())) { // GOOD: Check if dir.Path() is normalised
5+
// GOOD: Check if dir.Path() is normalised
6+
if (!dir.toPath().normalize().startsWith(parent.toPath())) {
67
throw new IOException("Path traversal attempt: " + dir.getCanonicalPath());
78
}
89
}

java/ql/src/Security/CWE/CWE-079/AndroidWebViewAddJavascriptInterfaceExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public String studentEmail(String studentName) {
2020
webview.loadData("", "text/html", null);
2121

2222
String name = "Robert'; DROP TABLE students; --";
23-
webview.loadUrl("javascript:alert(exposedObject.studentEmail(\""+ name +"\"))"); // BAD: Untrusted input loaded into WebView
23+
// BAD: Untrusted input loaded into WebView
24+
webview.loadUrl("javascript:alert(exposedObject.studentEmail(\""+ name +"\"))");

java/ql/src/Security/CWE/CWE-094/InstallApkWithFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
File file = new File(Environment.getExternalStorageDirectory(), "myapp.apk");
1010
Intent intent = new Intent(Intent.ACTION_VIEW);
1111
/* Set the mimetype to APK */
12-
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); // BAD: The file may be altered by another app
12+
// BAD: The file may be altered by another app
13+
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
1314

1415
startActivity(intent);

java/ql/src/Security/CWE/CWE-094/InstallApkWithFileProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
/* Expose temporary file with FileProvider */
2323
File toInstall = new File(this.getFilesDir(), tempFilename);
24-
Uri applicationUri = FileProvider.getUriForFile(this, "com.example.apkprovider", toInstall); // GOOD: The file is protected by FileProvider
24+
// GOOD: The file is protected by FileProvider
25+
Uri applicationUri = FileProvider.getUriForFile(this, "com.example.apkprovider", toInstall);
2526

2627
/* Create Intent and set data to APK file. */
2728
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);

java/ql/src/Security/CWE/CWE-094/SSTIBad.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public void bad(HttpServletRequest request) {
1414

1515
StringWriter w = new StringWriter();
1616
// evaluate( Context context, Writer out, String logTag, String instring )
17-
Velocity.evaluate(context, w, "mystring", code); // BAD: code is controlled by the user
17+
// BAD: code is controlled by the user
18+
Velocity.evaluate(context, w, "mystring", code);
1819
}
1920
}

java/ql/src/Security/CWE/CWE-094/SaferSpelExpressionEvaluation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ public Object evaluate(Socket socket) throws IOException {
44

55
String string = reader.readLine();
66
ExpressionParser parser = new SpelExpressionParser();
7-
Expression expression = parser.parseExpression(string); // AVOID: string is controlled by the user
7+
// AVOID: string is controlled by the user
8+
Expression expression = parser.parseExpression(string);
89
SimpleEvaluationContext context
910
= SimpleEvaluationContext.forReadWriteDataBinding().build();
10-
return expression.getValue(context); // OK: Untrusted expressions are evaluated in a restricted context
11+
// OK: Untrusted expressions are evaluated in a restricted context
12+
return expression.getValue(context);
1113
}
1214
}

java/ql/src/Security/CWE/CWE-094/UnsafeJexlExpressionEvaluation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public void evaluate(Socket socket) throws IOException {
44

55
String input = reader.readLine();
66
JexlEngine jexl = new JexlBuilder().create();
7-
JexlExpression expression = jexl.createExpression(input); // BAD: input is controlled by the user
7+
// BAD: input is controlled by the user
8+
JexlExpression expression = jexl.createExpression(input);
89
JexlContext context = new MapContext();
910
expression.evaluate(context);
1011
}

java/ql/src/Security/CWE/CWE-094/UnsafeSpelExpressionEvaluation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public Object evaluate(Socket socket) throws IOException {
44

55
String string = reader.readLine();
66
ExpressionParser parser = new SpelExpressionParser();
7-
Expression expression = parser.parseExpression(string); // BAD: string is controlled by the user
7+
// BAD: string is controlled by the user
8+
Expression expression = parser.parseExpression(string);
89
return expression.getValue();
910
}
1011
}

0 commit comments

Comments
 (0)