Skip to content

Commit cfb181f

Browse files
committed
feat(security): Add checks and documentation for remote debugging, insecure FTPS state, and TLS version in Azure Web Apps
1 parent c65571e commit cfb181f

16 files changed

+366
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Remote debugging enabled in Web App
2+
3+
Enabling remote debugging in production Azure Web Apps is a security risk. Remote debugging allows developers to connect to and debug the web application remotely, which can expose sensitive information and potentially allow unauthorized access to the application.
4+
5+
## Recommendation
6+
7+
Disable remote debugging in production environments. Remote debugging should only be enabled temporarily for development and troubleshooting purposes, and should be disabled once troubleshooting is complete.
8+
9+
## Example
10+
11+
Insecure configuration:
12+
13+
```bicep
14+
resource webApp 'Microsoft.Web/sites@2021-03-01' = {
15+
name: 'mywebapp'
16+
properties: {
17+
siteConfig: {
18+
remoteDebuggingEnabled: true
19+
}
20+
}
21+
}
22+
```
23+
24+
Secure configuration:
25+
26+
```bicep
27+
resource webApp 'Microsoft.Web/sites@2021-03-01' = {
28+
name: 'mywebapp'
29+
properties: {
30+
siteConfig: {
31+
remoteDebuggingEnabled: false // or omit this property as it defaults to false
32+
}
33+
}
34+
}
35+
```
36+
37+
## References
38+
39+
* [Azure Web App Security Best Practices](https://learn.microsoft.com/en-us/azure/app-service/security-recommendations)
40+
* [Remote debugging in Azure App Service](https://learn.microsoft.com/en-us/azure/app-service/configure-language-dotnet-framework#remote-debugging)
41+
* [Common Weakness Enumeration: CWE-306](https://cwe.mitre.org/data/definitions/306.html)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name Remote debugging enabled in Web App
3+
* @description Enabling remote debugging in production Azure Web Apps is a security risk.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 7.5
7+
* @precision high
8+
* @id bicep/webapp-remote-debugging
9+
* @tags security
10+
* bicep
11+
* azure
12+
* CWE-306
13+
*/
14+
15+
import bicep
16+
import codeql.bicep.frameworks.Microsoft.Web
17+
18+
from Web::SitesResource site, Web::SitesProperties::SiteConfig config
19+
where
20+
config = site.getProperties().getSiteConfig() and
21+
config.isRemoteDebuggingEnabled()
22+
select site, "Azure Web App has remote debugging enabled, which should not be used in production environments"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Insecure FTPS state in Web App
2+
3+
Using insecure FTP or allowing both FTP and FTPS in Azure Web Apps can expose sensitive credentials and data. FTP (File Transfer Protocol) transmits data and credentials in plaintext, which can be intercepted by attackers through network sniffing.
4+
5+
## Recommendation
6+
7+
Use secure file transfer by setting the `ftpsState` property to `FtpsOnly` to enforce FTPS (FTP Secure), which encrypts the connection. If file transfer is not needed, consider setting it to `Disabled`.
8+
9+
## Example
10+
11+
Insecure configurations:
12+
13+
```bicep
14+
// Allows both FTP and FTPS
15+
resource webApp1 'Microsoft.Web/sites@2021-03-01' = {
16+
name: 'mywebapp1'
17+
properties: {
18+
siteConfig: {
19+
ftpsState: 'AllAllowed'
20+
}
21+
}
22+
}
23+
24+
// Only allows insecure FTP
25+
resource webApp2 'Microsoft.Web/sites@2021-03-01' = {
26+
name: 'mywebapp2'
27+
properties: {
28+
siteConfig: {
29+
ftpsState: 'FtpOnly'
30+
}
31+
}
32+
}
33+
```
34+
35+
Secure configurations:
36+
37+
```bicep
38+
// Only allows secure FTPS
39+
resource webApp3 'Microsoft.Web/sites@2021-03-01' = {
40+
name: 'mywebapp3'
41+
properties: {
42+
siteConfig: {
43+
ftpsState: 'FtpsOnly'
44+
}
45+
}
46+
}
47+
48+
// Disables both FTP and FTPS
49+
resource webApp4 'Microsoft.Web/sites@2021-03-01' = {
50+
name: 'mywebapp4'
51+
properties: {
52+
siteConfig: {
53+
ftpsState: 'Disabled'
54+
}
55+
}
56+
}
57+
```
58+
59+
## References
60+
61+
* [Azure Web App Security Best Practices](https://learn.microsoft.com/en-us/azure/app-service/security-recommendations)
62+
* [FTP/S connection settings for Azure App Service](https://learn.microsoft.com/en-us/azure/app-service/configure-ftp-deploy)
63+
* [Common Weakness Enumeration: CWE-319](https://cwe.mitre.org/data/definitions/319.html)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @name Insecure FTPS state in Web App
3+
* @description Using insecure FTP or allowing both FTP and FTPS in Azure Web Apps can expose sensitive credentials and data.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 7.8
7+
* @precision high
8+
* @id bicep/insecure-webapp-ftps-state
9+
* @tags security
10+
* bicep
11+
* azure
12+
* CWE-319
13+
*/
14+
15+
import bicep
16+
import codeql.bicep.frameworks.Microsoft.Web
17+
18+
from Web::SitesResource site, Web::SitesProperties::SiteConfig config, StringLiteral ftpsState
19+
where
20+
config = site.getProperties().getSiteConfig() and
21+
ftpsState = config.getFtpsState() and
22+
(
23+
ftpsState.getValue() = "AllAllowed" or
24+
ftpsState.getValue() = "FtpOnly"
25+
)
26+
select site, "Azure Web App allows insecure FTP protocol: " + ftpsState.getValue() + ". Use 'FtpsOnly' or 'Disabled' instead."

ql/src/security/CWE-319/InsecureWebAppTlsVersion.actual

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Insecure TLS version in Web App
2+
3+
Using an insecure TLS version (TLS 1.0 or TLS 1.1) in an Azure Web App may lead to security vulnerabilities. These older TLS versions have known security weaknesses that can be exploited by attackers.
4+
5+
## Recommendation
6+
7+
Configure Web Apps to use at least TLS 1.2 by setting the `minTlsVersion` property to "1.2".
8+
9+
## Example
10+
11+
Insecure configuration:
12+
13+
```bicep
14+
resource webApp 'Microsoft.Web/sites@2021-03-01' = {
15+
name: 'mywebapp'
16+
properties: {
17+
siteConfig: {
18+
minTlsVersion: '1.1'
19+
}
20+
}
21+
}
22+
```
23+
24+
Secure configuration:
25+
26+
```bicep
27+
resource webApp 'Microsoft.Web/sites@2021-03-01' = {
28+
name: 'mywebapp'
29+
properties: {
30+
siteConfig: {
31+
minTlsVersion: '1.2'
32+
}
33+
}
34+
}
35+
```
36+
37+
## References
38+
39+
* [Azure Web App Security Best Practices](https://learn.microsoft.com/en-us/azure/app-service/security-recommendations)
40+
* [Transport Layer Security (TLS) - Azure App Service](https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-bindings#enforce-tls-versions)
41+
* [Common Weakness Enumeration: CWE-319](https://cwe.mitre.org/data/definitions/319.html)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @name Insecure TLS version in Web App
3+
* @description Using an insecure TLS version in an Azure Web App may lead to security vulnerabilities.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 8.1
7+
* @precision high
8+
* @id bicep/insecure-webapp-tls-version
9+
* @tags security
10+
* bicep
11+
* azure
12+
* CWE-319
13+
*/
14+
15+
import bicep
16+
import codeql.bicep.frameworks.Microsoft.Web
17+
18+
from Web::SitesResource site, Web::SitesProperties::SiteConfig config, StringLiteral tlsVersion
19+
where
20+
config = site.getProperties().getSiteConfig() and
21+
tlsVersion = config.getMinTlsVersion() and
22+
(
23+
tlsVersion.getValue() = "1.0" or
24+
tlsVersion.getValue() = "1.1"
25+
)
26+
select site, "Azure Web App configured with insecure TLS version: " + tlsVersion.getValue()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| app.bicep:4:1:12:1 | AppService[webAppBad1] | Azure Web App has remote debugging enabled, which should not be used in production environments |
2+
| app.bicep:15:1:24:1 | AppService[webAppBad2] | Azure Web App has remote debugging enabled, which should not be used in production environments |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/CWE-306/WebAppRemoteDebugging.ql
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Test cases for WebAppRemoteDebugging.ql
2+
3+
// BAD: Remote debugging is enabled
4+
resource webAppBad1 'Microsoft.Web/sites@2021-03-01' = {
5+
name: 'mywebapp-bad1'
6+
location: 'eastus'
7+
properties: {
8+
siteConfig: {
9+
remoteDebuggingEnabled: true
10+
}
11+
}
12+
}
13+
14+
// BAD: Remote debugging is enabled with a specific version
15+
resource webAppBad2 'Microsoft.Web/sites@2021-03-01' = {
16+
name: 'mywebapp-bad2'
17+
location: 'eastus'
18+
properties: {
19+
siteConfig: {
20+
remoteDebuggingEnabled: true
21+
remoteDebuggingVersion: 'VS2019'
22+
}
23+
}
24+
}
25+
26+
// GOOD: Remote debugging is explicitly disabled
27+
resource webAppGood1 'Microsoft.Web/sites@2021-03-01' = {
28+
name: 'mywebapp-good1'
29+
location: 'eastus'
30+
properties: {
31+
siteConfig: {
32+
remoteDebuggingEnabled: false
33+
}
34+
}
35+
}
36+
37+
// GOOD: Remote debugging is not specified (defaults to disabled)
38+
resource webAppGood2 'Microsoft.Web/sites@2021-03-01' = {
39+
name: 'mywebapp-good2'
40+
location: 'eastus'
41+
properties: {
42+
siteConfig: {
43+
// No remoteDebuggingEnabled property
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)