Skip to content

Commit 492325d

Browse files
committed
feat(query): Add SSL Enforement query
1 parent aca2084 commit 492325d

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SSL / TLS not Enforced
2+
3+
This query detects Azure database resources that have SSL/TLS enforcement disabled. Disabling SSL/TLS enforcement can expose sensitive data to interception and man-in-the-middle attacks, as connections to the database may be established without encryption. It is a security best practice to always require SSL/TLS for database connections to ensure data in transit is protected.
4+
5+
## Bad Example: SSL Enforcement Disabled
6+
7+
```bicep
8+
resource db 'Microsoft.Sql/servers@2021-02-01-preview' = {
9+
name: 'mydbserver'
10+
location: 'eastus'
11+
properties: {
12+
version: '12.0'
13+
sslEnforcement: 'Disabled' // BAD: SSL enforcement is disabled
14+
}
15+
}
16+
```
17+
18+
## Good Example: SSL Enforcement Enabled
19+
20+
```bicep
21+
resource db 'Microsoft.Sql/servers@2021-02-01-preview' = {
22+
name: 'mydbserver'
23+
location: 'eastus'
24+
properties: {
25+
version: '12.0'
26+
sslEnforcement: 'Enabled' // GOOD: SSL enforcement is enabled
27+
}
28+
}
29+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name SSL / TLS not Enforced
3+
* @description SSL / TLS should be enforced on resources to ensure secure communication.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 6.0
7+
* @precision high
8+
* @id bicep/ssl-enforcement-disabled
9+
* @tags security
10+
* bicep
11+
* azure
12+
* cryptography
13+
*/
14+
15+
16+
import bicep
17+
import codeql.bicep.frameworks.Microsoft.Databases::Databases
18+
19+
from DatabaseResource db
20+
where db.sslEnforcement() = "Disabled"
21+
select db.getSslEnforcement(),
22+
"SSL / TLS is not enforced on the database resource '" + db.getName() + "'."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| app.bicep:19:21:19:30 | String | SSL / TLS is not enforced on the database resource 'publicdbserver'. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/CWE-319/SslEnforement.ql
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// Secure
3+
resource db 'Microsoft.Sql/servers@2021-02-01-preview' = {
4+
name: 'securetlsdb'
5+
location: 'eastus'
6+
properties: {
7+
sslEnforcement: 'Enabled' // GOOD: Enforced
8+
}
9+
}
10+
11+
// Bad
12+
resource db 'Microsoft.Sql/servers@2021-02-01-preview' = {
13+
name: 'publicdbserver'
14+
location: 'eastus'
15+
properties: {
16+
version: '12.0'
17+
publicNetworkAccess: 'Enabled' // BAD: Database is publicly accessible
18+
minimalTlsVersion: '1.0' // BAD: Weak TLS version
19+
sslEnforcement: 'Disabled' // BAD: SSL enforcement is disabled
20+
}
21+
}

0 commit comments

Comments
 (0)