Skip to content

Commit 5abcf13

Browse files
author
Paolo Tranquilli
committed
Merge branch 'main' into redsun82/rust-config
2 parents a6f58c9 + dd102c4 commit 5abcf13

File tree

56 files changed

+180
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+180
-42
lines changed

csharp/documentation/library-coverage/coverage.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ MySql.Data.MySqlClient,48,,,,,,,,,,,,48,,,,,,,,,,
4242
Newtonsoft.Json,,,91,,,,,,,,,,,,,,,,,,,73,18
4343
ServiceStack,194,,7,27,,,,,75,,,,92,,,,,,,,,7,
4444
SourceGenerators,,,5,,,,,,,,,,,,,,,,,,,,5
45-
System,54,47,12221,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5921,6300
45+
System,54,47,12241,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5941,6300
4646
Windows.Security.Cryptography.Core,1,,,,,,,1,,,,,,,,,,,,,,,

csharp/documentation/library-coverage/coverage.rst

+2-2

go/documentation/library-coverage/coverage.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ container/ring,,,5,,,,,,,,,,,,,,,,,,,,,,,5,
1616
context,,,5,,,,,,,,,,,,,,,,,,,,,,,5,
1717
crypto,,,10,,,,,,,,,,,,,,,,,,,,,,,10,
1818
database/sql,30,18,12,,,,,,,,,,,,30,,,,,,18,,,,,12,
19-
encoding,,,77,,,,,,,,,,,,,,,,,,,,,,,77,
19+
encoding,,,81,,,,,,,,,,,,,,,,,,,,,,,81,
2020
errors,,,3,,,,,,,,,,,,,,,,,,,,,,,3,
2121
expvar,,,6,,,,,,,,,,,,,,,,,,,,,,,6,
2222
fmt,3,,16,,,,3,,,,,,,,,,,,,,,,,,,16,
@@ -139,4 +139,5 @@ syscall,5,2,8,5,,,,,,,,,,,,,,,,,,2,,,,8,
139139
text/scanner,,,3,,,,,,,,,,,,,,,,,,,,,,,3,
140140
text/tabwriter,,,1,,,,,,,,,,,,,,,,,,,,,,,1,
141141
text/template,,,4,,,,,,,,,,,,,,,,,,,,,,,4,
142+
weak,,,2,,,,,,,,,,,,,,,,,,,,,,,2,
142143
xorm.io/xorm,34,,,,,,,,,,,,,,34,,,,,,,,,,,,

go/documentation/library-coverage/coverage.rst

+3-3

java/ql/src/Security/CWE/CWE-020/ExternalAPITaintStepExample.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
44

55
StringBuilder sqlQueryBuilder = new StringBuilder();
66
sqlQueryBuilder.append("SELECT * FROM user WHERE user_id='");
7+
// BAD: a request parameter is concatenated directly into a SQL query
78
sqlQueryBuilder.append(request.getParameter("user_id"));
89
sqlQueryBuilder.append("'");
910

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

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

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

+1
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+
// BAD: Untrusted input loaded into WebView
2324
webview.loadUrl("javascript:alert(exposedObject.studentEmail(\""+ name +"\"))");
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
WebSettings settings = webview.getSettings();
2-
settings.setJavaScriptEnabled(false);
2+
settings.setJavaScriptEnabled(false); // GOOD: webview has JavaScript disabled
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
WebSettings settings = webview.getSettings();
2-
settings.setJavaScriptEnabled(true);
2+
settings.setJavaScriptEnabled(true); // BAD: webview has JavaScript enabled

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ public class GroovyInjection {
22
void injectionViaClassLoader(HttpServletRequest request) {
33
String script = request.getParameter("script");
44
final GroovyClassLoader classLoader = new GroovyClassLoader();
5-
Class groovy = classLoader.parseClass(script);
5+
Class groovy = classLoader.parseClass(script); // BAD: Groovy code injection
66
GroovyObject groovyObj = (GroovyObject) groovy.newInstance();
77
}
88

99
void injectionViaEval(HttpServletRequest request) {
1010
String script = request.getParameter("script");
11-
Eval.me(script);
11+
Eval.me(script); // BAD: Groovy code injection
1212
}
1313

1414
void injectionViaGroovyShell(HttpServletRequest request) {
1515
GroovyShell shell = new GroovyShell();
1616
String script = request.getParameter("script");
17-
shell.evaluate(script);
17+
shell.evaluate(script); // BAD: Groovy code injection
1818
}
1919

2020
void injectionViaGroovyShellGroovyCodeSource(HttpServletRequest request) {
2121
GroovyShell shell = new GroovyShell();
2222
String script = request.getParameter("script");
2323
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
24-
shell.evaluate(gcs);
24+
shell.evaluate(gcs); // BAD: Groovy code injection
2525
}
2626
}
2727

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

+1
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+
// BAD: The file may be altered by another app
1213
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
1314

1415
startActivity(intent);

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

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

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

2627
/* Create Intent and set data to APK file. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// GOOD: Package installed using PackageInstaller
12
import android.content.Context;
23
import android.content.Intent;
34
import android.content.pm.PackageInstaller;

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

+1
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+
// BAD: code is controlled by the user
1718
Velocity.evaluate(context, w, "mystring", code);
1819
}
1920
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void good(HttpServletRequest request) {
1111

1212
String s = "We are using $project $name to render this.";
1313
StringWriter w = new StringWriter();
14-
Velocity.evaluate(context, w, "mystring", s);
14+
Velocity.evaluate(context, w, "mystring", s); // GOOD: s is a constant string
1515
System.out.println(" string : " + w);
1616
}
1717
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public void evaluate(Socket socket) throws IOException {
44

55
JexlSandbox onlyMath = new JexlSandbox(false);
66
onlyMath.white("java.lang.Math");
7-
JexlEngine jexl = new JexlBuilder().sandbox(onlyMath).create();
7+
JexlEngine jexl = new JexlBuilder().sandbox(onlyMath).create(); // GOOD: using a sandbox
88

99
String input = reader.readLine();
1010
JexlExpression expression = jexl.createExpression(input);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public void evaluate(Socket socket) throws IOException {
66
JexlEngine jexl = new JexlBuilder().uberspect(sandbox).create();
77

88
String input = reader.readLine();
9-
JexlExpression expression = jexl.createExpression(input);
9+
JexlExpression expression = jexl.createExpression(input); // GOOD: jexl uses a sandbox
1010
JexlContext context = new MapContext();
1111
expression.evaluate(context);
1212
}

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

+2
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+
// AVOID: string is controlled by the user
78
Expression expression = parser.parseExpression(string);
89
SimpleEvaluationContext context
910
= SimpleEvaluationContext.forReadWriteDataBinding().build();
11+
// OK: Untrusted expressions are evaluated in a restricted context
1012
return expression.getValue(context);
1113
}
1214
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public void evaluate(Socket socket) throws IOException {
44

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public Object evaluate(Socket socket) throws IOException {
44

55
String string = reader.readLine();
66
ExpressionParser parser = new SpelExpressionParser();
7+
// BAD: string is controlled by the user
78
Expression expression = parser.parseExpression(string);
89
return expression.getValue();
910
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
byte[] iv = new byte[16]; // all zeroes
1+
byte[] iv = new byte[16]; // BAD: all zeroes
22
GCMParameterSpec params = new GCMParameterSpec(128, iv);
33
Cipher cipher = Cipher.getInstance("AES/GCM/PKCS5PADDING");
44
cipher.init(Cipher.ENCRYPT_MODE, key, params);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
byte[] iv = new byte[16];
22
SecureRandom random = SecureRandom.getInstanceStrong();
3-
random.nextBytes(iv);
3+
random.nextBytes(iv); // GOOD: random initialization vector
44
GCMParameterSpec params = new GCMParameterSpec(128, iv);
55
Cipher cipher = Cipher.getInstance("AES/GCM/PKCS5PADDING");
66
cipher.init(Cipher.ENCRYPT_MODE, key, params);
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
TextView pwView = getViewById(R.id.pw_text);
2-
pwView.setText("Your password is: " + password);
2+
pwView.setText("Your password is: " + password); // BAD: password is shown immediately

java/ql/src/Security/CWE/CWE-200/AndroidSensitiveTextGood.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
Button showButton = findViewById(R.id.show_pw_button);
66
showButton.setOnClickListener(new View.OnClickListener() {
77
public void onClick(View v) {
8-
pwView.setVisibility(View.VISIBLE);
8+
pwView.setVisibility(View.VISIBLE); // GOOD: password is only shown when the user clicks the button
99
}
1010
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
WebSettings settings = webview.getSettings();
22

3+
// GOOD: WebView is configured to disallow content access
34
settings.setAllowContentAccess(false);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
WebSettings settings = webview.getSettings();
22

3+
// BAD: WebView is configured to allow content access
34
settings.setAllowContentAccess(true);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
WebSettings settings = view.getSettings();
22

3+
// GOOD: WebView is configured to disallow file access
34
settings.setAllowFileAccess(false);
45
settings.setAllowFileAccessFromURLs(false);
56
settings.setAllowUniversalAccessFromURLs(false);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
WebSettings settings = view.getSettings();
22

3+
// BAD: WebView is configured to allow file access
34
settings.setAllowFileAccess(true);
45
settings.setAllowFileAccessFromURLs(true);
56
settings.setAllowUniversalAccessFromURLs(true);

java/ql/src/Security/CWE/CWE-330/examples/InsecureRandomnessCookie.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Random r = new Random();
1+
Random r = new Random(); // BAD: Random is not cryptographically secure
22

33
byte[] bytes = new byte[16];
44
r.nextBytes(bytes);

java/ql/src/Security/CWE/CWE-330/examples/SecureRandomnessCookie.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SecureRandom r = new SecureRandom();
1+
SecureRandom r = new SecureRandom(); // GOOD: SecureRandom is cryptographically secure
22

33
byte[] bytes = new byte[16];
44
r.nextBytes(bytes);

java/ql/src/Security/CWE/CWE-367/TOCTOURace.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public synchronized void act() {
1212

1313
public synchronized void bad(Resource r) {
1414
if (r.isReady()) {
15-
// r might no longer be ready, another thread might
15+
// BAD: r might no longer be ready, another thread might
1616
// have called setReady(false)
1717
r.act();
1818
}
1919
}
2020

2121
public synchronized void good(Resource r) {
22-
synchronized(r) {
22+
synchronized(r) { // GOOD: r is locked
2323
if (r.isReady()) {
2424
r.act();
2525
}

java/ql/src/Security/CWE/CWE-502/UnsafeDeserializationBad.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
public MyObject deserialize(Socket sock) {
99
try(ObjectInputStream in = new ObjectInputStream(sock.getInputStream())) {
10-
return (MyObject)in.readObject(); // unsafe
10+
return (MyObject)in.readObject(); // BAD: in is from untrusted source
1111
}
1212
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public MyObject deserialize(Socket sock) {
22
try(DataInputStream in = new DataInputStream(sock.getInputStream())) {
3-
return new MyObject(in.readInt());
3+
return new MyObject(in.readInt()); // GOOD: read only an int
44
}
55
}

java/ql/src/Security/CWE/CWE-522/LdapAuthUseLdap.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// BAD: LDAP authentication is used
12
String ldapUrl = "ldap://ad.your-server.com:389";
23
Hashtable<String, String> environment = new Hashtable<String, String>();
34
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

java/ql/src/Security/CWE/CWE-522/LdapAuthUseLdaps.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// GOOD: LDAP connection using LDAPS
12
String ldapUrl = "ldaps://ad.your-server.com:636";
23
Hashtable<String, String> environment = new Hashtable<String, String>();
34
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

java/ql/src/Security/CWE/CWE-522/LdapEnableSasl.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// GOOD: LDAP is used but SASL authentication is enabled
12
String ldapUrl = "ldap://ad.your-server.com:389";
23
Hashtable<String, String> environment = new Hashtable<String, String>();
34
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public void parse(Socket sock) throws Exception {
22
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
33
DocumentBuilder builder = factory.newDocumentBuilder();
4-
builder.parse(sock.getInputStream()); //unsafe
4+
builder.parse(sock.getInputStream()); // BAD: DTD parsing is enabled
55
}

java/ql/src/Security/CWE/CWE-611/XXEGood.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ public void disableDTDParse(Socket sock) throws Exception {
22
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
33
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
44
DocumentBuilder builder = factory.newDocumentBuilder();
5-
builder.parse(sock.getInputStream()); //safe
5+
builder.parse(sock.getInputStream()); // GOOD: DTD parsing is disabled
66
}

java/ql/src/Security/CWE/CWE-798/HardcodedAWSCredentials.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public class HardcodedAWSCredentials {
55
public static void main(String[] args) {
6-
//Hardcoded credentials for connecting to AWS services
6+
// BAD: Hardcoded credentials for connecting to AWS services
77
//To fix the problem, use other approaches including AWS credentials file, environment variables, or instance/container credentials instead
88
AWSCredentials creds = new BasicAWSCredentials("ACCESS_KEY", "SECRET_KEY"); //sensitive call
99
}

java/ql/src/Security/CWE/CWE-798/HardcodedCredentialsApiCall.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
private static final String p = "123456"; // hard-coded credential
1+
private static final String p = "123456"; // BAD: hard-coded credential
22

33
public static void main(String[] args) throws SQLException {
44
String url = "jdbc:mysql://localhost/test";
5-
String u = "admin"; // hard-coded credential
5+
String u = "admin"; // BAD: hard-coded credential
66

77
getConn(url, u, p);
88
}

java/ql/src/Security/CWE/CWE-835/InfiniteLoopBad.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
for (int i=0; i<10; i++) {
2-
for (int j=0; i<10; j++) {
2+
for (int j=0; i<10; j++) { // BAD: Potential infinite loop: i should be j
33
// do stuff
44
if (shouldBreak()) break;
55
}

java/ql/src/Security/CWE/CWE-835/InfiniteLoopGood.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
for (int i=0; i<10; i++) {
2-
for (int j=0; j<10; j++) {
2+
for (int j=0; j<10; j++) { // GOOD: correct variable j
33
// do stuff
44
if (shouldBreak()) break;
55
}

java/ql/src/Security/CWE/CWE-925/Bad.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
public class ShutdownReceiver extends BroadcastReceiver {
22
@Override
33
public void onReceive(final Context context, final Intent intent) {
4+
// BAD: The code does not check if the intent is an ACTION_SHUTDOWN intent
45
mainActivity.saveLocalData();
56
mainActivity.stopActivity();
67
}

java/ql/src/Security/CWE/CWE-925/Good.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
public class ShutdownReceiver extends BroadcastReceiver {
22
@Override
33
public void onReceive(final Context context, final Intent intent) {
4+
// GOOD: The code checks if the intent is an ACTION_SHUTDOWN intent
45
if (!intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
56
return;
67
}

0 commit comments

Comments
 (0)