Skip to content

Commit a86cbd8

Browse files
Apply suggestions from code review
Co-authored-by: Anders Schack-Mulligen <[email protected]>
1 parent 3323f7a commit a86cbd8

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

java/ql/src/semmle/code/java/security/Mail.qll renamed to java/ql/lib/semmle/code/java/security/Mail.qll

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ private import semmle.code.java.frameworks.Properties
1010
* set the `mail.smtp.ssl.socketFactory`/`mail.smtp.ssl.socketFactory.class` property to create an SMTP SSL socket.
1111
* 2. No `mail.smtp.ssl.checkserveridentity` property is enabled.
1212
*/
13-
predicate isInsecureMailPropertyConfig(VarAccess propertiesVarAccess) {
13+
predicate isInsecureMailPropertyConfig(Variable properties) {
1414
exists(MethodAccess ma |
1515
ma.getMethod() instanceof SetPropertyMethod and
16-
ma.getQualifier() = propertiesVarAccess.getVariable().getAnAccess()
16+
ma.getQualifier() = properties.getAnAccess()
1717
|
1818
getStringValue(ma.getArgument(0)).matches("%.auth%") and //mail.smtp.auth
1919
getStringValue(ma.getArgument(1)) = "true"
@@ -22,7 +22,7 @@ predicate isInsecureMailPropertyConfig(VarAccess propertiesVarAccess) {
2222
) and
2323
not exists(MethodAccess ma |
2424
ma.getMethod() instanceof SetPropertyMethod and
25-
ma.getQualifier() = propertiesVarAccess.getVariable().getAnAccess()
25+
ma.getQualifier() = properties.getAnAccess()
2626
|
2727
getStringValue(ma.getArgument(0)).matches("%.ssl.checkserveridentity%") and //mail.smtp.ssl.checkserveridentity
2828
getStringValue(ma.getArgument(1)) = "true"
@@ -39,19 +39,20 @@ predicate enablesEmailSsl(MethodAccess ma) {
3939
}
4040

4141
/**
42-
* Holds if a SSL certificate check is enabled on `va` with Apache Email
42+
* Holds if a SSL certificate check is enabled on an access of `apacheEmail` with Apache Email.
4343
*/
44-
predicate hasSslCertificateCheck(VarAccess va) {
44+
predicate hasSslCertificateCheck(Variable apacheEmail) {
4545
exists(MethodAccess ma |
46-
ma.getQualifier() = va.getVariable().getAnAccess() and
46+
ma.getQualifier() = apacheEmail.getAnAccess() and
4747
ma.getMethod().hasName("setSSLCheckServerIdentity") and
4848
ma.getMethod().getDeclaringType() instanceof ApacheEmail and
4949
ma.getArgument(0).(BooleanLiteral).getBooleanValue() = true
5050
)
5151
}
5252

5353
/**
54-
* Helper method to get string value of an argument
54+
* Returns the string value of `expr` if it is a `CompileTimeConstantExpr`,
55+
* or the string value of its operands if it is an `AddExpr`.
5556
*/
5657
private string getStringValue(Expr expr) {
5758
result = expr.(CompileTimeConstantExpr).getStringValue()
@@ -60,7 +61,8 @@ private string getStringValue(Expr expr) {
6061
}
6162

6263
/**
63-
* A method to set Java properties
64+
* A method to set Java properties, either using the `Properties` class
65+
* or the `Dictionary` class.
6466
*/
6567
private class SetPropertyMethod extends Method {
6668
SetPropertyMethod() {

java/ql/src/Security/CWE/CWE-297/InsecureJavaMail.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* makes the session susceptible to a man-in-the-middle attack.
66
* @kind problem
77
* @problem.severity warning
8+
* @security-severity 5.9
89
* @precision medium
910
* @id java/insecure-smtp-ssl
1011
* @tags security
@@ -17,7 +18,7 @@ import semmle.code.java.security.Mail
1718
from MethodAccess ma
1819
where
1920
ma.getMethod() instanceof MailSessionGetInstanceMethod and
20-
isInsecureMailPropertyConfig(ma.getArgument(0))
21+
isInsecureMailPropertyConfig(ma.getArgument(0).(VarAccess).getVariable())
2122
or
22-
enablesEmailSsl(ma) and not hasSslCertificateCheck(ma.getQualifier())
23+
enablesEmailSsl(ma) and not hasSslCertificateCheck(ma.getQualifier().(VarAccess).getVariable())
2324
select ma, "Java mailing has insecure SSL configuration"

java/ql/test/query-tests/security/CWE-297/InsecureJavaMailTest.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ class InsecureJavaMailTest extends InlineExpectationsTest {
1515
value = ""
1616
|
1717
ma.getMethod() instanceof MailSessionGetInstanceMethod and
18-
isInsecureMailPropertyConfig(ma.getArgument(0))
18+
isInsecureMailPropertyConfig(ma.getArgument(0).(VarAccess).getVariable())
1919
or
20-
enablesEmailSsl(ma) and not hasSslCertificateCheck(ma.getQualifier())
20+
enablesEmailSsl(ma) and
21+
not hasSslCertificateCheck(ma.getQualifier().(VarAccess).getVariable())
2122
)
2223
}
2324
}

0 commit comments

Comments
 (0)