Skip to content

Commit 8050e6c

Browse files
committed
feat(security): Enhance Redis Cache security checks and add expected results for backup and authentication configurations
1 parent 093d2d3 commit 8050e6c

File tree

9 files changed

+46
-12
lines changed

9 files changed

+46
-12
lines changed

ql/src/security/CWE-400/RedisCacheUnsafeMemoryPolicy.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ where
2121
config = redis.getRedisConfiguration() and
2222
unsafePolicy = config.maxMemoryPolicy() and
2323
unsafePolicy in ["allkeys-lru", "allkeys-random", "volatile-lru", "volatile-random", "volatile-ttl"]
24-
select redis,
24+
select config,
2525
"Redis Cache '" + redis.getName() + "' uses potentially unsafe memory policy '" + unsafePolicy + "' which may cause unexpected data loss."

ql/src/security/CWE-693/RedisCacheNoBackup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Redis Cache without data backup
22

3-
Redis Cache instances without backup configuration risk data loss in case of failures or disasters. This issue falls under [CWE-693: Protection Mechanism Failure](https://cwe.mitre.org/data/definitions/693.html), as it represents a failure to protect critical data.
3+
Redis Cache instances with both AOF and RDB backups disabled risk data loss in case of failures or disasters. This issue falls under [CWE-693: Protection Mechanism Failure](https://cwe.mitre.org/data/definitions/693.html), as it represents a failure to protect critical data.
44

55
## Problem Description
66

@@ -9,7 +9,7 @@ Azure Cache for Redis offers two types of persistence options:
99
1. RDB (Redis Database) snapshots - periodic full backups
1010
2. AOF (Append Only File) persistence - continuous logging of write operations
1111

12-
When neither backup method is enabled, the Redis cache becomes vulnerable to data loss from:
12+
When both backup methods are disabled or not configured, the Redis cache becomes vulnerable to data loss from:
1313

1414
- Service outages or crashes
1515
- Accidental data deletion
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Redis Cache without data backup
3-
* @description Redis Cache without data backup configuration risks data loss in case of failures.
3+
* @description Redis Cache with both AOF and RDB backups disabled risks data loss in case of failures.
44
* @kind problem
55
* @problem.severity warning
66
* @security-severity 3.5
@@ -14,14 +14,31 @@
1414

1515
import bicep
1616
import codeql.bicep.Concepts
17-
import codeql.bicep.frameworks.Microsoft.Cache
1817

19-
from Cache::RedisCacheResource redis, Cache::CacheProperties::RedisConfiguration config
20-
where
21-
config = redis.getRedisConfiguration() and
18+
from Expr output, Cache::RedisCacheResource redis, Cache::CacheProperties::RedisConfiguration config
19+
where
20+
// If the resource doesn't have a Redis configuration, its an issue.
21+
not exists(redis.getRedisConfiguration()) and
22+
output = redis.getProperties()
23+
or
2224
(
23-
not exists(string aofBackupEnabled | aofBackupEnabled = config.aofBackupEnabled()) and
24-
not exists(string rdbBackupEnabled | rdbBackupEnabled = config.rdbBackupEnabled())
25+
// We only consider Redis Cache resources that have a configuration.
26+
config = redis.getRedisConfiguration() and
27+
// If they don't have any backup enabled, we consider it a risk.
28+
(
29+
not config.hasAofBackupEnabled() and
30+
not config.hasRdbBackupEnabled() and
31+
output = config
32+
)
33+
or
34+
config.hasAofBackupEnabled() and
35+
config.aofBackupEnabled() = "false" and
36+
output = config
37+
or
38+
config.hasRdbBackupEnabled() and
39+
config.rdbBackupEnabled() = "false" and
40+
output = config
2541
)
26-
select redis,
27-
"Redis Cache '" + redis.getName() + "' does not have either AOF or RDB backups enabled, risking data loss."
42+
select output,
43+
"Redis Cache '" + redis.getName() +
44+
"' has both AOF and RDB backups disabled (or not configured), risking data loss."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| app.bicep:13:1:19:1 | RedisCacheResource | Redis Cache 'public-redis' has public network access enabled, exposing it to the internet. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| app.bicep:26:1:34:1 | RedisCacheResource | Redis Cache 'noauth-redis' has authentication disabled, allowing unauthenticated access. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| app.bicep:14:1:20:1 | RedisCacheResource | Redis Cache 'insecure-redis' has non-SSL port enabled, which allows unencrypted connections. |
2+
| app.bicep:23:1:29:1 | RedisCacheResource | Redis Cache 'explicit-default-redis' has non-SSL port enabled, which allows unencrypted connections. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| app.bicep:19:25:21:5 | RedisConfiguration | Redis Cache 'unsafe-memory-1-redis' uses potentially unsafe memory policy 'allkeys-lru' which may cause unexpected data loss. |
2+
| app.bicep:30:25:32:5 | RedisConfiguration | Redis Cache 'unsafe-memory-2-redis' uses potentially unsafe memory policy 'allkeys-random' which may cause unexpected data loss. |
3+
| app.bicep:41:25:43:5 | RedisConfiguration | Redis Cache 'unsafe-memory-3-redis' uses potentially unsafe memory policy 'volatile-lru' which may cause unexpected data loss. |
4+
| app.bicep:52:25:54:5 | RedisConfiguration | Redis Cache 'unsafe-memory-4-redis' uses potentially unsafe memory policy 'volatile-random' which may cause unexpected data loss. |
5+
| app.bicep:63:25:65:5 | RedisConfiguration | Redis Cache 'unsafe-memory-5-redis' uses potentially unsafe memory policy 'volatile-ttl' which may cause unexpected data loss. |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| app.bicep:62:15:69:3 | Object | Redis Cache 'nobackup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
2+
| app.bicep:82:25:85:5 | Object | Redis Cache 'aof-backup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
3+
| app.bicep:82:25:85:5 | Object | Redis Cache 'both-backup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
4+
| app.bicep:82:25:85:5 | Object | Redis Cache 'disabled-backup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
5+
| app.bicep:82:25:85:5 | Object | Redis Cache 'nobackup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
6+
| app.bicep:82:25:85:5 | Object | Redis Cache 'rdb-backup-redis' has both AOF and RDB backups disabled (or not configured), risking data loss. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| app.bicep:15:1:23:1 | RedisCacheResource | Redis Cache 'no-aad-redis' is not using Azure Active Directory (AAD) authentication. |
2+
| app.bicep:26:1:34:1 | RedisCacheResource | Redis Cache 'disabled-aad-redis' is not using Azure Active Directory (AAD) authentication. |

0 commit comments

Comments
 (0)